1
0
mirror of https://gitlab.com/comunic/comunicapiv2 synced 2025-06-21 17:15:17 +00:00

Can check for uploaded files

This commit is contained in:
2019-11-30 18:10:25 +01:00
parent fef321f0ff
commit 4a280e312c
4 changed files with 71 additions and 2 deletions

View File

@ -3,6 +3,7 @@ import { APIHelper } from "../helpers/APIHelper";
import { APIClient } from "./APIClient";
import { checkMail } from "../utils/StringUtils";
import { AccountHelper } from "../helpers/AccountHelper";
import { UploadedFile } from "express-fileupload";
/**
* Response to a request
@ -169,6 +170,31 @@ export class RequestHandler {
return param === "true" || param === true;
}
/**
* Get information about an uploaded file
*
* @param name The name of the posted file
*/
private GetUploadedFile(name: string) : undefined | UploadedFile {
if(!this.req.files)
return undefined;
if(this.req.files[name] instanceof Array)
this.error(500, "Multiple upload are not supported!");
return <UploadedFile|undefined>this.req.files[name];
}
/**
* Check out whether a file has been included in the request or not
*
* @param name The name of the file to check
*/
public hasFile(name: string) : boolean {
return this.GetUploadedFile(name) != undefined;
}
/**
* Validate API tokens