@l10nmonster/helpers-lqaboss 3.0.0-alpha.14 → 3.0.0-alpha.16

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.
@@ -1,11 +1,14 @@
1
1
  import JSZip from 'jszip';
2
- import { providers, logVerbose, styleString, opsManager } from '@l10nmonster/core';
2
+ import path from 'path';
3
+ import { readFileSync } from 'fs';
4
+ import { providers, logVerbose, styleString, opsManager, getBaseDir } from '@l10nmonster/core';
3
5
 
4
6
  /**
5
7
  * @typedef {object} LQABossProviderOptions
6
8
  * @extends BaseTranslationProvider
7
9
  * @property {Object} delegate - Required file store delegate implementing file operations
8
10
  * @property {string} [urlPrefix] - Prefix for the LQA Boss URL
11
+ * @property {string} [qualityFile] - Path to a quality model JSON file
9
12
  */
10
13
 
11
14
  /**
@@ -14,16 +17,18 @@ import { providers, logVerbose, styleString, opsManager } from '@l10nmonster/cor
14
17
  export class LQABossProvider extends providers.BaseTranslationProvider {
15
18
  #storageDelegate;
16
19
  urlPrefix;
20
+ #qualityFilePath;
17
21
  #opNames = {};
18
22
 
19
23
  /**
20
24
  * Initializes a new instance of the LQABossProvider class.
21
25
  * @param {LQABossProviderOptions} options - Configuration options for the provider.
22
26
  */
23
- constructor({ delegate, urlPrefix, ...options }) {
27
+ constructor({ delegate, urlPrefix, qualityFile, ...options }) {
24
28
  super(options);
25
29
  this.#storageDelegate = delegate;
26
30
  this.urlPrefix = urlPrefix;
31
+ qualityFile && (this.#qualityFilePath = path.resolve(getBaseDir(), qualityFile));
27
32
  this.#opNames.startReviewOp = `${this.id}.startReviewOp`;
28
33
  opsManager.registerOp(this.startReviewOp.bind(this), { opName: this.#opNames.startReviewOp, idempotent: false });
29
34
  }
@@ -34,27 +39,30 @@ export class LQABossProvider extends providers.BaseTranslationProvider {
34
39
  }
35
40
 
36
41
  async startReviewOp(op) {
37
- const { tus, ...jobResponse } = op.args.job;
42
+ const filename = op.args.job.jobName ?
43
+ `${op.args.job.jobName.replace(/\s+/g, '_')}-${op.args.job.jobGuid.substring(0, 5)}.lqaboss` :
44
+ `${op.args.job.jobGuid}.lqaboss`;
45
+ const jobRequest = {
46
+ ...op.args.job,
47
+ statusDescription: `Created LQA Boss file ${this.urlPrefix ? `at ${this.urlPrefix}/${filename}` : `: ${filename}`}`,
48
+ providerData: { quality: this.quality },
49
+ };
38
50
  const zip = new JSZip();
39
- zip.file('job.json', JSON.stringify({
40
- ...jobResponse,
41
- tus: tus.map(tu => ({
42
- rid: tu.rid,
43
- sid: tu.sid,
44
- guid: tu.guid,
45
- nsrc: tu.nsrc,
46
- notes: tu.notes,
47
- ntgt: tu.ntgt,
48
- q: this.quality,
49
- })),
50
- }, null, 2));
51
+ zip.file('job.json', JSON.stringify(jobRequest, null, 2));
52
+
53
+ // Add quality model if configured
54
+ if (this.#qualityFilePath) {
55
+ const qualityModel = JSON.parse(readFileSync(this.#qualityFilePath, 'utf-8'));
56
+ zip.file('quality.json', JSON.stringify(qualityModel, null, 2));
57
+ }
58
+
51
59
  const buffer = await zip.generateAsync({ type: 'nodebuffer', compression: 'DEFLATE', compressionOptions: { level: 6 } });
52
- const filename = `${jobResponse.jobGuid}.lqaboss`;
53
60
  await this.#storageDelegate.saveFile(filename, buffer);
54
- logVerbose`Saved LQABoss file ${filename} with ${tus.length} guids and ${buffer.length} bytes`;
55
- jobResponse.statusDescription = `Created LQA Boss file${this.urlPrefix ? ` at ${this.urlPrefix}/${filename}` : ''}`;
56
- jobResponse.tus = []; // remove tus so that job is cancelled and won't be stored
57
- return jobResponse;
61
+ logVerbose`Saved LQABoss file ${filename} with ${jobRequest.tus.length} guids and ${buffer.length} bytes`;
62
+ return {
63
+ ...jobRequest,
64
+ tus: [], // remove tus so that job is cancelled and won't be stored
65
+ };
58
66
  }
59
67
 
60
68
  async info() {
package/lqabossRoutes.js CHANGED
@@ -15,7 +15,7 @@ export function createLQABossRoutes(mm) {
15
15
  const guidMap = new Map(tus.map(tu => [ tu.guid, tu ]));
16
16
  const results = segments.map(segment => guidMap.get(segment.g) ?? {});
17
17
  logVerbose`Matched ${tus.length} segments out of ${guids.size}`;
18
- res.json(results);
18
+ res.json({ results });
19
19
  } catch (error) {
20
20
  logInfo`Error in LQABossRoute:/lookup: ${error.message}`;
21
21
  res.status(500).json({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@l10nmonster/helpers-lqaboss",
3
- "version": "3.0.0-alpha.14",
3
+ "version": "3.0.0-alpha.16",
4
4
  "description": "LQA Boss helper for L10n Monster",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -1,9 +0,0 @@
1
- {
2
- "permissions": {
3
- "allow": [
4
- "Bash(wc:*)"
5
- ],
6
- "deny": [],
7
- "ask": []
8
- }
9
- }