ali-flmngr-server-fixed
Version:
> Node.js Backend for Flmngr file manager
55 lines • 2.31 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ActionUploadInit = void 0;
const AAction_1 = require("../action/AAction");
const fsx = __importStar(require("fs-extra"));
const MessageException_1 = require("../MessageException");
const Message_1 = require("../action/resp/Message");
const RespUploadInit_1 = require("../action/resp/RespUploadInit");
class ActionUploadInit extends AAction_1.AAction {
getName() {
return "uploadInit";
}
run(request, onFinish) {
let alphabeth = "abcdefghijklmnopqrstuvwxyz0123456789";
let dir;
let id;
do {
id = "";
for (let i = 0; i < 6; i++) {
let charNumber = Math.floor(Math.random() * alphabeth.length);
id += alphabeth.substring(charNumber, charNumber + 1);
}
dir = this.m_config.getTmpDir() + "/" + id;
} while (fsx.existsSync(dir) && fsx.lstatSync(dir).isDirectory());
try {
fsx.mkdirsSync(dir);
}
catch (e) {
console.log(e);
throw new MessageException_1.MessageException(Message_1.Message.createMessage(Message_1.Message.UNABLE_TO_CREATE_UPLOAD_DIR));
}
onFinish(new RespUploadInit_1.RespUploadInit(id, this.m_config));
}
}
exports.ActionUploadInit = ActionUploadInit;
//# sourceMappingURL=ActionUploadInit.js.map