@mdgf11/filesystem-lib 2.2.20 → 2.2.22

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.
@@ -5,6 +5,7 @@ export declare function loadFilesystemDocument(jsonPath: string): FilesystemDocu
5
5
  export type DocumentFileType = "nlp" | "details" | "pdf" | "docx" | "txt";
6
6
  export declare function loadDocumentFile(doc: PartialJurisprudenciaDocument, type: "nlp" | "details"): string;
7
7
  export declare function loadDocumentFile(doc: PartialJurisprudenciaDocument, type: "pdf" | "docx" | "txt"): Buffer;
8
+ export declare function writeContentToDocument(doc: PartialJurisprudenciaDocument, content: ContentType, isSumario: boolean): void;
8
9
  export declare const ANONIMIZADO_NAME = "Anonimizado";
9
10
  /**
10
11
  * Converts the anonymized HTML text (and optionally summary) to DOCX and PDF files
@@ -2,7 +2,7 @@ import { execFileSync } from "child_process";
2
2
  import fs from "fs";
3
3
  import mammoth from "mammoth";
4
4
  import path from "path";
5
- import { DETAILS_NAME, FILESYSTEM_PATH, ORIGINAL_NAME, ROOT_PATH, SHAREPOINT_COPY_PATH } from "./types.js";
5
+ import { DETAILS_NAME, ENTITIES_NAME, FILESYSTEM_PATH, ROOT_PATH, SHAREPOINT_COPY_PATH, SUMARIO_NAME, TEXTO_NAME } from "./types.js";
6
6
  import { writeDocumentEvent } from "./filesystemUpdateMethods.js";
7
7
  import { getDocument } from "pdfjs-dist/legacy/build/pdf.mjs";
8
8
  export function writeFilesystemDocument(filesystem_document) {
@@ -20,7 +20,8 @@ export function writeFilesystemDocument(filesystem_document) {
20
20
  fs.mkdirSync(filesystem_dir_path, { recursive: true });
21
21
  fs.writeFileSync(filesystem_metadata_path, JSON.stringify(safe, null, 2), { encoding: "utf-8" });
22
22
  for (const content_i of content) {
23
- const filesystem_original_path = `${filesystem_dir_path}/${ORIGINAL_NAME}.${content_i.extension}`;
23
+ const name = content_i.extension === "json" ? ENTITIES_NAME : TEXTO_NAME;
24
+ const filesystem_original_path = `${filesystem_dir_path}/${name}.${content_i.extension}`;
24
25
  fs.writeFileSync(filesystem_original_path, content_i.data, { encoding: "utf-8" });
25
26
  }
26
27
  // make metadata copy on filesystem copy
@@ -38,7 +39,8 @@ export function writeFilesystemDocument(filesystem_document) {
38
39
  fs.mkdirSync(filesystem_sharepoint_dir_path, { recursive: true });
39
40
  fs.writeFileSync(filesystem_sharepoint_path, JSON.stringify(safe, null, 2), { encoding: "utf-8" });
40
41
  for (const content_i of content) {
41
- const filesystem_original_path = `${filesystem_sharepoint_dir_path}/${ORIGINAL_NAME}.${content_i.extension}`;
42
+ const name = content_i.extension === "json" ? ENTITIES_NAME : TEXTO_NAME;
43
+ const filesystem_original_path = `${filesystem_sharepoint_dir_path}/${name}.${content_i.extension}`;
42
44
  fs.writeFileSync(filesystem_original_path, content_i.data, { encoding: "utf-8" });
43
45
  }
44
46
  }
@@ -60,12 +62,18 @@ export function loadFilesystemDocument(jsonPath) {
60
62
  export function loadDocumentFile(doc, type) {
61
63
  const dirPath = `${ROOT_PATH}${FILESYSTEM_PATH}${generateFilePath(doc)}`;
62
64
  if (type === "nlp") {
63
- return fs.readFileSync(`${dirPath}/${ORIGINAL_NAME}.json`, "utf-8");
65
+ return fs.readFileSync(`${dirPath}/${ENTITIES_NAME}.json`, "utf-8");
64
66
  }
65
67
  if (type === "details") {
66
68
  return fs.readFileSync(`${dirPath}/${DETAILS_NAME}.json`, "utf-8");
67
69
  }
68
- return fs.readFileSync(`${dirPath}/${ORIGINAL_NAME}.${type}`);
70
+ return fs.readFileSync(`${dirPath}/${TEXTO_NAME}.${type}`);
71
+ }
72
+ export function writeContentToDocument(doc, content, isSumario) {
73
+ const filePath = generateFilePath(doc);
74
+ const dirPath = `${ROOT_PATH}${FILESYSTEM_PATH}${filePath}`;
75
+ const name = isSumario ? SUMARIO_NAME : TEXTO_NAME;
76
+ fs.writeFileSync(`${dirPath}/${name}.${content.extension}`, content.data);
69
77
  }
70
78
  export const ANONIMIZADO_NAME = "Anonimizado";
71
79
  /**
package/dist/types.d.ts CHANGED
@@ -4,7 +4,9 @@ export declare const ROOT_PATH: string;
4
4
  export declare const FILESYSTEM_PATH = "/FileSystem";
5
5
  export declare const SHAREPOINT_COPY_PATH = "/Sharepoint";
6
6
  export declare const DETAILS_NAME = "Detalhes";
7
- export declare const ORIGINAL_NAME = "Original";
7
+ export declare const ENTITIES_NAME = "Entities";
8
+ export declare const TEXTO_NAME = "Texto";
9
+ export declare const SUMARIO_NAME = "Sum\u00E1rio";
8
10
  export declare const LOGS_PATH = "/Updates";
9
11
  export declare const SHAREPOINT_LOGS_PATH = "/Updates/Sharepoint";
10
12
  export declare const DGSI_LOGS_PATH = "/Updates/DGSI";
package/dist/types.js CHANGED
@@ -5,7 +5,9 @@ export const ROOT_PATH = process.env['LOCAL_ROOT'] || 'results';
5
5
  export const FILESYSTEM_PATH = `/FileSystem`;
6
6
  export const SHAREPOINT_COPY_PATH = `/Sharepoint`;
7
7
  export const DETAILS_NAME = "Detalhes";
8
- export const ORIGINAL_NAME = "Original";
8
+ export const ENTITIES_NAME = "Entities";
9
+ export const TEXTO_NAME = "Texto";
10
+ export const SUMARIO_NAME = "Sumário";
9
11
  export const LOGS_PATH = "/Updates";
10
12
  export const SHAREPOINT_LOGS_PATH = `${LOGS_PATH}/Sharepoint`;
11
13
  export const DGSI_LOGS_PATH = `${LOGS_PATH}/DGSI`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mdgf11/filesystem-lib",
3
- "version": "2.2.20",
3
+ "version": "2.2.22",
4
4
  "description": "Library to extend usage of jurisprudencia-document",
5
5
  "license": "ISC",
6
6
  "author": "Miguel Fonseca",
@@ -3,7 +3,7 @@ import { execFileSync } from "child_process";
3
3
  import fs from "fs";
4
4
  import mammoth from "mammoth";
5
5
  import path from "path";
6
- import { ContentType, Date_Area_Section, DETAILS_NAME, DocumentUpdateEvent, FILESYSTEM_PATH, FilesystemDocument, ORIGINAL_NAME, Retrievable_Metadata, ROOT_PATH, SHAREPOINT_COPY_PATH, Sharepoint_Metadata, SupportedUpdateSources } from "./types.js";
6
+ import { ContentType, Date_Area_Section, DETAILS_NAME, DocumentUpdateEvent, ENTITIES_NAME, FILESYSTEM_PATH, FilesystemDocument, Retrievable_Metadata, ROOT_PATH, SHAREPOINT_COPY_PATH, Sharepoint_Metadata, SUMARIO_NAME, SupportedUpdateSources, TEXTO_NAME } from "./types.js";
7
7
  import { writeDocumentEvent } from "./filesystemUpdateMethods.js";
8
8
  import { DescritorOficial } from "./descritores.js";
9
9
  import { getDocument } from "pdfjs-dist/legacy/build/pdf.mjs";
@@ -26,7 +26,8 @@ export function writeFilesystemDocument(filesystem_document: FilesystemDocument)
26
26
  fs.mkdirSync(filesystem_dir_path, { recursive: true });
27
27
  fs.writeFileSync(filesystem_metadata_path, JSON.stringify(safe, null, 2), { encoding: "utf-8" });
28
28
  for (const content_i of content) {
29
- const filesystem_original_path = `${filesystem_dir_path}/${ORIGINAL_NAME}.${content_i.extension}`;
29
+ const name = content_i.extension === "json" ? ENTITIES_NAME : TEXTO_NAME;
30
+ const filesystem_original_path = `${filesystem_dir_path}/${name}.${content_i.extension}`;
30
31
  fs.writeFileSync(filesystem_original_path, content_i.data, { encoding: "utf-8" });
31
32
  }
32
33
 
@@ -44,7 +45,8 @@ export function writeFilesystemDocument(filesystem_document: FilesystemDocument)
44
45
  fs.mkdirSync(filesystem_sharepoint_dir_path, { recursive: true });
45
46
  fs.writeFileSync(filesystem_sharepoint_path, JSON.stringify(safe, null, 2), { encoding: "utf-8" });
46
47
  for (const content_i of content) {
47
- const filesystem_original_path = `${filesystem_sharepoint_dir_path}/${ORIGINAL_NAME}.${content_i.extension}`;
48
+ const name = content_i.extension === "json" ? ENTITIES_NAME : TEXTO_NAME;
49
+ const filesystem_original_path = `${filesystem_sharepoint_dir_path}/${name}.${content_i.extension}`;
48
50
  fs.writeFileSync(filesystem_original_path, content_i.data, { encoding: "utf-8" });
49
51
  }
50
52
  }
@@ -73,12 +75,23 @@ export function loadDocumentFile(doc: PartialJurisprudenciaDocument, type: "pdf"
73
75
  export function loadDocumentFile(doc: PartialJurisprudenciaDocument, type: DocumentFileType): string | Buffer {
74
76
  const dirPath = `${ROOT_PATH}${FILESYSTEM_PATH}${generateFilePath(doc)}`;
75
77
  if (type === "nlp") {
76
- return fs.readFileSync(`${dirPath}/${ORIGINAL_NAME}.json`, "utf-8");
78
+ return fs.readFileSync(`${dirPath}/${ENTITIES_NAME}.json`, "utf-8");
77
79
  }
78
80
  if (type === "details") {
79
81
  return fs.readFileSync(`${dirPath}/${DETAILS_NAME}.json`, "utf-8");
80
82
  }
81
- return fs.readFileSync(`${dirPath}/${ORIGINAL_NAME}.${type}`);
83
+ return fs.readFileSync(`${dirPath}/${TEXTO_NAME}.${type}`);
84
+ }
85
+
86
+ export function writeContentToDocument(
87
+ doc: PartialJurisprudenciaDocument,
88
+ content: ContentType,
89
+ isSumario: boolean
90
+ ): void {
91
+ const filePath = generateFilePath(doc);
92
+ const dirPath = `${ROOT_PATH}${FILESYSTEM_PATH}${filePath}`;
93
+ const name = isSumario ? SUMARIO_NAME : TEXTO_NAME;
94
+ fs.writeFileSync(`${dirPath}/${name}.${content.extension}`, content.data);
82
95
  }
83
96
 
84
97
  export const ANONIMIZADO_NAME = "Anonimizado";
package/src/types.ts CHANGED
@@ -8,7 +8,9 @@ export const ROOT_PATH = process.env['LOCAL_ROOT'] || 'results';
8
8
  export const FILESYSTEM_PATH = `/FileSystem`;
9
9
  export const SHAREPOINT_COPY_PATH = `/Sharepoint`;
10
10
  export const DETAILS_NAME = "Detalhes";
11
- export const ORIGINAL_NAME = "Original";
11
+ export const ENTITIES_NAME = "Entities";
12
+ export const TEXTO_NAME = "Texto";
13
+ export const SUMARIO_NAME = "Sumário";
12
14
  export const LOGS_PATH = "/Updates";
13
15
 
14
16
  export const SHAREPOINT_LOGS_PATH = `${LOGS_PATH}/Sharepoint`;