42 lines
1.5 KiB
JavaScript
42 lines
1.5 KiB
JavaScript
"use strict";
|
|
/**
|
|
* Multer middleware for Android APK uploads into the staging directory.
|
|
*/
|
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
};
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.apkUpload = void 0;
|
|
const multer_1 = __importDefault(require("multer"));
|
|
const path_1 = __importDefault(require("path"));
|
|
const uuid_1 = require("uuid");
|
|
const apkStorageService_1 = require("../services/apkStorageService");
|
|
const APK_MIMES = new Set([
|
|
'application/vnd.android.package-archive',
|
|
'application/octet-stream',
|
|
'application/zip',
|
|
'application/java-archive',
|
|
]);
|
|
const storage = multer_1.default.diskStorage({
|
|
destination(_req, _file, cb) {
|
|
cb(null, (0, apkStorageService_1.ensureApkStagingDir)());
|
|
},
|
|
filename(_req, file, cb) {
|
|
const ext = path_1.default.extname(file.originalname).toLowerCase() === '.apk' ? '.apk' : '.apk';
|
|
cb(null, `${(0, uuid_1.v4)()}${ext}`);
|
|
},
|
|
});
|
|
exports.apkUpload = (0, multer_1.default)({
|
|
storage,
|
|
limits: { fileSize: (0, apkStorageService_1.getApkMaxUploadBytes)(), files: 1 },
|
|
fileFilter(_req, file, cb) {
|
|
const extOk = path_1.default.extname(file.originalname).toLowerCase() === '.apk';
|
|
if (extOk || APK_MIMES.has(file.mimetype)) {
|
|
cb(null, true);
|
|
}
|
|
else {
|
|
cb(new Error('Only .apk files are allowed'));
|
|
}
|
|
},
|
|
});
|
|
//# sourceMappingURL=apkUpload.js.map
|