mirror of
https://github.com/umami-software/umami.git
synced 2026-02-19 12:05:41 +01:00
Resolve favicon locally (WIP)
This commit is contained in:
parent
0cb14f3f6c
commit
4688986901
13 changed files with 91 additions and 30 deletions
|
|
@ -2,6 +2,22 @@ import { ok, unauthorized, methodNotAllowed, getRandomChars } from 'next-basics'
|
|||
import { updateWebsite, createWebsite, getWebsiteById } from 'queries';
|
||||
import { useAuth } from 'lib/middleware';
|
||||
import { uuid } from 'lib/crypto';
|
||||
import favecon from 'favecon';
|
||||
|
||||
const getFavicon = async domain => {
|
||||
try {
|
||||
const icons = await favecon.getIcons(`https://${domain}`);
|
||||
|
||||
if (icons.length && icons.length > 0) {
|
||||
return icons[0]?.href;
|
||||
}
|
||||
} catch (e) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.log(`Could not fetch favicon for domain ${domain}`, e);
|
||||
}
|
||||
|
||||
return null;
|
||||
};
|
||||
|
||||
export default async (req, res) => {
|
||||
await useAuth(req, res);
|
||||
|
|
@ -13,6 +29,8 @@ export default async (req, res) => {
|
|||
const { name, domain, owner } = req.body;
|
||||
const website_owner = parseInt(owner);
|
||||
|
||||
const favicon = await getFavicon(domain);
|
||||
|
||||
if (website_id) {
|
||||
const website = await getWebsiteById(website_id);
|
||||
|
||||
|
|
@ -28,13 +46,19 @@ export default async (req, res) => {
|
|||
share_id = null;
|
||||
}
|
||||
|
||||
await updateWebsite(website_id, { name, domain, share_id, user_id: website_owner });
|
||||
await updateWebsite(website_id, { name, domain, share_id, user_id: website_owner, favicon });
|
||||
|
||||
return ok(res);
|
||||
} else {
|
||||
const website_uuid = uuid();
|
||||
const share_id = enable_share_url ? getRandomChars(8) : null;
|
||||
const website = await createWebsite(website_owner, { website_uuid, name, domain, share_id });
|
||||
const website = await createWebsite(website_owner, {
|
||||
website_uuid,
|
||||
name,
|
||||
domain,
|
||||
share_id,
|
||||
favicon,
|
||||
});
|
||||
|
||||
return ok(res, website);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue