mirror of
https://github.com/codex-team/codex.docs.git
synced 2025-08-09 15:35:25 +02:00
Fixed duplicating os.tmpdir
This commit is contained in:
parent
c2130a2225
commit
3bf407b74d
2 changed files with 8 additions and 6 deletions
|
@ -24,10 +24,12 @@ app.set('views', path.join(__dirname, './', 'views'));
|
||||||
app.set('view engine', 'twig');
|
app.set('view engine', 'twig');
|
||||||
require('./utils/twig');
|
require('./utils/twig');
|
||||||
|
|
||||||
|
const downloadedFaviconFolder = os.tmpdir();
|
||||||
|
|
||||||
// Check if favicon is not empty
|
// Check if favicon is not empty
|
||||||
if (favicon) {
|
if (favicon) {
|
||||||
// Upload favicon by url, it's path on server is '/temp/favicon.{format}'
|
// 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;
|
app.locals.favicon = res;
|
||||||
console.log('Favicon successfully uploaded');
|
console.log('Favicon successfully uploaded');
|
||||||
})
|
})
|
||||||
|
@ -45,7 +47,7 @@ app.use(express.urlencoded({ extended: true }));
|
||||||
app.use(cookieParser());
|
app.use(cookieParser());
|
||||||
app.use(express.static(path.join(__dirname, '../../public')));
|
app.use(express.static(path.join(__dirname, '../../public')));
|
||||||
app.use('/uploads', express.static(config.get('uploads')));
|
app.use('/uploads', express.static(config.get('uploads')));
|
||||||
app.use('/favicon', express.static(os.tmpdir()));
|
app.use('/favicon', express.static(downloadedFaviconFolder));
|
||||||
|
|
||||||
app.use('/', routes);
|
app.use('/', routes);
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import os from 'os';
|
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
import fetch from 'node-fetch';
|
import fetch from 'node-fetch';
|
||||||
|
|
||||||
|
@ -32,9 +31,10 @@ function checkIsUrl(str: string): boolean {
|
||||||
* Upload favicon by url, or get it by path
|
* Upload favicon by url, or get it by path
|
||||||
*
|
*
|
||||||
* @param destination - url or path of favicon
|
* @param destination - url or path of favicon
|
||||||
|
* @param faviconFolder - folder to save favicon
|
||||||
* @returns { Promise<FaviconData> } - Promise with data about favicon
|
* @returns { Promise<FaviconData> } - Promise with data about favicon
|
||||||
*/
|
*/
|
||||||
export async function downloadFavicon(destination: string): Promise<FaviconData> {
|
export async function downloadFavicon(destination: string, faviconFolder: string): Promise<FaviconData> {
|
||||||
// Check of destination is empty
|
// Check of destination is empty
|
||||||
if (!destination) {
|
if (!destination) {
|
||||||
throw Error('Favicon destination is empty');
|
throw Error('Favicon destination is empty');
|
||||||
|
@ -67,7 +67,7 @@ export async function downloadFavicon(destination: string): Promise<FaviconData>
|
||||||
clearTimeout(timeoutId);
|
clearTimeout(timeoutId);
|
||||||
|
|
||||||
// Get file path in temporary directory
|
// Get file path in temporary directory
|
||||||
const filePath = path.join(os.tmpdir(), `favicon.${format}`);
|
const filePath = path.join(faviconFolder, `favicon.${format}`);
|
||||||
|
|
||||||
// Save file
|
// Save file
|
||||||
await fs.writeFile(filePath, fileData, (err) => {
|
await fs.writeFile(filePath, fileData, (err) => {
|
||||||
|
@ -76,6 +76,6 @@ export async function downloadFavicon(destination: string): Promise<FaviconData>
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return { destination: `/favicon/favicon.${format}`,
|
return { destination: `/favicon/favicon.${format}`,
|
||||||
type: `image/${format}` } as FaviconData;
|
type: `image/${format}` } as FaviconData;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue