mirror of
				https://gitlab.com/comunic/comunicapiv2
				synced 2025-11-04 11:34:04 +00:00 
			
		
		
		
	Can check for uploaded files
This commit is contained in:
		
							
								
								
									
										38
									
								
								package-lock.json
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										38
									
								
								package-lock.json
									
									
									
										generated
									
									
									
								
							@@ -34,6 +34,15 @@
 | 
			
		||||
        "@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": {
 | 
			
		||||
      "version": "4.17.0",
 | 
			
		||||
      "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=",
 | 
			
		||||
      "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": {
 | 
			
		||||
      "version": "3.1.0",
 | 
			
		||||
      "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",
 | 
			
		||||
      "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": {
 | 
			
		||||
      "version": "5.0.3",
 | 
			
		||||
      "resolved": "https://registry.npmjs.org/diffie-hellman/-/diffie-hellman-5.0.3.tgz",
 | 
			
		||||
@@ -1470,6 +1495,14 @@
 | 
			
		||||
        "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": {
 | 
			
		||||
      "version": "3.0.2",
 | 
			
		||||
      "resolved": "https://registry.npmjs.org/extend-shallow/-/extend-shallow-3.0.2.tgz",
 | 
			
		||||
@@ -4165,6 +4198,11 @@
 | 
			
		||||
      "integrity": "sha1-1cdSgl5TZ+eG944Y5EXqIjoVWVI=",
 | 
			
		||||
      "dev": true
 | 
			
		||||
    },
 | 
			
		||||
    "streamsearch": {
 | 
			
		||||
      "version": "0.1.2",
 | 
			
		||||
      "resolved": "https://registry.npmjs.org/streamsearch/-/streamsearch-0.1.2.tgz",
 | 
			
		||||
      "integrity": "sha1-gIudDlb8Jz2Am6VzOOkpkZoanxo="
 | 
			
		||||
    },
 | 
			
		||||
    "string-width": {
 | 
			
		||||
      "version": "2.1.1",
 | 
			
		||||
      "resolved": "https://registry.npmjs.org/string-width/-/string-width-2.1.1.tgz",
 | 
			
		||||
 
 | 
			
		||||
@@ -9,12 +9,14 @@
 | 
			
		||||
  "author": "",
 | 
			
		||||
  "license": "MIT",
 | 
			
		||||
  "dependencies": {
 | 
			
		||||
    "express": "^4.17.1",
 | 
			
		||||
    "express-fileupload": "^1.1.6",
 | 
			
		||||
    "mysql": "^2.17.1",
 | 
			
		||||
    "typescript": "^3.7.2",
 | 
			
		||||
    "express": "^4.17.1"
 | 
			
		||||
    "typescript": "^3.7.2"
 | 
			
		||||
  },
 | 
			
		||||
  "devDependencies": {
 | 
			
		||||
    "@types/express": "^4.17.2",
 | 
			
		||||
    "@types/express-fileupload": "^1.1.0",
 | 
			
		||||
    "@types/mysql": "^2.15.8",
 | 
			
		||||
    "@types/node": "^12.12.8",
 | 
			
		||||
    "nodemon": "^2.0.0",
 | 
			
		||||
 
 | 
			
		||||
@@ -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