From 577195b5786858cf682c6547cf3c60c2d76b281f Mon Sep 17 00:00:00 2001 From: diced Date: Sun, 27 Nov 2022 20:06:22 -0800 Subject: [PATCH] fix: serve favicon.ico always --- src/components/pages/Dashboard/index.tsx | 12 ++++++++---- src/server/index.ts | 10 ++++++++++ 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/components/pages/Dashboard/index.tsx b/src/components/pages/Dashboard/index.tsx index b182086..37f732d 100644 --- a/src/components/pages/Dashboard/index.tsx +++ b/src/components/pages/Dashboard/index.tsx @@ -35,14 +35,14 @@ export default function Dashboard({ disableMediaPreview, exifEnabled }) { if (!res.error) { updateImages(); showNotification({ - title: 'Image Deleted', - message: '', + title: 'File Deleted', + message: `${original.name}`, color: 'green', icon: , }); } else { showNotification({ - title: 'Failed to delete image', + title: 'Failed to Delete File', message: res.error, color: 'red', icon: , @@ -54,7 +54,11 @@ export default function Dashboard({ disableMediaPreview, exifEnabled }) { clipboard.copy(`${window.location.protocol}//${window.location.host}${original.url}`); showNotification({ title: 'Copied to clipboard', - message: '', + message: ( + {`${window.location.protocol}//${window.location.host}${original.url}`} + ), icon: , }); }; diff --git a/src/server/index.ts b/src/server/index.ts index 5c267e1..f4f384d 100644 --- a/src/server/index.ts +++ b/src/server/index.ts @@ -1,5 +1,6 @@ import { Image, PrismaClient } from '@prisma/client'; import Router from 'find-my-way'; +import { createReadStream, existsSync } from 'fs'; import { mkdir } from 'fs/promises'; import { createServer, IncomingMessage, OutgoingMessage, ServerResponse } from 'http'; import next from 'next'; @@ -84,6 +85,15 @@ async function start() { }, }); + router.on('GET', '/favicon.ico', async (req, res) => { + if (!existsSync('./public/favicon.ico')) return nextServer.render404(req, res); + + const favicon = createReadStream('./public/favicon.ico'); + res.setHeader('Content-Type', 'image/x-icon'); + + favicon.pipe(res); + }); + router.on('GET', `${config.urls.route}/:id`, async (req, res, params) => { if (params.id === '') return nextServer.render404(req, res as ServerResponse);