@crowdin/app-project-module 0.28.0-10 → 0.28.0-11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/out/handlers/{custom-file-format/process.js → file-processing/custom-file-format.js} +8 -23
- package/out/handlers/file-processing/file-download.d.ts +4 -0
- package/out/handlers/{custom-file-format/download.js → file-processing/file-download.js} +3 -2
- package/out/handlers/file-processing/pre-post-process.d.ts +4 -0
- package/out/handlers/file-processing/pre-post-process.js +96 -0
- package/out/handlers/manifest.js +36 -0
- package/out/index.js +24 -6
- package/out/models/index.d.ts +39 -14
- package/out/models/index.js +4 -0
- package/out/util/files.d.ts +3 -0
- package/out/util/files.js +43 -0
- package/package.json +1 -1
- package/out/handlers/custom-file-format/download.d.ts +0 -4
- /package/out/handlers/{custom-file-format/process.d.ts → file-processing/custom-file-format.d.ts} +0 -0
package/out/handlers/{custom-file-format/process.js → file-processing/custom-file-format.js}
RENAMED
|
@@ -12,12 +12,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
const axios_1 = __importDefault(require("axios"));
|
|
16
15
|
const fs_1 = __importDefault(require("fs"));
|
|
17
16
|
const path_1 = __importDefault(require("path"));
|
|
18
17
|
const models_1 = require("../../models");
|
|
19
18
|
const util_1 = require("../../util");
|
|
20
|
-
const
|
|
19
|
+
const files_1 = require("../../util/files");
|
|
21
20
|
function handle(baseConfig, baseUrl, folder, config) {
|
|
22
21
|
if (!fs_1.default.existsSync(path_1.default.join(folder, 'custom-file-format'))) {
|
|
23
22
|
fs_1.default.mkdirSync(path_1.default.join(folder, 'custom-file-format'), { recursive: true });
|
|
@@ -38,7 +37,7 @@ function handle(baseConfig, baseUrl, folder, config) {
|
|
|
38
37
|
file = Buffer.from(body.file.content, 'base64').toString();
|
|
39
38
|
}
|
|
40
39
|
else if (body.file.contentUrl) {
|
|
41
|
-
file =
|
|
40
|
+
file = yield (0, files_1.getFileContent)(body.file.contentUrl);
|
|
42
41
|
}
|
|
43
42
|
let response = {};
|
|
44
43
|
let error;
|
|
@@ -71,10 +70,7 @@ function handleBuildFile(baseUrl, dataFolder, config, req, client, context, proj
|
|
|
71
70
|
strings = req.strings;
|
|
72
71
|
}
|
|
73
72
|
else {
|
|
74
|
-
|
|
75
|
-
const response = (yield axios_1.default.get(req.stringsUrl)).data;
|
|
76
|
-
const jsonRows = response.split(/\n|\n\r/).filter(Boolean);
|
|
77
|
-
strings = jsonRows.map((jsonStringRow) => JSON.parse(jsonStringRow));
|
|
73
|
+
strings = yield (0, files_1.getFileContent)(req.stringsUrl, true);
|
|
78
74
|
}
|
|
79
75
|
let res;
|
|
80
76
|
if ((req.file.id || !file) && config.exportStrings) {
|
|
@@ -87,7 +83,7 @@ function handleBuildFile(baseUrl, dataFolder, config, req, client, context, proj
|
|
|
87
83
|
return { response };
|
|
88
84
|
}
|
|
89
85
|
const contentFileEncoded = Buffer.from(res.contentFile).toString('base64');
|
|
90
|
-
if (Buffer.byteLength(contentFileEncoded, 'utf8') < MAX_BODY_SIZE) {
|
|
86
|
+
if (Buffer.byteLength(contentFileEncoded, 'utf8') < files_1.MAX_BODY_SIZE) {
|
|
91
87
|
response.content = contentFileEncoded;
|
|
92
88
|
}
|
|
93
89
|
else {
|
|
@@ -96,7 +92,7 @@ function handleBuildFile(baseUrl, dataFolder, config, req, client, context, proj
|
|
|
96
92
|
url = yield config.storeFile(res.contentFile);
|
|
97
93
|
}
|
|
98
94
|
else {
|
|
99
|
-
const storedFile = yield storeFile(res.contentFile, dataFolder);
|
|
95
|
+
const storedFile = yield (0, files_1.storeFile)(res.contentFile, path_1.default.join(dataFolder, 'custom-file-format'));
|
|
100
96
|
url = `${baseUrl}?file=${storedFile}`;
|
|
101
97
|
}
|
|
102
98
|
response.contentUrl = url;
|
|
@@ -111,7 +107,7 @@ function handleParseFile(baseUrl, dataFolder, config, req, client, context, proj
|
|
|
111
107
|
return { response };
|
|
112
108
|
}
|
|
113
109
|
const res = yield config.parseFile(file, req, client, context, projectId);
|
|
114
|
-
let maxSize = MAX_BODY_SIZE;
|
|
110
|
+
let maxSize = files_1.MAX_BODY_SIZE;
|
|
115
111
|
if (res.strings && res.previewFile) {
|
|
116
112
|
maxSize = maxSize / 2;
|
|
117
113
|
}
|
|
@@ -126,7 +122,7 @@ function handleParseFile(baseUrl, dataFolder, config, req, client, context, proj
|
|
|
126
122
|
url = yield config.storeFile(res.previewFile);
|
|
127
123
|
}
|
|
128
124
|
else {
|
|
129
|
-
const storedFile = yield storeFile(res.previewFile, dataFolder);
|
|
125
|
+
const storedFile = yield (0, files_1.storeFile)(res.previewFile, path_1.default.join(dataFolder, 'custom-file-format'));
|
|
130
126
|
url = `${baseUrl}?file=${storedFile}`;
|
|
131
127
|
}
|
|
132
128
|
response.previewUrl = url;
|
|
@@ -153,7 +149,7 @@ function handleParseFile(baseUrl, dataFolder, config, req, client, context, proj
|
|
|
153
149
|
url = yield config.storeFile(stringsNDJson);
|
|
154
150
|
}
|
|
155
151
|
else {
|
|
156
|
-
const storedFile = yield storeFile(stringsNDJson, dataFolder);
|
|
152
|
+
const storedFile = yield (0, files_1.storeFile)(stringsNDJson, path_1.default.join(dataFolder, 'custom-file-format'));
|
|
157
153
|
url = `${baseUrl}?file=${storedFile}`;
|
|
158
154
|
}
|
|
159
155
|
response.stringsUrl = url;
|
|
@@ -162,14 +158,3 @@ function handleParseFile(baseUrl, dataFolder, config, req, client, context, proj
|
|
|
162
158
|
return { response, error: res.error };
|
|
163
159
|
});
|
|
164
160
|
}
|
|
165
|
-
function storeFile(fileContent, folder) {
|
|
166
|
-
const fileName = `file${Date.now()}`;
|
|
167
|
-
return new Promise((res, rej) => fs_1.default.writeFile(path_1.default.join(folder, 'custom-file-format', fileName), fileContent, (err) => {
|
|
168
|
-
if (err) {
|
|
169
|
-
rej(err);
|
|
170
|
-
}
|
|
171
|
-
else {
|
|
172
|
-
res(fileName);
|
|
173
|
-
}
|
|
174
|
-
}));
|
|
175
|
-
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/// <reference types="qs" />
|
|
2
|
+
import { Request, Response } from 'express';
|
|
3
|
+
import { Config, FileProcessLogic } from '../../models';
|
|
4
|
+
export default function handle(config: Config, processingConfig: FileProcessLogic, folderName: string): (req: Request<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>>, res: Response<any, Record<string, any>>, next: Function) => void;
|
|
@@ -15,9 +15,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
15
15
|
const fs_1 = __importDefault(require("fs"));
|
|
16
16
|
const path_1 = __importDefault(require("path"));
|
|
17
17
|
const util_1 = require("../../util");
|
|
18
|
-
function handle(config,
|
|
18
|
+
function handle(config, processingConfig, folderName) {
|
|
19
|
+
const folder = processingConfig.filesFolder || config.dbFolder || '/';
|
|
19
20
|
return (0, util_1.runAsyncWrapper)((req, res) => __awaiter(this, void 0, void 0, function* () {
|
|
20
|
-
const filePath = path_1.default.join(folder,
|
|
21
|
+
const filePath = path_1.default.join(folder, folderName, req.query.file);
|
|
21
22
|
(0, util_1.log)(`Downloading file ${filePath}`, config.logger);
|
|
22
23
|
res.download(filePath, function (err) {
|
|
23
24
|
if (err) {
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/// <reference types="qs" />
|
|
2
|
+
import { Response } from 'express';
|
|
3
|
+
import { Config, FileImportExportLogic } from '../../models';
|
|
4
|
+
export default function handle(baseConfig: Config, config: FileImportExportLogic, folderName: string): (req: import("express").Request<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>>, res: Response<any, Record<string, any>>, next: Function) => void;
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const fs_1 = __importDefault(require("fs"));
|
|
16
|
+
const path_1 = __importDefault(require("path"));
|
|
17
|
+
const models_1 = require("../../models");
|
|
18
|
+
const util_1 = require("../../util");
|
|
19
|
+
const files_1 = require("../../util/files");
|
|
20
|
+
function handle(baseConfig, config, folderName) {
|
|
21
|
+
const folderPath = config.filesFolder || baseConfig.dbFolder || '/';
|
|
22
|
+
if (!fs_1.default.existsSync(path_1.default.join(folderPath, folderName))) {
|
|
23
|
+
fs_1.default.mkdirSync(path_1.default.join(folderPath, folderName), { recursive: true });
|
|
24
|
+
}
|
|
25
|
+
return (0, util_1.runAsyncWrapper)((req, res) => __awaiter(this, void 0, void 0, function* () {
|
|
26
|
+
const response = {};
|
|
27
|
+
const baseFilesUrl = `${baseConfig.baseUrl}/file/download/${folderName}`;
|
|
28
|
+
const body = req.body;
|
|
29
|
+
let processingError;
|
|
30
|
+
let fileContent;
|
|
31
|
+
if (body.stringsUrl) {
|
|
32
|
+
fileContent = yield (0, files_1.getFileContent)(body.stringsUrl, true);
|
|
33
|
+
}
|
|
34
|
+
else if (body.strings) {
|
|
35
|
+
fileContent = body.strings;
|
|
36
|
+
}
|
|
37
|
+
else if (body.file.contentUrl) {
|
|
38
|
+
fileContent = yield (0, files_1.getFileContent)(body.file.contentUrl);
|
|
39
|
+
}
|
|
40
|
+
else if (body.file.content) {
|
|
41
|
+
fileContent = Buffer.from(body.file.content, 'base64').toString();
|
|
42
|
+
}
|
|
43
|
+
const fileProcessResult = yield config.fileProcess(body, fileContent, req.crowdinApiClient, req.crowdinContext, req.crowdinContext.jwtPayload.context.project_id);
|
|
44
|
+
switch (body.jobType) {
|
|
45
|
+
case models_1.ProcessFileJobType.PRE_IMPORT:
|
|
46
|
+
case models_1.ProcessFileJobType.POST_EXPORT:
|
|
47
|
+
const { contentFile, fileName, error: contentFileError } = fileProcessResult;
|
|
48
|
+
if (contentFile) {
|
|
49
|
+
const contentFileEncoded = Buffer.from(contentFile).toString('base64');
|
|
50
|
+
if (Buffer.byteLength(contentFileEncoded, 'utf8') < files_1.MAX_BODY_SIZE) {
|
|
51
|
+
response.content = contentFileEncoded;
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
let url;
|
|
55
|
+
if (config.storeFile) {
|
|
56
|
+
url = yield config.storeFile(contentFile);
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
const storedFile = yield (0, files_1.storeFile)(contentFile, path_1.default.join(folderPath, folderName));
|
|
60
|
+
url = `${baseFilesUrl}?file=${storedFile}`;
|
|
61
|
+
}
|
|
62
|
+
response.contentUrl = url;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
if (fileName) {
|
|
66
|
+
response.fileName = fileName;
|
|
67
|
+
}
|
|
68
|
+
processingError = contentFileError;
|
|
69
|
+
break;
|
|
70
|
+
case models_1.ProcessFileJobType.POST_IMPORT:
|
|
71
|
+
case models_1.ProcessFileJobType.PRE_EXPORT:
|
|
72
|
+
const { strings, error: stringsFileError } = fileProcessResult;
|
|
73
|
+
if (strings) {
|
|
74
|
+
const stringsNDJson = strings.map((s) => JSON.stringify(s)).join('\n\r');
|
|
75
|
+
if (Buffer.byteLength(stringsNDJson, 'utf8') < files_1.MAX_BODY_SIZE) {
|
|
76
|
+
response.strings = strings;
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
let url;
|
|
80
|
+
if (config.storeFile) {
|
|
81
|
+
url = yield config.storeFile(stringsNDJson);
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
const storedFile = yield (0, files_1.storeFile)(stringsNDJson, path_1.default.join(folderPath, folderName));
|
|
85
|
+
url = `${baseFilesUrl}?file=${storedFile}`;
|
|
86
|
+
}
|
|
87
|
+
response.stringsUrl = url;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
processingError = stringsFileError;
|
|
91
|
+
break;
|
|
92
|
+
}
|
|
93
|
+
res.send({ data: response, error: processingError ? { message: processingError } : undefined });
|
|
94
|
+
}), baseConfig.onError);
|
|
95
|
+
}
|
|
96
|
+
exports.default = handle;
|
package/out/handlers/manifest.js
CHANGED
|
@@ -31,6 +31,42 @@ function handle(config) {
|
|
|
31
31
|
},
|
|
32
32
|
];
|
|
33
33
|
}
|
|
34
|
+
if (config.filePreImport) {
|
|
35
|
+
modules['file-pre-import'] = [
|
|
36
|
+
{
|
|
37
|
+
key: config.identifier + '-pri',
|
|
38
|
+
signaturePatterns: config.filePreImport.signaturePatterns,
|
|
39
|
+
url: '/pre-import',
|
|
40
|
+
},
|
|
41
|
+
];
|
|
42
|
+
}
|
|
43
|
+
if (config.filePostImport) {
|
|
44
|
+
modules['file-post-import'] = [
|
|
45
|
+
{
|
|
46
|
+
key: config.identifier + '-poi',
|
|
47
|
+
signaturePatterns: config.filePostImport.signaturePatterns,
|
|
48
|
+
url: '/post-import',
|
|
49
|
+
},
|
|
50
|
+
];
|
|
51
|
+
}
|
|
52
|
+
if (config.filePreExport) {
|
|
53
|
+
modules['file-pre-export'] = [
|
|
54
|
+
{
|
|
55
|
+
key: config.identifier + '-pre',
|
|
56
|
+
signaturePatterns: config.filePreExport.signaturePatterns,
|
|
57
|
+
url: '/pre-export',
|
|
58
|
+
},
|
|
59
|
+
];
|
|
60
|
+
}
|
|
61
|
+
if (config.filePostExport) {
|
|
62
|
+
modules['file-post-export'] = [
|
|
63
|
+
{
|
|
64
|
+
key: config.identifier + '-poe',
|
|
65
|
+
signaturePatterns: config.filePostExport.signaturePatterns,
|
|
66
|
+
url: '/post-export',
|
|
67
|
+
},
|
|
68
|
+
];
|
|
69
|
+
}
|
|
34
70
|
if (config.customMT) {
|
|
35
71
|
modules['custom-mt'] = [
|
|
36
72
|
{
|
package/out/index.js
CHANGED
|
@@ -46,8 +46,9 @@ const crowdin_project_1 = __importDefault(require("./handlers/crowdin-project"))
|
|
|
46
46
|
const crowdin_update_1 = __importDefault(require("./handlers/crowdin-update"));
|
|
47
47
|
const crowdin_webhook_1 = __importDefault(require("./handlers/crowdin-webhook"));
|
|
48
48
|
const integration_webhook_1 = __importDefault(require("./handlers/integration-webhook"));
|
|
49
|
-
const
|
|
50
|
-
const
|
|
49
|
+
const file_download_1 = __importDefault(require("./handlers/file-processing/file-download"));
|
|
50
|
+
const custom_file_format_1 = __importDefault(require("./handlers/file-processing/custom-file-format"));
|
|
51
|
+
const pre_post_process_1 = __importDefault(require("./handlers/file-processing/pre-post-process"));
|
|
51
52
|
const translate_1 = __importDefault(require("./handlers/custom-mt/translate"));
|
|
52
53
|
const install_1 = __importDefault(require("./handlers/install"));
|
|
53
54
|
const integration_data_1 = __importDefault(require("./handlers/integration-data"));
|
|
@@ -71,14 +72,15 @@ const integration_credentials_1 = __importDefault(require("./middlewares/integra
|
|
|
71
72
|
const json_response_1 = __importDefault(require("./middlewares/json-response"));
|
|
72
73
|
const ui_module_1 = __importDefault(require("./middlewares/ui-module"));
|
|
73
74
|
const render_ui_module_1 = __importDefault(require("./middlewares/render-ui-module"));
|
|
75
|
+
const models_1 = require("./models");
|
|
74
76
|
const storage = __importStar(require("./storage"));
|
|
75
77
|
const util_1 = require("./util");
|
|
76
78
|
const connection_1 = require("./util/connection");
|
|
77
79
|
const cron_1 = require("./util/cron");
|
|
78
80
|
const defaults_1 = require("./util/defaults");
|
|
79
81
|
const webhooks_1 = require("./util/webhooks");
|
|
80
|
-
var
|
|
81
|
-
Object.defineProperty(exports, "Scope", { enumerable: true, get: function () { return
|
|
82
|
+
var models_2 = require("./models");
|
|
83
|
+
Object.defineProperty(exports, "Scope", { enumerable: true, get: function () { return models_2.Scope; } });
|
|
82
84
|
function addCrowdinEndpoints(app, plainConfig) {
|
|
83
85
|
var _a, _b, _c;
|
|
84
86
|
if (!plainConfig.disableGlobalErrorHandling) {
|
|
@@ -172,8 +174,24 @@ function addCrowdinEndpoints(app, plainConfig) {
|
|
|
172
174
|
}
|
|
173
175
|
}
|
|
174
176
|
if (config.customFileFormat) {
|
|
175
|
-
app.post('/process', (0, crowdin_client_1.default)(config), (0,
|
|
176
|
-
app.get('/file/download', (0,
|
|
177
|
+
app.post('/process', (0, crowdin_client_1.default)(config), (0, custom_file_format_1.default)(config, config.baseUrl, config.customFileFormat.filesFolder || config.dbFolder || '/', config.customFileFormat));
|
|
178
|
+
app.get('/file/download', (0, file_download_1.default)(config, config.customFileFormat, 'custom-file-format'));
|
|
179
|
+
}
|
|
180
|
+
if (config.filePreImport) {
|
|
181
|
+
app.post('/pre-import', (0, crowdin_client_1.default)(config), (0, pre_post_process_1.default)(config, config.filePreImport, models_1.ProcessFileJobType.PRE_IMPORT));
|
|
182
|
+
app.get(`/file/download/${models_1.ProcessFileJobType.PRE_IMPORT}`, (0, file_download_1.default)(config, config.filePreImport, models_1.ProcessFileJobType.PRE_IMPORT));
|
|
183
|
+
}
|
|
184
|
+
if (config.filePostImport) {
|
|
185
|
+
app.post('/post-import', (0, crowdin_client_1.default)(config), (0, pre_post_process_1.default)(config, config.filePostImport, models_1.ProcessFileJobType.POST_IMPORT));
|
|
186
|
+
app.get(`/file/download/${models_1.ProcessFileJobType.POST_IMPORT}`, (0, file_download_1.default)(config, config.filePostImport, models_1.ProcessFileJobType.POST_IMPORT));
|
|
187
|
+
}
|
|
188
|
+
if (config.filePreExport) {
|
|
189
|
+
app.post('/pre-export', (0, crowdin_client_1.default)(config), (0, pre_post_process_1.default)(config, config.filePreExport, models_1.ProcessFileJobType.PRE_EXPORT));
|
|
190
|
+
app.get(`/file/download/${models_1.ProcessFileJobType.PRE_EXPORT}`, (0, file_download_1.default)(config, config.filePreExport, models_1.ProcessFileJobType.PRE_EXPORT));
|
|
191
|
+
}
|
|
192
|
+
if (config.filePostExport) {
|
|
193
|
+
app.post('/post-export', (0, crowdin_client_1.default)(config), (0, pre_post_process_1.default)(config, config.filePostExport, models_1.ProcessFileJobType.POST_EXPORT));
|
|
194
|
+
app.get(`/file/download/${models_1.ProcessFileJobType.POST_EXPORT}`, (0, file_download_1.default)(config, config.filePostExport, models_1.ProcessFileJobType.POST_EXPORT));
|
|
177
195
|
}
|
|
178
196
|
if (config.customMT) {
|
|
179
197
|
app.get('/logo/mt/logo.png', (req, res) => { var _a; return res.sendFile(((_a = config.customMT) === null || _a === void 0 ? void 0 : _a.imagePath) || config.imagePath || (0, path_1.join)(__dirname, 'logo.png')); });
|
package/out/models/index.d.ts
CHANGED
|
@@ -127,6 +127,10 @@ export interface Config extends ImagePath {
|
|
|
127
127
|
* Configuration of app pricing
|
|
128
128
|
*/
|
|
129
129
|
pricing?: Pricing;
|
|
130
|
+
filePreImport?: FilePreImportLogic;
|
|
131
|
+
filePostImport?: FilePostImportLogic;
|
|
132
|
+
filePreExport?: FilePreExportLogic;
|
|
133
|
+
filePostExport?: FilePostExportLogic;
|
|
130
134
|
}
|
|
131
135
|
export declare enum AuthenticationType {
|
|
132
136
|
CODE = "authorization_code",
|
|
@@ -484,23 +488,29 @@ export interface CronJob {
|
|
|
484
488
|
task: (projectId: number, client: Crowdin, apiCredentials: any, appRootFolder?: SourceFilesModel.Directory, config?: any) => Promise<void>;
|
|
485
489
|
expression: string;
|
|
486
490
|
}
|
|
487
|
-
export interface
|
|
488
|
-
/**
|
|
489
|
-
* The type parameter value for a custom file format. Used for a custom format file upload via API.
|
|
490
|
-
*/
|
|
491
|
-
type: string;
|
|
491
|
+
export interface FileProcessLogic {
|
|
492
492
|
/**
|
|
493
493
|
* Folder where larger file will be temporary stored (default "{@link dbFolder}/custom-file-format")
|
|
494
494
|
*/
|
|
495
495
|
filesFolder?: string;
|
|
496
|
-
/**
|
|
497
|
-
* This parameter is used to combine the content of multiple languages into one request when uploading and downloading translations in your Crowdin project.
|
|
498
|
-
*/
|
|
499
|
-
multilingual?: boolean;
|
|
500
496
|
/**
|
|
501
497
|
* Contains fileName and/or fileContent regular expressions used to detect file type when uploading a new source file via UI (or via API without specified type parameter). If the file matches regular expressions, it's labeled as a custom format file.
|
|
502
498
|
*/
|
|
503
499
|
signaturePatterns?: SignaturePatterns;
|
|
500
|
+
/**
|
|
501
|
+
* Override to store huge responses (by default they will be stored in fs)
|
|
502
|
+
*/
|
|
503
|
+
storeFile?: (content: string) => Promise<string>;
|
|
504
|
+
}
|
|
505
|
+
export interface CustomFileFormatLogic extends FileProcessLogic {
|
|
506
|
+
/**
|
|
507
|
+
* The type parameter value for a custom file format. Used for a custom format file upload via API.
|
|
508
|
+
*/
|
|
509
|
+
type: string;
|
|
510
|
+
/**
|
|
511
|
+
* This parameter is used to combine the content of multiple languages into one request when uploading and downloading translations in your Crowdin project.
|
|
512
|
+
*/
|
|
513
|
+
multilingual?: boolean;
|
|
504
514
|
/**
|
|
505
515
|
* Flag to automatically upload translations
|
|
506
516
|
*/
|
|
@@ -533,10 +543,19 @@ export interface CustomFileFormatLogic {
|
|
|
533
543
|
* Used for strings export
|
|
534
544
|
*/
|
|
535
545
|
exportStrings?: (req: Omit<ProcessFileRequest, 'jobType'>, strings: ProcessFileString[], client: Crowdin, context: CrowdinContextInfo, projectId: number) => Promise<BuildFileResponse>;
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
546
|
+
}
|
|
547
|
+
export type FileImportExportLogic = FilePreImportLogic | FilePostImportLogic | FilePreExportLogic | FilePostExportLogic;
|
|
548
|
+
export interface FilePreImportLogic extends FileProcessLogic {
|
|
549
|
+
fileProcess: (req: ProcessFileRequest, content: string, client: Crowdin, context: CrowdinContextInfo, projectId: number) => Promise<BuildFileResponse>;
|
|
550
|
+
}
|
|
551
|
+
export interface FilePostImportLogic extends FileProcessLogic {
|
|
552
|
+
fileProcess: (req: ProcessFileRequest, content: string, client: Crowdin, context: CrowdinContextInfo, projectId: number) => Promise<ParseFileResponse>;
|
|
553
|
+
}
|
|
554
|
+
export interface FilePreExportLogic extends FileProcessLogic {
|
|
555
|
+
fileProcess: (req: ProcessFileRequest, content: string, client: Crowdin, context: CrowdinContextInfo, projectId: number) => Promise<ParseFileResponse>;
|
|
556
|
+
}
|
|
557
|
+
export interface FilePostExportLogic extends FileProcessLogic {
|
|
558
|
+
fileProcess: (req: ProcessFileRequest, content: string, client: Crowdin, context: CrowdinContextInfo, projectId: number) => Promise<BuildFileResponse>;
|
|
540
559
|
}
|
|
541
560
|
export interface SignaturePatterns {
|
|
542
561
|
fileName?: string;
|
|
@@ -559,7 +578,11 @@ export interface ProcessFileRecord {
|
|
|
559
578
|
}
|
|
560
579
|
export declare enum ProcessFileJobType {
|
|
561
580
|
PARSE_FILE = "parse-file",
|
|
562
|
-
BUILD_FILE = "build-file"
|
|
581
|
+
BUILD_FILE = "build-file",
|
|
582
|
+
PRE_IMPORT = "pre-import-file",
|
|
583
|
+
POST_IMPORT = "post-import-file",
|
|
584
|
+
PRE_EXPORT = "pre-export-file",
|
|
585
|
+
POST_EXPORT = "post-export-file"
|
|
563
586
|
}
|
|
564
587
|
export interface ParseFileResponse {
|
|
565
588
|
previewFile?: string;
|
|
@@ -569,6 +592,7 @@ export interface ParseFileResponse {
|
|
|
569
592
|
export interface BuildFileResponse {
|
|
570
593
|
contentFile: string;
|
|
571
594
|
error?: string;
|
|
595
|
+
fileName?: string;
|
|
572
596
|
}
|
|
573
597
|
export interface ProcessFileString {
|
|
574
598
|
previewId?: number;
|
|
@@ -582,6 +606,7 @@ export interface ProcessFileString {
|
|
|
582
606
|
labels?: string[];
|
|
583
607
|
text: string | SourceStringsModel.PluralText;
|
|
584
608
|
translations?: StringTranslations;
|
|
609
|
+
uniqId?: string;
|
|
585
610
|
}
|
|
586
611
|
export interface StringTranslations {
|
|
587
612
|
[language: string]: {
|
package/out/models/index.js
CHANGED
|
@@ -39,6 +39,10 @@ var ProcessFileJobType;
|
|
|
39
39
|
(function (ProcessFileJobType) {
|
|
40
40
|
ProcessFileJobType["PARSE_FILE"] = "parse-file";
|
|
41
41
|
ProcessFileJobType["BUILD_FILE"] = "build-file";
|
|
42
|
+
ProcessFileJobType["PRE_IMPORT"] = "pre-import-file";
|
|
43
|
+
ProcessFileJobType["POST_IMPORT"] = "post-import-file";
|
|
44
|
+
ProcessFileJobType["PRE_EXPORT"] = "pre-export-file";
|
|
45
|
+
ProcessFileJobType["POST_EXPORT"] = "post-export-file";
|
|
42
46
|
})(ProcessFileJobType = exports.ProcessFileJobType || (exports.ProcessFileJobType = {}));
|
|
43
47
|
var EditorPanelsMode;
|
|
44
48
|
(function (EditorPanelsMode) {
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.getFileContent = exports.storeFile = exports.MAX_BODY_SIZE = void 0;
|
|
16
|
+
const fs_1 = __importDefault(require("fs"));
|
|
17
|
+
const path_1 = __importDefault(require("path"));
|
|
18
|
+
const axios_1 = __importDefault(require("axios"));
|
|
19
|
+
exports.MAX_BODY_SIZE = 4.9 * 1024 * 1024; //4.9mb
|
|
20
|
+
function storeFile(fileContent, folder) {
|
|
21
|
+
const fileName = `file${Date.now()}`;
|
|
22
|
+
return new Promise((res, rej) => fs_1.default.writeFile(path_1.default.join(folder, fileName), fileContent, (err) => {
|
|
23
|
+
if (err) {
|
|
24
|
+
rej(err);
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
res(fileName);
|
|
28
|
+
}
|
|
29
|
+
}));
|
|
30
|
+
}
|
|
31
|
+
exports.storeFile = storeFile;
|
|
32
|
+
function getFileContent(url, isString = false) {
|
|
33
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
34
|
+
const response = (yield axios_1.default.get(url)).data;
|
|
35
|
+
if (isString) {
|
|
36
|
+
// the response is presented in the ndjson format
|
|
37
|
+
const jsonRows = response.split(/\n|\n\r/).filter(Boolean);
|
|
38
|
+
return jsonRows.map((jsonStringRow) => JSON.parse(jsonStringRow));
|
|
39
|
+
}
|
|
40
|
+
return response;
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
exports.getFileContent = getFileContent;
|
package/package.json
CHANGED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
/// <reference types="qs" />
|
|
2
|
-
import { Request, Response } from 'express';
|
|
3
|
-
import { Config } from '../../models';
|
|
4
|
-
export default function handle(config: Config, folder: string): (req: Request<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>>, res: Response<any, Record<string, any>>, next: Function) => void;
|
/package/out/handlers/{custom-file-format/process.d.ts → file-processing/custom-file-format.d.ts}
RENAMED
|
File without changes
|