mirror of
https://gitlab.com/comunic/comunicapiv2
synced 2025-06-20 00:25:17 +00:00
Can check for uploaded files
This commit is contained in:
@ -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
|
||||
|
@ -3,6 +3,7 @@ import { ConfigurationHelper, conf } from "./helpers/ConfigHelper";
|
||||
import { DatabaseHelper } from "./helpers/DatabaseHelper";
|
||||
import { Routes, RouteType } from './controllers/Routes';
|
||||
import { RequestHandler } from './entities/RequestHandler';
|
||||
import * as fileUpload from 'express-fileupload';
|
||||
|
||||
/**
|
||||
* Main project script
|
||||
@ -25,6 +26,8 @@ async function init() {
|
||||
|
||||
app.use(express.urlencoded({extended: true}));
|
||||
|
||||
app.use(fileUpload());
|
||||
|
||||
// Process the list of routes
|
||||
Routes.forEach(route => {
|
||||
|
||||
|
Reference in New Issue
Block a user