add pack upload file
parent
5dabcc4649
commit
434a54b038
|
@ -1,9 +1,29 @@
|
|||
import { Request, Response, NextFunction, response } from "express";
|
||||
import os from "os";
|
||||
|
||||
const uploadsFolder = `${os.homedir()}/beatloads`;
|
||||
|
||||
export default class PackUploader {
|
||||
public static uploadPack = async (
|
||||
req: Request,
|
||||
req: any,
|
||||
res: Response,
|
||||
next: NextFunction
|
||||
) => {};
|
||||
) => {
|
||||
let packName;
|
||||
|
||||
if (!req.files || Object.keys(req.files).length === 0) {
|
||||
return res.status(400).send("No files were uploaded.");
|
||||
}
|
||||
try {
|
||||
const packFile = req.files.pack;
|
||||
packName = req.files.pack.name;
|
||||
const path = `${uploadsFolder}/${packName}`;
|
||||
|
||||
await packFile.mv(path);
|
||||
} catch (error) {
|
||||
return res.status(500).send(error);
|
||||
}
|
||||
|
||||
return res.status(200).send("File uploaded!");
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue