fixes(eslint): fixing everything that eslint complained about
This commit is contained in:
parent
d11e4a4516
commit
404735fe22
17 changed files with 1566 additions and 69 deletions
|
|
@ -4,10 +4,11 @@ import fastifyMultipart from '@fastify/multipart';
|
|||
import { mkdir } from 'node:fs/promises';
|
||||
import fp from 'fastify-plugin';
|
||||
import * as db from '@shared/database';
|
||||
import { authPlugin, jwtPlugin } from '@shared/auth';
|
||||
|
||||
// @ts-except-error: import.meta.glob is a vite thing. Typescript doesn't know this...
|
||||
// @ts-expect-error: import.meta.glob is a vite thing. Typescript doesn't know this...
|
||||
const plugins = import.meta.glob('./plugins/**/*.ts', { eager: true });
|
||||
// @ts-except-error: import.meta.glob is a vite thing. Typescript doesn't know this...
|
||||
// @ts-expect-error: import.meta.glob is a vite thing. Typescript doesn't know this...
|
||||
const routes = import.meta.glob('./routes/**/*.ts', { eager: true });
|
||||
|
||||
|
||||
|
|
@ -20,20 +21,23 @@ declare module 'fastify' {
|
|||
|
||||
const app: FastifyPluginAsync = async (
|
||||
fastify,
|
||||
opts,
|
||||
_opts,
|
||||
): Promise<void> => {
|
||||
void _opts;
|
||||
// Place here your custom code!
|
||||
for (const plugin of Object.values(plugins)) {
|
||||
void fastify.register(plugin as any, {});
|
||||
void fastify.register(plugin as FastifyPluginAsync, {});
|
||||
}
|
||||
for (const route of Object.values(routes)) {
|
||||
void fastify.register(route as any, {});
|
||||
void fastify.register(route as FastifyPluginAsync, {});
|
||||
}
|
||||
|
||||
await fastify.register(db.useDatabase as any, {});
|
||||
await fastify.register(db.useDatabase as FastifyPluginAsync, {});
|
||||
await fastify.register(authPlugin as FastifyPluginAsync, {});
|
||||
await fastify.register(jwtPlugin as FastifyPluginAsync, {});
|
||||
|
||||
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
|
||||
|
|
|
|||
|
|
@ -5,21 +5,22 @@ import sharp from 'sharp';
|
|||
import rawBody from 'raw-body';
|
||||
import { isNullish } from '@shared/utils';
|
||||
|
||||
const route: FastifyPluginAsync = async (fastify, opts): Promise<void> => {
|
||||
const route: FastifyPluginAsync = async (fastify, _opts): Promise<void> => {
|
||||
void _opts;
|
||||
// await fastify.register(authMethod, {});
|
||||
// here we register plugins that will be active for the current fastify instance (aka everything in this function)
|
||||
|
||||
// we register a route handler for: `/<USERID_HERE>`
|
||||
// it sets some configuration options, and set the actual function that will handle the request
|
||||
|
||||
fastify.addContentTypeParser('*', function(request, payload, done: any) {
|
||||
done();
|
||||
fastify.addContentTypeParser('*', function(request, payload, done) {
|
||||
done(null);
|
||||
});
|
||||
|
||||
fastify.post('/:userid', async function(request, reply) {
|
||||
fastify.post<{ Params: { userid: string } }>('/:userid', async function(request, reply) {
|
||||
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'];
|
||||
const userid: string | undefined = (request.params)['userid'];
|
||||
if (isNullish(userid)) {
|
||||
return await reply.code(403);
|
||||
}
|
||||
|
|
@ -38,10 +39,10 @@ const route: FastifyPluginAsync = async (fastify, opts): Promise<void> => {
|
|||
await image_file.write(data);
|
||||
await image_file.close();
|
||||
}
|
||||
catch (e: any) {
|
||||
catch (e) {
|
||||
fastify.log.error(`Error: ${e}`);
|
||||
reply.code(400);
|
||||
return { status: 'error', message: e.toString() };
|
||||
return { status: 'error' };
|
||||
}
|
||||
});
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue