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 {
|
import {
|
||||||
BadRequestException,
|
BadRequestException,
|
||||||
Controller,
|
Controller,
|
||||||
DefaultValuePipe,
|
DefaultValuePipe, Delete,
|
||||||
Get,
|
Get,
|
||||||
HttpCode,
|
HttpCode,
|
||||||
HttpStatus,
|
HttpStatus,
|
||||||
@ -15,9 +15,9 @@ import {
|
|||||||
Res,
|
Res,
|
||||||
Response,
|
Response,
|
||||||
StreamableFile,
|
StreamableFile,
|
||||||
UseGuards,
|
UseGuards
|
||||||
} from "@nestjs/common";
|
} from '@nestjs/common';
|
||||||
import { InsertAdminState } from "../auth/auth.guard";
|
import { AdminGuard, InsertAdminState } from '../auth/auth.guard';
|
||||||
import { FilesService } from "./files.service";
|
import { FilesService } from "./files.service";
|
||||||
|
|
||||||
@Controller("files")
|
@Controller("files")
|
||||||
@ -121,4 +121,11 @@ export class FilesController {
|
|||||||
async getFile(@Param("fileId") fileId: string) {
|
async getFile(@Param("fileId") fileId: string) {
|
||||||
return await this.filesService.get(fileId);
|
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
|
//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.
|
* Searches for files in the database using the specified search field, limit, and offset.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user