UNPKG

@crowdin/app-project-module

Version:

Module that generates for you all common endpoints for serving standalone Crowdin App

47 lines (46 loc) 2.4 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.register = register; const crowdin_client_1 = __importDefault(require("../../middlewares/crowdin-client")); const util_1 = require("../../util"); const normalize_module_1 = require("../../util/normalize-module"); const file_download_1 = __importDefault(require("../file-processing/handlers/file-download")); const folder_1 = require("../file-processing/util/folder"); const translate_1 = __importDefault(require("./handlers/translate")); function register({ config, app }) { var _a; if (!config.customMT) { return; } const items = (0, normalize_module_1.normalizeToArray)(config.customMT); const isSingle = items.length === 1; for (const [index, mt] of items.entries()) { const key = (_a = mt.key) !== null && _a !== void 0 ? _a : (0, normalize_module_1.resolveInstanceKey)({ identifier: config.identifier, suffix: 'mt', item: mt, index, isSingle }); const folder = (0, folder_1.resolveModuleFilesFolder)(config.dbFolder, mt.filesFolder); const logoPath = isSingle ? '/logo/mt' : `/logo/mt-${key}`; const translatePath = isSingle ? '/mt/translate' : `/mt/${key}/translate`; const downloadPath = isSingle ? '/file/download/custom-mt' : `/file/download/custom-mt-${key}`; app.use(logoPath, (0, util_1.serveLogo)(config, mt)); app.post(translatePath, (0, crowdin_client_1.default)({ config, optional: false, checkSubscriptionExpiration: true, moduleKey: key, }), (0, translate_1.default)({ baseUrl: config.baseUrl, folder, config: mt, fileStore: config.fileStore })); app.get(downloadPath, (0, file_download_1.default)(config, mt, 'custom-mt')); } if (isSingle) { const mt = items[0]; const folder = mt.filesFolder || config.dbFolder; // TEMPORARY CODE: it needs to support old path app.post('/translate', (0, crowdin_client_1.default)({ config, optional: false, checkSubscriptionExpiration: true, }), (0, translate_1.default)({ baseUrl: config.baseUrl, folder, config: mt, fileStore: config.fileStore })); // END TEMPORARY CODE } }