Add file deletion endpoint with admin guard
Introduced the deleteFile method in files.service.ts to handle file deletion, considering duplicates. Also updated files.controller.ts to create a new DELETE endpoint protected by the AdminGuard to ensure only admins can delete files.
This commit is contained in:
parent
3e6b2dc2bc
commit
79b2dec9e9
@ -2,7 +2,7 @@ import { IncomingMessage } from "node:http";
|
||||
import {
|
||||
BadRequestException,
|
||||
Controller,
|
||||
DefaultValuePipe,
|
||||
DefaultValuePipe, Delete,
|
||||
Get,
|
||||
HttpCode,
|
||||
HttpStatus,
|
||||
@ -15,9 +15,9 @@ import {
|
||||
Res,
|
||||
Response,
|
||||
StreamableFile,
|
||||
UseGuards,
|
||||
} from "@nestjs/common";
|
||||
import { InsertAdminState } from "../auth/auth.guard";
|
||||
UseGuards
|
||||
} from '@nestjs/common';
|
||||
import { AdminGuard, InsertAdminState } from '../auth/auth.guard';
|
||||
import { FilesService } from "./files.service";
|
||||
|
||||
@Controller("files")
|
||||
@ -121,4 +121,11 @@ export class FilesController {
|
||||
async getFile(@Param("fileId") fileId: string) {
|
||||
return await this.filesService.get(fileId);
|
||||
}
|
||||
|
||||
@UseGuards(AdminGuard)
|
||||
@HttpCode(HttpStatus.OK)
|
||||
@Delete(":fileId")
|
||||
async deleteFile(@Param("fileId") fileId: string) {
|
||||
return await this.filesService.deleteFile(fileId);
|
||||
}
|
||||
}
|
||||
|
@ -68,6 +68,12 @@ export class FilesService {
|
||||
}
|
||||
|
||||
//TODO DELETE FILE
|
||||
public async deleteFile(fileId: string) {
|
||||
//get checksum for fileId
|
||||
//check if multiple entry for checksum
|
||||
//if that the case then only remove the entry in database relative to fileId.
|
||||
//if there is one only entry then remove the file from the storage and the database.
|
||||
}
|
||||
|
||||
/**
|
||||
* Searches for files in the database using the specified search field, limit, and offset.
|
||||
|
Loading…
x
Reference in New Issue
Block a user