Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Sharkey
Manage
Activity
Members
Labels
Plan
Issues
342
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
25
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TransFem.org
Sharkey
Commits
eb350e8d
Commit
eb350e8d
authored
4 years ago
by
syuilo
Browse files
Options
Downloads
Patches
Plain Diff
Better favicon detection
parent
615fedd6
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/services/fetch-instance-metadata.ts
+24
-15
24 additions, 15 deletions
src/services/fetch-instance-metadata.ts
with
24 additions
and
15 deletions
src/services/fetch-instance-metadata.ts
+
24
−
15
View file @
eb350e8d
...
...
@@ -9,14 +9,16 @@ import { URL } from 'url';
const
logger
=
new
Logger
(
'
metadata
'
,
'
cyan
'
);
export
async
function
fetchInstanceMetadata
(
instance
:
Instance
):
Promise
<
void
>
{
export
async
function
fetchInstanceMetadata
(
instance
:
Instance
,
force
=
false
):
Promise
<
void
>
{
const
unlock
=
await
getFetchInstanceMetadataLock
(
instance
.
host
);
const
_instance
=
await
Instances
.
findOne
({
host
:
instance
.
host
});
const
now
=
Date
.
now
();
if
(
_instance
&&
_instance
.
infoUpdatedAt
&&
(
now
-
_instance
.
infoUpdatedAt
.
getTime
()
<
1000
*
60
*
60
*
24
))
{
unlock
();
return
;
if
(
!
force
)
{
const
_instance
=
await
Instances
.
findOne
({
host
:
instance
.
host
});
const
now
=
Date
.
now
();
if
(
_instance
&&
_instance
.
infoUpdatedAt
&&
(
now
-
_instance
.
infoUpdatedAt
.
getTime
()
<
1000
*
60
*
60
*
24
))
{
unlock
();
return
;
}
}
logger
.
info
(
`Fetching metadata of
${
instance
.
host
}
...`
);
...
...
@@ -29,7 +31,7 @@ export async function fetchInstanceMetadata(instance: Instance): Promise<void> {
]);
const
[
favicon
,
icon
,
themeColor
,
name
,
description
]
=
await
Promise
.
all
([
fetchFaviconUrl
(
instance
).
catch
(()
=>
null
),
fetchFaviconUrl
(
instance
,
dom
).
catch
(()
=>
null
),
fetchIconUrl
(
instance
,
dom
,
manifest
).
catch
(()
=>
null
),
getThemeColor
(
dom
,
manifest
).
catch
(()
=>
null
),
getSiteName
(
info
,
dom
,
manifest
).
catch
(()
=>
null
),
...
...
@@ -150,10 +152,17 @@ async function fetchManifest(instance: Instance): Promise<Record<string, any> |
return
manifest
;
}
async
function
fetchFaviconUrl
(
instance
:
Instance
):
Promise
<
string
|
null
>
{
logger
.
info
(
`Fetching favicon URL of
${
instance
.
host
}
...`
);
async
function
fetchFaviconUrl
(
instance
:
Instance
,
doc
:
DOMWindow
[
'
document
'
]
|
null
):
Promise
<
string
|
null
>
{
const
url
=
'
https://
'
+
instance
.
host
;
if
(
doc
)
{
const
href
=
doc
.
querySelector
(
'
link[rel="icon"]
'
)?.
getAttribute
(
'
href
'
);
if
(
href
)
{
return
(
new
URL
(
href
,
url
)).
href
;
}
}
const
faviconUrl
=
url
+
'
/favicon.ico
'
;
const
favicon
=
await
fetch
(
faviconUrl
,
{
...
...
@@ -169,6 +178,11 @@ async function fetchFaviconUrl(instance: Instance): Promise<string | null> {
}
async
function
fetchIconUrl
(
instance
:
Instance
,
doc
:
DOMWindow
[
'
document
'
]
|
null
,
manifest
:
Record
<
string
,
any
>
|
null
):
Promise
<
string
|
null
>
{
if
(
manifest
&&
manifest
.
icons
&&
manifest
.
icons
.
length
>
0
&&
manifest
.
icons
[
0
].
src
)
{
const
url
=
'
https://
'
+
instance
.
host
;
return
(
new
URL
(
manifest
.
icons
[
0
].
src
,
url
)).
href
;
}
if
(
doc
)
{
const
url
=
'
https://
'
+
instance
.
host
;
...
...
@@ -183,11 +197,6 @@ async function fetchIconUrl(instance: Instance, doc: DOMWindow['document'] | nul
}
}
if
(
manifest
&&
manifest
.
icons
&&
manifest
.
icons
.
length
>
0
&&
manifest
.
icons
[
0
].
src
)
{
const
url
=
'
https://
'
+
instance
.
host
;
return
(
new
URL
(
manifest
.
icons
[
0
].
src
,
url
)).
href
;
}
return
null
;
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment