style(src/icons): auto-correction of the linter

- using pnpm eslint --fix ./src
This commit is contained in:
Raphael 2025-09-28 19:04:24 +02:00
parent 38013b77d3
commit bdcadcf324
No known key found for this signature in database
5 changed files with 60 additions and 58 deletions

View file

@ -1,9 +1,9 @@
import { FastifyPluginAsync } from 'fastify' import { FastifyPluginAsync } from 'fastify';
import fastifyFormBody from '@fastify/formbody' import fastifyFormBody from '@fastify/formbody';
import fastifyMultipart from '@fastify/multipart' import fastifyMultipart from '@fastify/multipart';
import { mkdir } from 'node:fs/promises' import { mkdir } from 'node:fs/promises';
import fp from 'fastify-plugin' import fp from 'fastify-plugin';
import * as db from '@shared/database' import * as db from '@shared/database';
// @ts-ignore: import.meta.glob is a vite thing. Typescript doesn't know this... // @ts-ignore: import.meta.glob is a vite thing. Typescript doesn't know this...
const plugins = import.meta.glob('./plugins/**/*.ts', { eager: true }); const plugins = import.meta.glob('./plugins/**/*.ts', { eager: true });
@ -20,7 +20,7 @@ declare module 'fastify' {
const app: FastifyPluginAsync = async ( const app: FastifyPluginAsync = async (
fastify, fastify,
opts opts,
): Promise<void> => { ): Promise<void> => {
// Place here your custom code! // Place here your custom code!
for (const plugin of Object.values(plugins)) { for (const plugin of Object.values(plugins)) {
@ -30,20 +30,20 @@ const app: FastifyPluginAsync = async (
void fastify.register(route as any, {}); void fastify.register(route as any, {});
} }
await fastify.register(db.useDatabase as any, {}) await fastify.register(db.useDatabase as any, {});
void fastify.register(fastifyFormBody, {}) void fastify.register(fastifyFormBody, {});
void fastify.register(fastifyMultipart, {}) void fastify.register(fastifyMultipart, {});
console.log(fastify.db.getUser(1)); console.log(fastify.db.getUser(1));
// The use of fastify-plugin is required to be able // The use of fastify-plugin is required to be able
// to export the decorators to the outer scope // to export the decorators to the outer scope
void fastify.register(fp(async (fastify) => { void fastify.register(fp(async (fastify) => {
const image_store = process.env.USER_ICONS_STORE ?? "/tmp/icons"; const image_store = process.env.USER_ICONS_STORE ?? '/tmp/icons';
fastify.decorate('image_store', image_store) fastify.decorate('image_store', image_store);
await mkdir(fastify.image_store, { recursive: true }) await mkdir(fastify.image_store, { recursive: true });
})) }));
} };
export default app export default app;
export { app } export { app };

View file

@ -1,5 +1,5 @@
import fp from 'fastify-plugin' import fp from 'fastify-plugin';
import sensible, { FastifySensibleOptions } from '@fastify/sensible' import sensible, { FastifySensibleOptions } from '@fastify/sensible';
/** /**
* This plugins adds some utilities to handle http errors * This plugins adds some utilities to handle http errors
@ -7,5 +7,5 @@ import sensible, { FastifySensibleOptions } from '@fastify/sensible'
* @see https://github.com/fastify/fastify-sensible * @see https://github.com/fastify/fastify-sensible
*/ */
export default fp<FastifySensibleOptions>(async (fastify) => { export default fp<FastifySensibleOptions>(async (fastify) => {
fastify.register(sensible) fastify.register(sensible);
}) });

View file

@ -1,9 +1,9 @@
import { FastifyPluginAsync } from 'fastify' import { FastifyPluginAsync } from 'fastify';
import { join } from 'node:path' import { join } from 'node:path';
import { open } from 'node:fs/promises' import { open } from 'node:fs/promises';
import sharp from 'sharp' import sharp from 'sharp';
import rawBody from 'raw-body' import rawBody from 'raw-body';
import { isNullish } from '@shared/utils' import { isNullish } from '@shared/utils';
const route: FastifyPluginAsync = async (fastify, opts): Promise<void> => { const route: FastifyPluginAsync = async (fastify, opts): Promise<void> => {
// await fastify.register(authMethod, {}); // await fastify.register(authMethod, {});
@ -13,37 +13,38 @@ const route: FastifyPluginAsync = async (fastify, opts): Promise<void> => {
// it sets some configuration options, and set the actual function that will handle the request // it sets some configuration options, and set the actual function that will handle the request
fastify.addContentTypeParser('*', function(request, payload, done: any) { fastify.addContentTypeParser('*', function(request, payload, done: any) {
done() done();
}); });
fastify.post('/:userid', async function(request, reply) { fastify.post('/:userid', async function(request, reply) {
let buffer = await rawBody(request.raw); const buffer = await rawBody(request.raw);
// this is how we get the `:userid` part of things // this is how we get the `:userid` part of things
const userid: string | undefined = (request.params as any)['userid']; const userid: string | undefined = (request.params as any)['userid'];
if (isNullish(userid)) { if (isNullish(userid)) {
return await reply.code(403); return await reply.code(403);
} }
const image_store: string = fastify.getDecorator('image_store') const image_store: string = fastify.getDecorator('image_store');
const image_path = join(image_store, userid) const image_path = join(image_store, userid);
try { try {
let img = sharp(buffer); const img = sharp(buffer);
img.resize({ img.resize({
height: 128, height: 128,
width: 128, width: 128,
fit: 'fill', fit: 'fill',
}) });
const data = await img.png({ compressionLevel: 6 }).toBuffer() const data = await img.png({ compressionLevel: 6 }).toBuffer();
let image_file = await open(image_path, "w", 0o666) const image_file = await open(image_path, 'w', 0o666);
await image_file.write(data); await image_file.write(data);
await image_file.close() await image_file.close();
} catch (e: any) { }
catch (e: any) {
fastify.log.error(`Error: ${e}`); fastify.log.error(`Error: ${e}`);
reply.code(400); reply.code(400);
return { status: "error", message: e.toString() }; return { status: 'error', message: e.toString() };
} }
}) });
} };
export default route export default route;

View file

@ -1,7 +1,7 @@
// this sould only be used by the docker file ! // this sould only be used by the docker file !
import fastify, { FastifyInstance } from "fastify"; import fastify, { FastifyInstance } from 'fastify';
import app from "./app" import app from './app';
const start = async () => { const start = async () => {
const envToLogger = { const envToLogger = {
@ -16,15 +16,16 @@ const start = async () => {
}, },
production: true, production: true,
test: false, test: false,
} };
const f: FastifyInstance = fastify({ logger: envToLogger.development }); const f: FastifyInstance = fastify({ logger: envToLogger.development });
try { try {
await f.register(app, {}); await f.register(app, {});
await f.listen({ port: 80, host: '0.0.0.0' }) await f.listen({ port: 80, host: '0.0.0.0' });
} catch (err) {
f.log.error(err)
process.exit(1)
} }
} catch (err) {
start() f.log.error(err);
process.exit(1);
}
};
start();

View file

@ -1,8 +1,8 @@
import { defineConfig } from 'vite' import { defineConfig } from 'vite';
import tsconfigPaths from 'vite-tsconfig-paths' import tsconfigPaths from 'vite-tsconfig-paths';
import nodeExternals from 'rollup-plugin-node-externals' import nodeExternals from 'rollup-plugin-node-externals';
import path from 'node:path' import path from 'node:path';
import fs from 'node:fs' import fs from 'node:fs';
function collectDeps(...pkgJsonPaths) { function collectDeps(...pkgJsonPaths) {
const allDeps = new Set(); const allDeps = new Set();
@ -20,7 +20,7 @@ function collectDeps(...pkgJsonPaths) {
const externals = collectDeps( const externals = collectDeps(
'./package.json', './package.json',
'../@shared/package.json' '../@shared/package.json',
); );
@ -42,5 +42,5 @@ export default defineConfig({
target: 'node22', // or whatever Node version you use target: 'node22', // or whatever Node version you use
sourcemap: false, sourcemap: false,
minify: true, // for easier debugging minify: true, // for easier debugging
} },
}) });