chamesu
Version:
This package contains all packages of the chat application.
37 lines (25 loc) • 882 B
text/typescript
/*
* Copyright (c) 2022.
* Author Peter Placzek (tada5hi)
* For the full copyright and license information,
* view the LICENSE file that was distributed with this source code.
*/
import {Middleware} from "@decorators/express";
import {NextFunction, Request, Response} from "express";
import multer, {Multer, Field} from 'multer';
let instance : Multer | undefined;
export function useMulter() {
if(typeof instance !== 'undefined') {
return instance;
}
const storage = multer.memoryStorage();
instance = multer({storage: storage, limits: {fieldSize: 25 * 1024 * 1024}});
return instance;
}
export function createMulterFieldsMiddleware(fields: Field[]) {
return class implements Middleware {
public use(request: Request, response: Response, next: NextFunction) {
return useMulter().fields(fields);
}
}
}