feat: Add pack upload functionality

master
ogomez-at-wiris 2022-02-27 07:39:21 +01:00
parent ddbd9e8303
commit 5dabcc4649
5 changed files with 70 additions and 1 deletions

View File

@ -12,9 +12,11 @@
},
"dependencies": {
"@nodelib/fs.walk": "^1.2.8",
"@types/express-fileupload": "^1.2.2",
"@types/multistream": "^2.1.2",
"axios": "^0.26.0",
"express": "^4.17.3",
"express-fileupload": "^1.3.1",
"express-zip": "^3.0.0",
"morgan": "^1.10.0",
"nodemon": "^2.0.15",

9
src/pack_upload.ts Normal file
View File

@ -0,0 +1,9 @@
import { Request, Response, NextFunction, response } from "express";
export default class PackUploader {
public static uploadPack = async (
req: Request,
res: Response,
next: NextFunction
) => {};
}

View File

@ -1,7 +1,9 @@
import express from "express";
import PackAPI from "../pack_api";
import PackUploader from "../pack_upload";
export const packRoutes = express.Router();
packRoutes.get("/packs", PackAPI.getPacks);
packRoutes.get("/getpack", PackAPI.downloadSinglePack);
packRoutes.post("/upload", PackUploader.uploadPack);

View File

@ -1,11 +1,13 @@
import http from "http";
import express, { Express } from "express";
import morgan from "morgan";
import os from "os";
import { packRoutes } from "./routes/packs";
import PackAPI from "./pack_api";
import PackService from "./services/pack_service";
const router: Express = express();
const fileUpload = require("express-fileupload");
/** Logging */
router.use(morgan("dev"));
@ -14,6 +16,19 @@ router.use(express.urlencoded({ extended: false }));
/** Takes care of JSON data */
router.use(express.json());
/** File Upload */
router.use(
fileUpload({
useTempFiles: true,
tempFileDir: `${os.homedir()}/beatloads/tmp`,
createParentPath: true,
uriDecodeFileNames: true,
safeFileNames: true,
preserveExtension: true,
debug: true,
})
);
/** RULES OF OUR API */
router.use((req, res, next) => {
// set the CORS policy

View File

@ -82,6 +82,13 @@
"@types/connect" "*"
"@types/node" "*"
"@types/busboy@^0":
version "0.3.2"
resolved "https://registry.yarnpkg.com/@types/busboy/-/busboy-0.3.2.tgz#2f29b017513415399c42632ae6a7cfcb1409b79c"
integrity sha512-iEvdm9Z9KdSs/ozuh1Z7ZsXrOl8F4M/CLMXPZHr3QuJ4d6Bjn+HBMC5EMKpwpAo8oi8iK9GZfFoHaIMrrZgwVw==
dependencies:
"@types/node" "*"
"@types/connect@*":
version "3.4.35"
resolved "https://registry.yarnpkg.com/@types/connect/-/connect-3.4.35.tgz#5fcf6ae445e4021d1fc2219a4873cc73a3bb2ad1"
@ -89,6 +96,14 @@
dependencies:
"@types/node" "*"
"@types/express-fileupload@^1.2.2":
version "1.2.2"
resolved "https://registry.yarnpkg.com/@types/express-fileupload/-/express-fileupload-1.2.2.tgz#98c10e900c222744bba16c848505a1fa95ab3ff0"
integrity sha512-sWU1EVFfLsdAginKVrkwTRbRPnbn7dawxEFEBgaRDcpNFCUuksZtASaAKEhqwEIg6fSdeTyI6dIUGl3thhrypg==
dependencies:
"@types/busboy" "^0"
"@types/express" "*"
"@types/express-serve-static-core@^4.17.18":
version "4.17.28"
resolved "https://registry.yarnpkg.com/@types/express-serve-static-core/-/express-serve-static-core-4.17.28.tgz#c47def9f34ec81dc6328d0b1b5303d1ec98d86b8"
@ -98,7 +113,7 @@
"@types/qs" "*"
"@types/range-parser" "*"
"@types/express@^4.17.13":
"@types/express@*", "@types/express@^4.17.13":
version "4.17.13"
resolved "https://registry.yarnpkg.com/@types/express/-/express-4.17.13.tgz#a76e2995728999bab51a33fabce1d705a3709034"
integrity sha512-6bSZTPaTIACxn48l50SR+axgrqm6qXFIxrdAKaG6PaJk3+zuUr35hBlgT7vOmJcum+OEaIBLtHV/qloEAFITeA==
@ -318,6 +333,13 @@ buffer@^5.1.0:
base64-js "^1.3.1"
ieee754 "^1.1.13"
busboy@^0.3.1:
version "0.3.1"
resolved "https://registry.yarnpkg.com/busboy/-/busboy-0.3.1.tgz#170899274c5bf38aae27d5c62b71268cd585fd1b"
integrity sha512-y7tTxhGKXcyBxRKAni+awqx8uqaJKrSFSNFSeRG5CsWNdmy2BIK+6VGWEW7TZnIO/533mtMEA4rOevQV815YJw==
dependencies:
dicer "0.3.0"
bytes@3.1.2:
version "3.1.2"
resolved "https://registry.yarnpkg.com/bytes/-/bytes-3.1.2.tgz#8b0beeb98605adf1b128fa4386403c009e0221a5"
@ -518,6 +540,13 @@ destroy@~1.0.4:
resolved "https://registry.yarnpkg.com/destroy/-/destroy-1.0.4.tgz#978857442c44749e4206613e37946205826abd80"
integrity sha1-l4hXRCxEdJ5CBmE+N5RiBYJqvYA=
dicer@0.3.0:
version "0.3.0"
resolved "https://registry.yarnpkg.com/dicer/-/dicer-0.3.0.tgz#eacd98b3bfbf92e8ab5c2fdb71aaac44bb06b872"
integrity sha512-MdceRRWqltEG2dZqO769g27N/3PXfcKl04VhYnBlo2YhH7zPi88VebsjTKclaOyiuMaGU72hTfw3VkUitGcVCA==
dependencies:
streamsearch "0.1.2"
diff@^4.0.1:
version "4.0.2"
resolved "https://registry.yarnpkg.com/diff/-/diff-4.0.2.tgz#60f3aecb89d5fae520c11aa19efc2bb982aade7d"
@ -572,6 +601,13 @@ etag@~1.8.1:
resolved "https://registry.yarnpkg.com/etag/-/etag-1.8.1.tgz#41ae2eeb65efa62268aebfea83ac7d79299b0887"
integrity sha1-Qa4u62XvpiJorr/qg6x9eSmbCIc=
express-fileupload@^1.3.1:
version "1.3.1"
resolved "https://registry.yarnpkg.com/express-fileupload/-/express-fileupload-1.3.1.tgz#3238472def305b8cb4cc5936a953761d0c442011"
integrity sha512-LD1yabD3exmWIFujKGDnT1rmxSomaqQSlUvzIsrA1ZgwCJ6ci7lg2YHFGM3Q6DfK+Yk0gAVU7GWLE7qDMwZLkw==
dependencies:
busboy "^0.3.1"
express-zip@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/express-zip/-/express-zip-3.0.0.tgz#f2590d5dd895842b51e9593c2af8dbfe3e5190f0"
@ -1355,6 +1391,11 @@ signal-exit@^3.0.2:
resolved "https://registry.yarnpkg.com/statuses/-/statuses-1.5.0.tgz#161c7dac177659fd9811f43771fa99381478628c"
integrity sha1-Fhx9rBd2Wf2YEfQ3cfqZOBR4Yow=
streamsearch@0.1.2:
version "0.1.2"
resolved "https://registry.yarnpkg.com/streamsearch/-/streamsearch-0.1.2.tgz#808b9d0e56fc273d809ba57338e929919a1a9f1a"
integrity sha1-gIudDlb8Jz2Am6VzOOkpkZoanxo=
string-width@^4.0.0, string-width@^4.1.0, string-width@^4.2.2:
version "4.2.3"
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"