fix: harden real backend workflows and channel connections
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { Injectable, NotFoundException } from '@nestjs/common';
|
||||
import { Prisma } from '@prisma/client';
|
||||
import { randomUUID } from 'node:crypto';
|
||||
import { PrismaService } from '../prisma/prisma.service';
|
||||
@@ -38,7 +38,7 @@ export class FilesService {
|
||||
where: tenantId ? { tenantId } : undefined,
|
||||
orderBy: { createdAt: 'desc' },
|
||||
take: 100,
|
||||
});
|
||||
}).then((items) => items.map(serializeFileObject));
|
||||
}
|
||||
|
||||
create(data: CreateFileObjectDto) {
|
||||
@@ -52,7 +52,7 @@ export class FilesService {
|
||||
checksum: data.checksum,
|
||||
purpose: data.purpose,
|
||||
};
|
||||
return this.prisma.fileObject.create({ data: createData });
|
||||
return this.prisma.fileObject.create({ data: createData }).then(serializeFileObject);
|
||||
}
|
||||
|
||||
async createPresignedUpload(data: CreatePresignedUploadDto) {
|
||||
@@ -79,4 +79,23 @@ export class FilesService {
|
||||
purpose: data.purpose,
|
||||
});
|
||||
}
|
||||
|
||||
async getDownload(id: string) {
|
||||
const fileObject = await this.prisma.fileObject.findUnique({ where: { id } });
|
||||
if (!fileObject) {
|
||||
throw new NotFoundException('File object not found');
|
||||
}
|
||||
const content = await this.objectStorage.getObject(fileObject.objectKey);
|
||||
return {
|
||||
fileObject: serializeFileObject(fileObject),
|
||||
content,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
function serializeFileObject<T extends { sizeBytes: bigint | number | string }>(fileObject: T) {
|
||||
return {
|
||||
...fileObject,
|
||||
sizeBytes: fileObject.sizeBytes.toString(),
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user