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 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<void> => {
// 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 };

View file

@ -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<FastifySensibleOptions>(async (fastify) => {
fastify.register(sensible)
})
fastify.register(sensible);
});

View file

@ -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<void> => {
// 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
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;

View file

@ -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();

View file

@ -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
}
})
},
});