mirror of
https://github.com/diced/zipline.git
synced 2026-01-19 08:01:19 -08:00
refactor: many columns/tables in prisma
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { Image } from '@prisma/client';
|
||||
import { File } from '@prisma/client';
|
||||
import { FastifyInstance, FastifyReply } from 'fastify';
|
||||
import fastifyPlugin from 'fastify-plugin';
|
||||
|
||||
@@ -6,21 +6,21 @@ function postFileDecorator(fastify: FastifyInstance, _: unknown, done: () => voi
|
||||
fastify.decorateReply('postFile', postFile);
|
||||
done();
|
||||
|
||||
async function postFile(this: FastifyReply, file: Image) {
|
||||
async function postFile(this: FastifyReply, file: File) {
|
||||
if (!file) return true;
|
||||
|
||||
const nFile = await this.server.prisma.image.update({
|
||||
const nFile = await this.server.prisma.file.update({
|
||||
where: { id: file.id },
|
||||
data: { views: { increment: 1 } },
|
||||
});
|
||||
|
||||
if (nFile.maxViews && nFile.views >= nFile.maxViews) {
|
||||
await this.server.datasource.delete(file.file);
|
||||
await this.server.prisma.image.delete({ where: { id: nFile.id } });
|
||||
await this.server.datasource.delete(file.name);
|
||||
await this.server.prisma.file.delete({ where: { id: nFile.id } });
|
||||
|
||||
this.server.logger
|
||||
.child('file')
|
||||
.info(`File ${file.file} has been deleted due to max views (${nFile.maxViews})`);
|
||||
.info(`File ${file.name} has been deleted due to max views (${nFile.maxViews})`);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -36,6 +36,6 @@ export default fastifyPlugin(postFileDecorator, {
|
||||
|
||||
declare module 'fastify' {
|
||||
interface FastifyReply {
|
||||
postFile: (file: Image) => Promise<boolean>;
|
||||
postFile: (file: File) => Promise<boolean>;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user