backup
This commit is contained in:
1 parent
02f97c8dfa
commit
06ffc05e2b
9 files changed
+257
-186
No files matched your search
@@ -19,7 +19,7 @@ export class ClientService {
|
||||
some: {
|
||||
id: Number(userId),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
include: {
|
||||
sharedWith: {
|
||||
|
||||
@@ -1,4 +1,13 @@
|
||||
import { Controller, Get, Param, Req, Res, UseGuards, Logger, Request } from '@nestjs/common';
|
||||
import {
|
||||
Controller,
|
||||
Get,
|
||||
Param,
|
||||
Req,
|
||||
Res,
|
||||
UseGuards,
|
||||
Logger,
|
||||
Request,
|
||||
} from '@nestjs/common';
|
||||
import { Response } from 'express';
|
||||
import { DocumentsService } from './documents.service';
|
||||
import { JwtAuthGuard } from '../auth/jwt-auth.guard';
|
||||
@@ -17,7 +26,7 @@ export class DocumentsController {
|
||||
|
||||
constructor(
|
||||
private readonly documentsService: DocumentsService,
|
||||
private readonly s3Service: S3Service
|
||||
private readonly s3Service: S3Service,
|
||||
) {}
|
||||
|
||||
@Get('shared/:userId')
|
||||
@@ -31,17 +40,18 @@ export class DocumentsController {
|
||||
async downloadDocument(
|
||||
@Param('key') key: string,
|
||||
@Request() req,
|
||||
@Res() res: Response
|
||||
@Res() res: Response,
|
||||
) {
|
||||
try {
|
||||
this.logger.debug(`Download request for key: ${key}`);
|
||||
|
||||
|
||||
const decodedKey = decodeURIComponent(key);
|
||||
this.logger.debug(`Decoded key: ${decodedKey}`);
|
||||
|
||||
// Get document from database first to verify access
|
||||
const document = await this.documentsService.findDocumentByS3Key(decodedKey);
|
||||
|
||||
const document =
|
||||
await this.documentsService.findDocumentByS3Key(decodedKey);
|
||||
|
||||
if (!document) {
|
||||
return res.status(404).json({ message: 'Document not found' });
|
||||
}
|
||||
@@ -49,7 +59,7 @@ export class DocumentsController {
|
||||
// Verify user has access to this document
|
||||
const hasAccess = await this.documentsService.verifyDocumentAccess(
|
||||
document.id,
|
||||
req.user.id
|
||||
req.user.id,
|
||||
);
|
||||
|
||||
if (!hasAccess) {
|
||||
@@ -58,7 +68,7 @@ export class DocumentsController {
|
||||
|
||||
// Get the file from S3
|
||||
const file = await this.s3Service.getFile(decodedKey);
|
||||
|
||||
|
||||
if (!file || !file.buffer) {
|
||||
return res.status(404).json({ message: 'File not found in storage' });
|
||||
}
|
||||
@@ -72,9 +82,9 @@ export class DocumentsController {
|
||||
return res.send(file.buffer);
|
||||
} catch (error) {
|
||||
this.logger.error('Download error:', error);
|
||||
return res.status(500).json({
|
||||
return res.status(500).json({
|
||||
message: 'Failed to download file',
|
||||
error: error.message
|
||||
error: error.message,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user