feat: DELETE /:name endpoint
This commit is contained in:
parent
89e7e3ded4
commit
71d635fcb1
|
@ -1,2 +1,3 @@
|
||||||
node_modules
|
node_modules
|
||||||
dist
|
dist
|
||||||
|
store
|
||||||
|
|
|
@ -0,0 +1,28 @@
|
||||||
|
import { type FastifyPluginAsync } from 'fastify';
|
||||||
|
import fsp from 'node:fs/promises';
|
||||||
|
|
||||||
|
import { Config, config } from '../config.js';
|
||||||
|
import { InvalidAuthorization } from '../errors.js';
|
||||||
|
import { getFilesFor, getPathFor } from '../store.js';
|
||||||
|
|
||||||
|
export default (async function (fastify) {
|
||||||
|
fastify.delete('/:name', async (req) => {
|
||||||
|
const key = req.headers.authorization?.replace('Bearer ', '') ?? 'none';
|
||||||
|
|
||||||
|
const client = Config.getClientByKey(config, key);
|
||||||
|
if (!client) {
|
||||||
|
throw InvalidAuthorization();
|
||||||
|
}
|
||||||
|
|
||||||
|
const params = req.params as { name: string };
|
||||||
|
const files = await getFilesFor(client.name);
|
||||||
|
|
||||||
|
if (!files.find((x) => x === client.name + '-' + params.name)) {
|
||||||
|
return { status: 'ok' };
|
||||||
|
}
|
||||||
|
|
||||||
|
await fsp.rm(getPathFor(params.name, client.name));
|
||||||
|
|
||||||
|
return { status: 'ok' };
|
||||||
|
});
|
||||||
|
} as FastifyPluginAsync);
|
|
@ -1,9 +1,11 @@
|
||||||
import { FastifyPluginAsync } from 'fastify';
|
import { FastifyPluginAsync } from 'fastify';
|
||||||
|
import deleter from './delete.js';
|
||||||
import upload from './upload.js';
|
import upload from './upload.js';
|
||||||
import list from './list.js';
|
import list from './list.js';
|
||||||
import get from './get.js';
|
import get from './get.js';
|
||||||
|
|
||||||
export default (async function (fastify) {
|
export default (async function (fastify) {
|
||||||
|
await fastify.register(deleter);
|
||||||
await fastify.register(upload);
|
await fastify.register(upload);
|
||||||
await fastify.register(list);
|
await fastify.register(list);
|
||||||
await fastify.register(get);
|
await fastify.register(get);
|
||||||
|
|
|
@ -1 +0,0 @@
|
||||||
uwu
|
|
Loading…
Reference in New Issue