diff --git a/src/backend/app.ts b/src/backend/app.ts index 51dd6a4..2646035 100644 --- a/src/backend/app.ts +++ b/src/backend/app.ts @@ -24,10 +24,12 @@ app.set('views', path.join(__dirname, './', 'views')); app.set('view engine', 'twig'); require('./utils/twig'); +const downloadedFaviconFolder = os.tmpdir(); + // Check if favicon is not empty if (favicon) { // Upload favicon by url, it's path on server is '/temp/favicon.{format}' - downloadFavicon(favicon).then((res) => { + downloadFavicon(favicon, downloadedFaviconFolder).then((res) => { app.locals.favicon = res; console.log('Favicon successfully uploaded'); }) @@ -45,7 +47,7 @@ app.use(express.urlencoded({ extended: true })); app.use(cookieParser()); app.use(express.static(path.join(__dirname, '../../public'))); app.use('/uploads', express.static(config.get('uploads'))); -app.use('/favicon', express.static(os.tmpdir())); +app.use('/favicon', express.static(downloadedFaviconFolder)); app.use('/', routes); diff --git a/src/backend/utils/downloadFavicon.ts b/src/backend/utils/downloadFavicon.ts index bb6a9dc..2047e51 100644 --- a/src/backend/utils/downloadFavicon.ts +++ b/src/backend/utils/downloadFavicon.ts @@ -1,5 +1,4 @@ import path from 'path'; -import os from 'os'; import fs from 'fs'; import fetch from 'node-fetch'; @@ -32,9 +31,10 @@ function checkIsUrl(str: string): boolean { * Upload favicon by url, or get it by path * * @param destination - url or path of favicon + * @param faviconFolder - folder to save favicon * @returns { Promise } - Promise with data about favicon */ -export async function downloadFavicon(destination: string): Promise { +export async function downloadFavicon(destination: string, faviconFolder: string): Promise { // Check of destination is empty if (!destination) { throw Error('Favicon destination is empty'); @@ -67,7 +67,7 @@ export async function downloadFavicon(destination: string): Promise clearTimeout(timeoutId); // Get file path in temporary directory - const filePath = path.join(os.tmpdir(), `favicon.${format}`); + const filePath = path.join(faviconFolder, `favicon.${format}`); // Save file await fs.writeFile(filePath, fileData, (err) => { @@ -76,6 +76,6 @@ export async function downloadFavicon(destination: string): Promise } }); - return { destination: `/favicon/favicon.${format}`, + return { destination: `/favicon/favicon.${format}`, type: `image/${format}` } as FaviconData; }