1
0
mirror of https://gitlab.com/comunic/comunicapiv2 synced 2024-11-22 05:19:22 +00:00

Can check for uploaded files

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

38
package-lock.json generated
View File

@ -34,6 +34,15 @@
"@types/serve-static": "*" "@types/serve-static": "*"
} }
}, },
"@types/express-fileupload": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/@types/express-fileupload/-/express-fileupload-1.1.0.tgz",
"integrity": "sha512-l7ElHOlTt3Dis1My3LvEwP4tDw/cYiM1sor5nQY8aRm8HPVwalG48lf7ym9k2/z/PwRGADABGgIhv0a6y7XzoA==",
"dev": true,
"requires": {
"@types/express": "*"
}
},
"@types/express-serve-static-core": { "@types/express-serve-static-core": {
"version": "4.17.0", "version": "4.17.0",
"resolved": "https://registry.npmjs.org/@types/express-serve-static-core/-/express-serve-static-core-4.17.0.tgz", "resolved": "https://registry.npmjs.org/@types/express-serve-static-core/-/express-serve-static-core-4.17.0.tgz",
@ -723,6 +732,14 @@
"integrity": "sha1-hZgoeOIbmOHGZCXgPQF0eI9Wnug=", "integrity": "sha1-hZgoeOIbmOHGZCXgPQF0eI9Wnug=",
"dev": true "dev": true
}, },
"busboy": {
"version": "0.3.1",
"resolved": "https://registry.npmjs.org/busboy/-/busboy-0.3.1.tgz",
"integrity": "sha512-y7tTxhGKXcyBxRKAni+awqx8uqaJKrSFSNFSeRG5CsWNdmy2BIK+6VGWEW7TZnIO/533mtMEA4rOevQV815YJw==",
"requires": {
"dicer": "0.3.0"
}
},
"bytes": { "bytes": {
"version": "3.1.0", "version": "3.1.0",
"resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.0.tgz", "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.0.tgz",
@ -1210,6 +1227,14 @@
"resolved": "https://registry.npmjs.org/destroy/-/destroy-1.0.4.tgz", "resolved": "https://registry.npmjs.org/destroy/-/destroy-1.0.4.tgz",
"integrity": "sha1-l4hXRCxEdJ5CBmE+N5RiBYJqvYA=" "integrity": "sha1-l4hXRCxEdJ5CBmE+N5RiBYJqvYA="
}, },
"dicer": {
"version": "0.3.0",
"resolved": "https://registry.npmjs.org/dicer/-/dicer-0.3.0.tgz",
"integrity": "sha512-MdceRRWqltEG2dZqO769g27N/3PXfcKl04VhYnBlo2YhH7zPi88VebsjTKclaOyiuMaGU72hTfw3VkUitGcVCA==",
"requires": {
"streamsearch": "0.1.2"
}
},
"diffie-hellman": { "diffie-hellman": {
"version": "5.0.3", "version": "5.0.3",
"resolved": "https://registry.npmjs.org/diffie-hellman/-/diffie-hellman-5.0.3.tgz", "resolved": "https://registry.npmjs.org/diffie-hellman/-/diffie-hellman-5.0.3.tgz",
@ -1470,6 +1495,14 @@
"vary": "~1.1.2" "vary": "~1.1.2"
} }
}, },
"express-fileupload": {
"version": "1.1.6",
"resolved": "https://registry.npmjs.org/express-fileupload/-/express-fileupload-1.1.6.tgz",
"integrity": "sha512-w24zPWT8DkoIxSVkbxYPo9hkTiLpCQQzNsLRTCnecBhfbYv+IkIC5uLw2MIUAxBZ+7UMmXPjGxlhzUXo4RcbZw==",
"requires": {
"busboy": "^0.3.1"
}
},
"extend-shallow": { "extend-shallow": {
"version": "3.0.2", "version": "3.0.2",
"resolved": "https://registry.npmjs.org/extend-shallow/-/extend-shallow-3.0.2.tgz", "resolved": "https://registry.npmjs.org/extend-shallow/-/extend-shallow-3.0.2.tgz",
@ -4165,6 +4198,11 @@
"integrity": "sha1-1cdSgl5TZ+eG944Y5EXqIjoVWVI=", "integrity": "sha1-1cdSgl5TZ+eG944Y5EXqIjoVWVI=",
"dev": true "dev": true
}, },
"streamsearch": {
"version": "0.1.2",
"resolved": "https://registry.npmjs.org/streamsearch/-/streamsearch-0.1.2.tgz",
"integrity": "sha1-gIudDlb8Jz2Am6VzOOkpkZoanxo="
},
"string-width": { "string-width": {
"version": "2.1.1", "version": "2.1.1",
"resolved": "https://registry.npmjs.org/string-width/-/string-width-2.1.1.tgz", "resolved": "https://registry.npmjs.org/string-width/-/string-width-2.1.1.tgz",

View File

@ -9,12 +9,14 @@
"author": "", "author": "",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"express": "^4.17.1",
"express-fileupload": "^1.1.6",
"mysql": "^2.17.1", "mysql": "^2.17.1",
"typescript": "^3.7.2", "typescript": "^3.7.2"
"express": "^4.17.1"
}, },
"devDependencies": { "devDependencies": {
"@types/express": "^4.17.2", "@types/express": "^4.17.2",
"@types/express-fileupload": "^1.1.0",
"@types/mysql": "^2.15.8", "@types/mysql": "^2.15.8",
"@types/node": "^12.12.8", "@types/node": "^12.12.8",
"nodemon": "^2.0.0", "nodemon": "^2.0.0",

View File

@ -3,6 +3,7 @@ import { APIHelper } from "../helpers/APIHelper";
import { APIClient } from "./APIClient"; import { APIClient } from "./APIClient";
import { checkMail } from "../utils/StringUtils"; import { checkMail } from "../utils/StringUtils";
import { AccountHelper } from "../helpers/AccountHelper"; import { AccountHelper } from "../helpers/AccountHelper";
import { UploadedFile } from "express-fileupload";
/** /**
* Response to a request * Response to a request
@ -169,6 +170,31 @@ export class RequestHandler {
return param === "true" || param === true; 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 * Validate API tokens

View File

@ -3,6 +3,7 @@ import { ConfigurationHelper, conf } from "./helpers/ConfigHelper";
import { DatabaseHelper } from "./helpers/DatabaseHelper"; import { DatabaseHelper } from "./helpers/DatabaseHelper";
import { Routes, RouteType } from './controllers/Routes'; import { Routes, RouteType } from './controllers/Routes';
import { RequestHandler } from './entities/RequestHandler'; import { RequestHandler } from './entities/RequestHandler';
import * as fileUpload from 'express-fileupload';
/** /**
* Main project script * Main project script
@ -25,6 +26,8 @@ async function init() {
app.use(express.urlencoded({extended: true})); app.use(express.urlencoded({extended: true}));
app.use(fileUpload());
// Process the list of routes // Process the list of routes
Routes.forEach(route => { Routes.forEach(route => {