mirror of
https://github.com/diced/zipline.git
synced 2026-01-21 00:43:28 -08:00
fix some errors
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import { unlinkSync } from 'fs';
|
||||
import { join } from 'path';
|
||||
import { FastifyReply, FastifyRequest, FastifyInstance } from 'fastify';
|
||||
import {
|
||||
Controller,
|
||||
@@ -57,14 +59,24 @@ export class ImagesController {
|
||||
id: req.params.id
|
||||
});
|
||||
|
||||
Console.logger(Image).info(`image ${image.id} was deleted`);
|
||||
if (this.webhooks.events.includes(WebhookType.DELETE_IMAGE))
|
||||
WebhookHelper.sendWebhook(this.webhooks.upload.content, {
|
||||
image,
|
||||
host: `${config.core.secure ? 'https' : 'http'}://${req.hostname}${config.uploader.route}/`
|
||||
});
|
||||
const dir = config.uploader.directory ? config.uploader.directory : 'uploads';
|
||||
const path = join(dir.charAt(0) == '/' ? dir : join(process.cwd(), dir), image.file);
|
||||
|
||||
return reply.send(image);
|
||||
try {
|
||||
unlinkSync(path);
|
||||
|
||||
Console.logger(Image).info(`image ${image.id} was deleted`);
|
||||
if (this.webhooks.events.includes(WebhookType.DELETE_IMAGE))
|
||||
WebhookHelper.sendWebhook(this.webhooks.upload.content, {
|
||||
image,
|
||||
host: `${config.core.secure ? 'https' : 'http'}://${req.hostname}${config.uploader.route}/`
|
||||
});
|
||||
|
||||
return reply.send(image);
|
||||
} catch (e) {
|
||||
Console.logger(Image).error(`image ${image.id} could not be deleted...`);
|
||||
return reply.status(401).send({ error: 'Could not delete image.' });
|
||||
}
|
||||
}
|
||||
|
||||
@GET('/recent')
|
||||
|
||||
@@ -39,6 +39,9 @@ if (!config) {
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
const dir = config.uploader.directory ? config.uploader.directory : 'uploads';
|
||||
const path = dir.charAt(0) == '/' ? dir : join(process.cwd(), dir);
|
||||
|
||||
const server = fastify({});
|
||||
const app = next({
|
||||
dev,
|
||||
@@ -121,7 +124,7 @@ server.register(fastifyCookies, {
|
||||
});
|
||||
|
||||
server.register(fastifyStatic, {
|
||||
root: join(process.cwd(), config.uploader.directory),
|
||||
root: path,
|
||||
prefix: config.uploader.route
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user