fix and update
This commit is contained in:
@@ -115,9 +115,10 @@ export class MediaService {
|
||||
};
|
||||
}
|
||||
|
||||
async createDocumentPhotoUploadUrl(userId: string, documentId: string, contentType: string) {
|
||||
async createDocumentPhotoUploadUrl(userId: string, documentId: string, contentType: string, fileName?: string) {
|
||||
let normalizedContentType: string;
|
||||
try {
|
||||
this.minio.assertImageContentType(contentType);
|
||||
normalizedContentType = this.minio.assertDocumentAttachmentContentType(contentType, fileName);
|
||||
} catch (error) {
|
||||
throw new BadRequestException(error instanceof Error ? error.message : 'Некорректный тип файла');
|
||||
}
|
||||
@@ -128,9 +129,9 @@ export class MediaService {
|
||||
throw new NotFoundException('Документ не найден');
|
||||
}
|
||||
|
||||
const extension = this.minio.extensionForContentType(contentType);
|
||||
const extension = this.minio.extensionForDocumentContentType(normalizedContentType, fileName);
|
||||
const storageKey = `documents/${userId}/${documentId}/${crypto.randomUUID()}.${extension}`;
|
||||
return this.createUploadTarget(userId, storageKey, contentType);
|
||||
return this.createUploadTarget(userId, storageKey, normalizedContentType);
|
||||
}
|
||||
|
||||
async resolveStreamToken(token: string, requesterId?: string) {
|
||||
@@ -177,18 +178,19 @@ export class MediaService {
|
||||
);
|
||||
}
|
||||
|
||||
async getDocumentPhotoAccessUrl(requesterId: string, targetUserId: string, storageKey: string) {
|
||||
async getDocumentPhotoAccessUrl(requesterId: string, targetUserId: string, storageKey: string, fileName?: string) {
|
||||
await this.access.assertCanViewUserDocuments(requesterId, targetUserId);
|
||||
|
||||
if (!storageKey.startsWith(`documents/${targetUserId}/`)) {
|
||||
throw new BadRequestException('Некорректный ключ фото документа');
|
||||
throw new BadRequestException('Некорректный ключ файла документа');
|
||||
}
|
||||
|
||||
const token = await this.jwt.signAsync(
|
||||
{
|
||||
purpose: 'media-stream',
|
||||
objectKey: storageKey,
|
||||
ownerId: targetUserId
|
||||
ownerId: targetUserId,
|
||||
fileName: fileName?.trim() || undefined
|
||||
} satisfies MediaStreamPayload,
|
||||
{
|
||||
secret: this.config.getOrThrow<string>('JWT_ACCESS_SECRET'),
|
||||
|
||||
Reference in New Issue
Block a user