update
This commit is contained in:
@ -95,6 +95,59 @@ export class FileController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static async delete(req: Request, res: Response, next: NextFunction): Promise<void | Response> {
|
||||||
|
/*
|
||||||
|
#swagger.tags = ['File']
|
||||||
|
#swagger.security = [{
|
||||||
|
"bearerAuth": []
|
||||||
|
}]
|
||||||
|
#swagger.requestBody = {
|
||||||
|
required: true,
|
||||||
|
content: {
|
||||||
|
"application/json": {
|
||||||
|
schema: {
|
||||||
|
type: "object",
|
||||||
|
properties: {
|
||||||
|
file: {
|
||||||
|
type: "string",
|
||||||
|
description: "File name returned from upload"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
required: ["file"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
try {
|
||||||
|
const schema = Joi.object({
|
||||||
|
file: Joi.string().required().label("File"),
|
||||||
|
});
|
||||||
|
|
||||||
|
const param = await schema.validateAsync(req.body);
|
||||||
|
|
||||||
|
if (param.file.includes("..") || param.file.includes("/") || param.file.includes("\\")) {
|
||||||
|
return ReturnHelper.errorResponse(res, 400, 400, Language.lang.failed_delete, "Invalid file name");
|
||||||
|
}
|
||||||
|
|
||||||
|
const field = {
|
||||||
|
file: param.file,
|
||||||
|
application: "saude",
|
||||||
|
};
|
||||||
|
|
||||||
|
let url = config.get("service.file") + "delete";
|
||||||
|
await Thirdparty.DeleteFile(url, field, JwtHelper.token(req.auth.data));
|
||||||
|
|
||||||
|
return ReturnHelper.successResponseAny(res, 200, Language.lang.success_delete, {});
|
||||||
|
} catch (e: unknown) {
|
||||||
|
log.error(e);
|
||||||
|
const err = e as Error;
|
||||||
|
|
||||||
|
return ReturnHelper.errorResponse(res, 400, 401, Language.lang.failed_delete, err.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static async download(req: Request, res: Response, next: NextFunction): Promise<void | Response> {
|
static async download(req: Request, res: Response, next: NextFunction): Promise<void | Response> {
|
||||||
/*
|
/*
|
||||||
#swagger.tags = ['File']
|
#swagger.tags = ['File']
|
||||||
|
|||||||
@ -105,4 +105,26 @@ export default class Thirdparty {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static async DeleteFile(url: string, field: any, token?: string) {
|
||||||
|
try {
|
||||||
|
const headers: Record<string, string> = {};
|
||||||
|
if (token) {
|
||||||
|
headers.Authorization = `Bearer ${token}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
const response = await axios.delete(url, { data: field, headers });
|
||||||
|
const result = response.data;
|
||||||
|
|
||||||
|
if (!result.status) throw response;
|
||||||
|
return result;
|
||||||
|
} catch (error: any) {
|
||||||
|
const { response } = error;
|
||||||
|
throw {
|
||||||
|
status: false,
|
||||||
|
message: response?.data?.error ?? response?.data?.message ?? "Unknown error",
|
||||||
|
data: null,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -103,6 +103,7 @@ export class RoutePrivate {
|
|||||||
app.put("/api/menu/restore/:id", MenuController.restore);
|
app.put("/api/menu/restore/:id", MenuController.restore);
|
||||||
|
|
||||||
app.post("/api/upload", FileController.upload);
|
app.post("/api/upload", FileController.upload);
|
||||||
|
app.delete("/api/delete", FileController.delete);
|
||||||
app.get("/api/download", FileController.download);
|
app.get("/api/download", FileController.download);
|
||||||
|
|
||||||
app.get("/api/administrativu/list", AdministrativuController.list);
|
app.get("/api/administrativu/list", AdministrativuController.list);
|
||||||
|
|||||||
Reference in New Issue
Block a user