refactor: optimize favicon fetcher with cache

This commit is contained in:
Sonny
2024-05-26 00:19:47 +02:00
committed by Sonny
parent 9481b0ad7d
commit 8437f6b96d
6 changed files with 288 additions and 222 deletions

View File

@@ -0,0 +1,20 @@
import { Exception } from '@adonisjs/core/exceptions';
import { HttpContext } from '@adonisjs/core/http';
import logger from '@adonisjs/core/services/logger';
import { createReadStream } from 'node:fs';
import { resolve } from 'node:path';
export default class FaviconNotFoundException extends Exception {
static status = 404;
static code = 'E_FAVICON_NOT_FOUND';
async handle(error: this, ctx: HttpContext) {
const readStream = createReadStream(
resolve(process.cwd(), './public/empty-image.png')
);
ctx.response.header('Content-Type', 'image/png');
ctx.response.stream(readStream);
logger.debug(error.message);
}
}