"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.StorageWebservice = void 0;
var bfastnode_1 = require("bfastnode");
var restController;
var StorageWebservice = (function () {
    function StorageWebservice(rest) {
        restController = rest;
    }
    StorageWebservice.handleGetFile = function () {
        return [
            function (request, _, next) {
                request.body.applicationId = request.params.appId;
                request.body.ruleId = 'files.read';
                next();
            },
            restController.verifyApplicationId,
            restController.verifyToken,
            restController.filePolicy,
            restController.getFile
        ];
    };
    StorageWebservice.handleUploadFile = function () {
        return [
            function (request, response, next) {
                request.body.applicationId = request.params.appId;
                request.body.ruleId = 'files.save';
                next();
            },
            restController.verifyApplicationId,
            restController.verifyToken,
            restController.filePolicy,
            restController.multipartForm
        ];
    };
    StorageWebservice.handleGetThumbnail = function () {
        return [
            function (request, _, next) {
                request.body.applicationId = request.params.appId;
                request.body.ruleId = 'files.read';
                next();
            },
            restController.verifyApplicationId,
            restController.verifyToken,
            restController.filePolicy,
            restController.getThumbnail
        ];
    };
    StorageWebservice.handleListFiles = function () {
        return [
            function (request, _, next) {
                request.body.applicationId = request.params.appId;
                request.body.ruleId = 'files.list';
                next();
            },
            restController.verifyApplicationId,
            restController.verifyToken,
            restController.filePolicy,
            restController.getAllFiles
        ];
    };
    StorageWebservice.prototype.getUploadFileV2 = function (prefix) {
        if (prefix === void 0) { prefix = '/'; }
        return bfastnode_1.BFast.functions().onGetHttpRequest(prefix + "storage/:appId", function (request, response) {
            response.writeHead(200, { 'content-type': 'text/html' });
            response.end("\n                    <h2>With Node.js <code>\"http\"</code> module</h2>\n                    <form action=\"" + prefix + "storage/" + request.params.appId + "\" enctype=\"multipart/form-data\" method=\"post\">\n                      <div>Text field title: <input type=\"text\" name=\"file\" /></div>\n                      <div>File: <input type=\"file\" name=\"multipleFiles\" multiple=\"multiple\" /></div>\n                      <input type=\"submit\" value=\"Upload\" />\n                    </form>\n                 ");
        });
    };
    StorageWebservice.prototype.getFileStorageV1 = function (prefix) {
        if (prefix === void 0) { prefix = '/'; }
        return bfastnode_1.BFast.functions().onGetHttpRequest(prefix + "files/:appId/:filename", StorageWebservice.handleGetFile());
    };
    StorageWebservice.prototype.getFileFromStorage = function (prefix) {
        if (prefix === void 0) { prefix = '/'; }
        return bfastnode_1.BFast.functions().onGetHttpRequest(prefix + "storage/:appId/file/:filename", StorageWebservice.handleGetFile());
    };
    StorageWebservice.prototype.getFileFromStorageV2 = function (prefix) {
        if (prefix === void 0) { prefix = '/'; }
        return bfastnode_1.BFast.functions().onGetHttpRequest(prefix + "v2/storage/:appId/file/:filename", StorageWebservice.handleGetFile());
    };
    StorageWebservice.prototype.geThumbnailFromStorage = function (prefix) {
        if (prefix === void 0) { prefix = '/'; }
        return bfastnode_1.BFast.functions().onGetHttpRequest(prefix + "storage/:appId/file/:filename/thumbnail", StorageWebservice.handleGetThumbnail());
    };
    StorageWebservice.prototype.geThumbnailFromStorageV2 = function (prefix) {
        if (prefix === void 0) { prefix = '/'; }
        return bfastnode_1.BFast.functions().onGetHttpRequest(prefix + "v2/storage/:appId/file/:filename/thumbnail", StorageWebservice.handleGetThumbnail());
    };
    StorageWebservice.prototype.uploadMultiPartFile = function (prefix) {
        if (prefix === void 0) { prefix = '/'; }
        return bfastnode_1.BFast.functions().onPostHttpRequest(prefix + "storage/:appId", StorageWebservice.handleUploadFile());
    };
    StorageWebservice.prototype.uploadMultiPartFileV2 = function (prefix) {
        if (prefix === void 0) { prefix = '/'; }
        return bfastnode_1.BFast.functions().onPostHttpRequest(prefix + "v2/storage/:appId", StorageWebservice.handleUploadFile());
    };
    StorageWebservice.prototype.getFilesFromStorage = function (prefix) {
        if (prefix === void 0) { prefix = '/'; }
        return bfastnode_1.BFast.functions().onGetHttpRequest(prefix + "storage/:appId/list", StorageWebservice.handleListFiles());
    };
    StorageWebservice.prototype.getFilesFromStorageV2 = function (prefix) {
        if (prefix === void 0) { prefix = '/'; }
        return bfastnode_1.BFast.functions().onGetHttpRequest(prefix + "v2/storage/:appId/list", StorageWebservice.handleListFiles());
    };
    return StorageWebservice;
}());
exports.StorageWebservice = StorageWebservice;
