@mdgf11/filesystem-lib 2.2.19 → 2.2.21
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/dist/filesystemDocumentMethods.js +6 -4
- package/dist/filesystemUpdateMethods.js +11 -13
- package/dist/types.d.ts +1 -0
- package/dist/types.js +1 -0
- package/package.json +1 -1
- package/src/filesystemDocumentMethods.ts +6 -4
- package/src/filesystemUpdateMethods.ts +12 -13
- package/src/types.ts +1 -0
|
@@ -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, ORIGINAL_NAME, ROOT_PATH, SHAREPOINT_COPY_PATH } 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
|
|
23
|
+
const name = content_i.extension === "json" ? ENTITIES_NAME : ORIGINAL_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
|
|
42
|
+
const name = content_i.extension === "json" ? ENTITIES_NAME : ORIGINAL_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,7 +62,7 @@ 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}/${
|
|
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");
|
|
@@ -22,16 +22,16 @@ export function writeFilesystemUpdate(update, source) {
|
|
|
22
22
|
let log_path = SOURCE_TO_PATH[source];
|
|
23
23
|
const timestamp = formatUpdateDate(update.date_end);
|
|
24
24
|
fs.mkdirSync(log_path, { recursive: true });
|
|
25
|
-
const updates_file_path = `${log_path}
|
|
25
|
+
const updates_file_path = `${log_path}/${timestamp}_log.json`;
|
|
26
26
|
removeOldUpdate(log_path);
|
|
27
27
|
fs.writeFileSync(updates_file_path, JSON.stringify(update, null, 2), { encoding: "utf-8" });
|
|
28
28
|
// Write to global All dir (never deleted — full history of all sources)
|
|
29
29
|
fs.mkdirSync(ALL_UPDATE_DIR, { recursive: true });
|
|
30
|
-
fs.writeFileSync(`${ALL_UPDATE_DIR}
|
|
30
|
+
fs.writeFileSync(`${ALL_UPDATE_DIR}/${timestamp}_log_${source.replace(/[^a-zA-Z0-9]/g, "_")}.json`, JSON.stringify(update, null, 2), { encoding: "utf-8" });
|
|
31
31
|
}
|
|
32
32
|
export function writeDocumentEvent(event) {
|
|
33
33
|
const timestamp = formatUpdateDate(new Date(event.date));
|
|
34
|
-
const filename =
|
|
34
|
+
const filename = `${timestamp}_event_${event.event}_${event.uuid}.json`;
|
|
35
35
|
const content = JSON.stringify(event, null, 2);
|
|
36
36
|
// Write to source-specific dir (e.g. Updates/Juris/) — keeps all individual events
|
|
37
37
|
const sourceDir = SOURCE_TO_PATH[event.source];
|
|
@@ -50,16 +50,14 @@ export function loadLastFilesystemUpdate(source) {
|
|
|
50
50
|
const old_log_path = SOURCE_TO_PATH[source];
|
|
51
51
|
if (!fs.existsSync(old_log_path))
|
|
52
52
|
return empty_update;
|
|
53
|
-
const files = fs.readdirSync(old_log_path)
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
}
|
|
62
|
-
return empty_update;
|
|
53
|
+
const files = fs.readdirSync(old_log_path)
|
|
54
|
+
.filter(f => fs.statSync(path.join(old_log_path, f)).isFile() && f.toLowerCase().includes("log"))
|
|
55
|
+
.sort();
|
|
56
|
+
if (files.length === 0)
|
|
57
|
+
return empty_update;
|
|
58
|
+
const fullPath = path.join(old_log_path, files[files.length - 1]);
|
|
59
|
+
const jsonString = fs.readFileSync(fullPath, 'utf-8');
|
|
60
|
+
return JSON.parse(jsonString);
|
|
63
61
|
}
|
|
64
62
|
function formatUpdateDate(d = new Date()) {
|
|
65
63
|
const pad = (n) => n.toString().padStart(2, "0");
|
package/dist/types.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ export declare const FILESYSTEM_PATH = "/FileSystem";
|
|
|
5
5
|
export declare const SHAREPOINT_COPY_PATH = "/Sharepoint";
|
|
6
6
|
export declare const DETAILS_NAME = "Detalhes";
|
|
7
7
|
export declare const ORIGINAL_NAME = "Original";
|
|
8
|
+
export declare const ENTITIES_NAME = "Entities";
|
|
8
9
|
export declare const LOGS_PATH = "/Updates";
|
|
9
10
|
export declare const SHAREPOINT_LOGS_PATH = "/Updates/Sharepoint";
|
|
10
11
|
export declare const DGSI_LOGS_PATH = "/Updates/DGSI";
|
package/dist/types.js
CHANGED
|
@@ -6,6 +6,7 @@ export const FILESYSTEM_PATH = `/FileSystem`;
|
|
|
6
6
|
export const SHAREPOINT_COPY_PATH = `/Sharepoint`;
|
|
7
7
|
export const DETAILS_NAME = "Detalhes";
|
|
8
8
|
export const ORIGINAL_NAME = "Original";
|
|
9
|
+
export const ENTITIES_NAME = "Entities";
|
|
9
10
|
export const LOGS_PATH = "/Updates";
|
|
10
11
|
export const SHAREPOINT_LOGS_PATH = `${LOGS_PATH}/Sharepoint`;
|
|
11
12
|
export const DGSI_LOGS_PATH = `${LOGS_PATH}/DGSI`;
|
package/package.json
CHANGED
|
@@ -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, ORIGINAL_NAME, Retrievable_Metadata, ROOT_PATH, SHAREPOINT_COPY_PATH, Sharepoint_Metadata, SupportedUpdateSources } 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
|
|
29
|
+
const name = content_i.extension === "json" ? ENTITIES_NAME : ORIGINAL_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
|
|
48
|
+
const name = content_i.extension === "json" ? ENTITIES_NAME : ORIGINAL_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,7 +75,7 @@ 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}/${
|
|
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");
|
|
@@ -29,19 +29,19 @@ export function writeFilesystemUpdate(update: FilesystemUpdate, source: Supporte
|
|
|
29
29
|
const timestamp = formatUpdateDate(update.date_end);
|
|
30
30
|
|
|
31
31
|
fs.mkdirSync(log_path, { recursive: true });
|
|
32
|
-
const updates_file_path = `${log_path}
|
|
32
|
+
const updates_file_path = `${log_path}/${timestamp}_log.json`;
|
|
33
33
|
|
|
34
34
|
removeOldUpdate(log_path);
|
|
35
35
|
fs.writeFileSync(updates_file_path, JSON.stringify(update, null, 2), { encoding: "utf-8" });
|
|
36
36
|
|
|
37
37
|
// Write to global All dir (never deleted — full history of all sources)
|
|
38
38
|
fs.mkdirSync(ALL_UPDATE_DIR, { recursive: true });
|
|
39
|
-
fs.writeFileSync(`${ALL_UPDATE_DIR}
|
|
39
|
+
fs.writeFileSync(`${ALL_UPDATE_DIR}/${timestamp}_log_${source.replace(/[^a-zA-Z0-9]/g, "_")}.json`, JSON.stringify(update, null, 2), { encoding: "utf-8" });
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
export function writeDocumentEvent(event: DocumentUpdateEvent): void {
|
|
43
43
|
const timestamp = formatUpdateDate(new Date(event.date));
|
|
44
|
-
const filename =
|
|
44
|
+
const filename = `${timestamp}_event_${event.event}_${event.uuid}.json`;
|
|
45
45
|
const content = JSON.stringify(event, null, 2);
|
|
46
46
|
|
|
47
47
|
// Write to source-specific dir (e.g. Updates/Juris/) — keeps all individual events
|
|
@@ -66,16 +66,15 @@ export function loadLastFilesystemUpdate(source: SupportedUpdateSources): Filesy
|
|
|
66
66
|
if (!fs.existsSync(old_log_path))
|
|
67
67
|
return empty_update;
|
|
68
68
|
|
|
69
|
-
const files = fs.readdirSync(old_log_path)
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
return empty_update;
|
|
69
|
+
const files = fs.readdirSync(old_log_path)
|
|
70
|
+
.filter(f => fs.statSync(path.join(old_log_path, f)).isFile() && f.toLowerCase().includes("log"))
|
|
71
|
+
.sort();
|
|
72
|
+
|
|
73
|
+
if (files.length === 0) return empty_update;
|
|
74
|
+
|
|
75
|
+
const fullPath = path.join(old_log_path, files[files.length - 1]);
|
|
76
|
+
const jsonString = fs.readFileSync(fullPath, 'utf-8');
|
|
77
|
+
return JSON.parse(jsonString) as FilesystemUpdate;
|
|
79
78
|
}
|
|
80
79
|
|
|
81
80
|
function formatUpdateDate(d: Date = new Date()): string {
|
package/src/types.ts
CHANGED
|
@@ -9,6 +9,7 @@ export const FILESYSTEM_PATH = `/FileSystem`;
|
|
|
9
9
|
export const SHAREPOINT_COPY_PATH = `/Sharepoint`;
|
|
10
10
|
export const DETAILS_NAME = "Detalhes";
|
|
11
11
|
export const ORIGINAL_NAME = "Original";
|
|
12
|
+
export const ENTITIES_NAME = "Entities";
|
|
12
13
|
export const LOGS_PATH = "/Updates";
|
|
13
14
|
|
|
14
15
|
export const SHAREPOINT_LOGS_PATH = `${LOGS_PATH}/Sharepoint`;
|