From bdcadcf3244f23ec7ffdd198e80e8edc87188656 Mon Sep 17 00:00:00 2001 From: Raphael Date: Sun, 28 Sep 2025 19:04:24 +0200 Subject: [PATCH] style(src/icons): auto-correction of the linter - using pnpm eslint --fix ./src --- src/icons/src/app.ts | 34 ++++++++++++------------- src/icons/src/plugins/sensible.ts | 8 +++--- src/icons/src/routes/set.ts | 41 ++++++++++++++++--------------- src/icons/src/run.ts | 19 +++++++------- src/icons/vite.config.js | 16 ++++++------ 5 files changed, 60 insertions(+), 58 deletions(-) diff --git a/src/icons/src/app.ts b/src/icons/src/app.ts index d2b29df..47ca618 100644 --- a/src/icons/src/app.ts +++ b/src/icons/src/app.ts @@ -1,9 +1,9 @@ -import { FastifyPluginAsync } from 'fastify' -import fastifyFormBody from '@fastify/formbody' -import fastifyMultipart from '@fastify/multipart' -import { mkdir } from 'node:fs/promises' -import fp from 'fastify-plugin' -import * as db from '@shared/database' +import { FastifyPluginAsync } from 'fastify'; +import fastifyFormBody from '@fastify/formbody'; +import fastifyMultipart from '@fastify/multipart'; +import { mkdir } from 'node:fs/promises'; +import fp from 'fastify-plugin'; +import * as db from '@shared/database'; // @ts-ignore: import.meta.glob is a vite thing. Typescript doesn't know this... const plugins = import.meta.glob('./plugins/**/*.ts', { eager: true }); @@ -20,7 +20,7 @@ declare module 'fastify' { const app: FastifyPluginAsync = async ( fastify, - opts + opts, ): Promise => { // Place here your custom code! for (const plugin of Object.values(plugins)) { @@ -30,20 +30,20 @@ const app: FastifyPluginAsync = async ( void fastify.register(route as any, {}); } - await fastify.register(db.useDatabase as any, {}) - void fastify.register(fastifyFormBody, {}) - void fastify.register(fastifyMultipart, {}) + await fastify.register(db.useDatabase as any, {}); + void fastify.register(fastifyFormBody, {}); + void fastify.register(fastifyMultipart, {}); console.log(fastify.db.getUser(1)); // The use of fastify-plugin is required to be able // to export the decorators to the outer scope void fastify.register(fp(async (fastify) => { - const image_store = process.env.USER_ICONS_STORE ?? "/tmp/icons"; - fastify.decorate('image_store', image_store) - await mkdir(fastify.image_store, { recursive: true }) - })) + const image_store = process.env.USER_ICONS_STORE ?? '/tmp/icons'; + fastify.decorate('image_store', image_store); + await mkdir(fastify.image_store, { recursive: true }); + })); -} +}; -export default app -export { app } +export default app; +export { app }; diff --git a/src/icons/src/plugins/sensible.ts b/src/icons/src/plugins/sensible.ts index 5be2c8a..8c2093c 100644 --- a/src/icons/src/plugins/sensible.ts +++ b/src/icons/src/plugins/sensible.ts @@ -1,5 +1,5 @@ -import fp from 'fastify-plugin' -import sensible, { FastifySensibleOptions } from '@fastify/sensible' +import fp from 'fastify-plugin'; +import sensible, { FastifySensibleOptions } from '@fastify/sensible'; /** * 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 */ export default fp(async (fastify) => { - fastify.register(sensible) -}) + fastify.register(sensible); +}); diff --git a/src/icons/src/routes/set.ts b/src/icons/src/routes/set.ts index 7e854c3..6cf1e00 100644 --- a/src/icons/src/routes/set.ts +++ b/src/icons/src/routes/set.ts @@ -1,9 +1,9 @@ -import { FastifyPluginAsync } from 'fastify' -import { join } from 'node:path' -import { open } from 'node:fs/promises' -import sharp from 'sharp' -import rawBody from 'raw-body' -import { isNullish } from '@shared/utils' +import { FastifyPluginAsync } from 'fastify'; +import { join } from 'node:path'; +import { open } from 'node:fs/promises'; +import sharp from 'sharp'; +import rawBody from 'raw-body'; +import { isNullish } from '@shared/utils'; const route: FastifyPluginAsync = async (fastify, opts): Promise => { // await fastify.register(authMethod, {}); @@ -13,37 +13,38 @@ const route: FastifyPluginAsync = async (fastify, opts): Promise => { // it sets some configuration options, and set the actual function that will handle the request fastify.addContentTypeParser('*', function(request, payload, done: any) { - done() + done(); }); 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 const userid: string | undefined = (request.params as any)['userid']; if (isNullish(userid)) { return await reply.code(403); } - const image_store: string = fastify.getDecorator('image_store') - const image_path = join(image_store, userid) + const image_store: string = fastify.getDecorator('image_store'); + const image_path = join(image_store, userid); try { - let img = sharp(buffer); + const img = sharp(buffer); img.resize({ height: 128, width: 128, fit: 'fill', - }) - const data = await img.png({ compressionLevel: 6 }).toBuffer() - let image_file = await open(image_path, "w", 0o666) + }); + const data = await img.png({ compressionLevel: 6 }).toBuffer(); + const image_file = await open(image_path, 'w', 0o666); await image_file.write(data); - await image_file.close() - } catch (e: any) { + await image_file.close(); + } + catch (e: any) { fastify.log.error(`Error: ${e}`); reply.code(400); - return { status: "error", message: e.toString() }; + return { status: 'error', message: e.toString() }; } - }) -} + }); +}; -export default route +export default route; diff --git a/src/icons/src/run.ts b/src/icons/src/run.ts index efaa386..9f9e3dd 100644 --- a/src/icons/src/run.ts +++ b/src/icons/src/run.ts @@ -1,7 +1,7 @@ // this sould only be used by the docker file ! -import fastify, { FastifyInstance } from "fastify"; -import app from "./app" +import fastify, { FastifyInstance } from 'fastify'; +import app from './app'; const start = async () => { const envToLogger = { @@ -16,15 +16,16 @@ const start = async () => { }, production: true, test: false, - } + }; const f: FastifyInstance = fastify({ logger: envToLogger.development }); try { await f.register(app, {}); - await f.listen({ port: 80, host: '0.0.0.0' }) - } catch (err) { - f.log.error(err) - process.exit(1) + await f.listen({ port: 80, host: '0.0.0.0' }); } -} -start() + catch (err) { + f.log.error(err); + process.exit(1); + } +}; +start(); diff --git a/src/icons/vite.config.js b/src/icons/vite.config.js index 8de6f14..9aba98c 100644 --- a/src/icons/vite.config.js +++ b/src/icons/vite.config.js @@ -1,8 +1,8 @@ -import { defineConfig } from 'vite' -import tsconfigPaths from 'vite-tsconfig-paths' -import nodeExternals from 'rollup-plugin-node-externals' -import path from 'node:path' -import fs from 'node:fs' +import { defineConfig } from 'vite'; +import tsconfigPaths from 'vite-tsconfig-paths'; +import nodeExternals from 'rollup-plugin-node-externals'; +import path from 'node:path'; +import fs from 'node:fs'; function collectDeps(...pkgJsonPaths) { const allDeps = new Set(); @@ -20,7 +20,7 @@ function collectDeps(...pkgJsonPaths) { const externals = collectDeps( './package.json', - '../@shared/package.json' + '../@shared/package.json', ); @@ -42,5 +42,5 @@ export default defineConfig({ target: 'node22', // or whatever Node version you use sourcemap: false, minify: true, // for easier debugging - } -}) + }, +});