@mdgf11/filesystem-lib 2.0.14 → 2.2.0
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 +2 -2
- package/dist/filesystemUpdateMethods.d.ts +4 -4
- package/dist/filesystemUpdateMethods.js +15 -14
- package/dist/types.d.ts +4 -1
- package/dist/types.js +4 -1
- package/package.json +2 -2
- package/src/filesystemDocumentMethods.ts +2 -2
- package/src/filesystemUpdateMethods.ts +18 -16
- package/src/types.ts +6 -1
|
@@ -111,8 +111,8 @@ export async function createJurisprudenciaDocument(retrievable_Metadata, content
|
|
|
111
111
|
...obj,
|
|
112
112
|
Original: obj.Original,
|
|
113
113
|
"Número de Processo": obj["Número de Processo"] || "",
|
|
114
|
-
|
|
115
|
-
|
|
114
|
+
Data: obj.Data || "",
|
|
115
|
+
"Meio Processual": obj["Meio Processual"],
|
|
116
116
|
});
|
|
117
117
|
obj["UUID"] = calculateUUID(obj["HASH"]);
|
|
118
118
|
return obj;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { FilesystemDocument, FilesystemUpdate } from "./types.js";
|
|
2
|
-
export declare function addFileToUpdate(update: FilesystemUpdate, filesystem_document: FilesystemDocument): void;
|
|
3
|
-
export declare function writeFilesystemUpdate(update: FilesystemUpdate): void;
|
|
1
|
+
import { FilesystemDocument, FilesystemUpdate, SupportedUpdateSources } from "./types.js";
|
|
4
2
|
export declare function logDocumentProcessingError(update: FilesystemUpdate, err: string): void;
|
|
5
|
-
export declare function
|
|
3
|
+
export declare function addFileToUpdate(update: FilesystemUpdate, filesystem_document: FilesystemDocument): void;
|
|
4
|
+
export declare function writeFilesystemUpdate(update: FilesystemUpdate, source: SupportedUpdateSources): void;
|
|
5
|
+
export declare function loadLastFilesystemUpdate(source: SupportedUpdateSources): FilesystemUpdate;
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import path from "path";
|
|
2
2
|
import fs from "fs";
|
|
3
|
-
import {
|
|
3
|
+
import { JURIS_UPDATE_DIR, SHAREPOINT_UPDATE_DIR } from "./types.js";
|
|
4
|
+
export function logDocumentProcessingError(update, err) {
|
|
5
|
+
update.file_errors.push(err);
|
|
6
|
+
}
|
|
4
7
|
export function addFileToUpdate(update, filesystem_document) {
|
|
5
8
|
if (!filesystem_document.file_path) {
|
|
6
9
|
throw new Error("File to be added to update doesn't have a system path.");
|
|
@@ -14,31 +17,29 @@ export function addFileToUpdate(update, filesystem_document) {
|
|
|
14
17
|
update.created_num += 1;
|
|
15
18
|
update.created.push(filesystem_document.file_path);
|
|
16
19
|
}
|
|
17
|
-
export function writeFilesystemUpdate(update) {
|
|
20
|
+
export function writeFilesystemUpdate(update, source) {
|
|
18
21
|
update.date_end = new Date();
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
const
|
|
22
|
+
let log_path = source === "STJ (Sharepoint)" ? SHAREPOINT_UPDATE_DIR : JURIS_UPDATE_DIR;
|
|
23
|
+
fs.mkdirSync(log_path, { recursive: true });
|
|
24
|
+
const updates_file_path = `${log_path}/log_${formatUpdateDate(update.date_end)}.json`;
|
|
25
|
+
const drive_dir_path = `${log_path}/All`;
|
|
22
26
|
fs.mkdirSync(drive_dir_path, { recursive: true });
|
|
23
27
|
const drive_file_path = `${drive_dir_path}/log_${formatUpdateDate(update.date_end)}.json`;
|
|
24
|
-
removeOldUpdate(
|
|
28
|
+
removeOldUpdate(log_path);
|
|
25
29
|
fs.writeFileSync(drive_file_path, JSON.stringify(update, null, 2), { encoding: "utf-8" });
|
|
26
30
|
fs.writeFileSync(updates_file_path, JSON.stringify(update, null, 2), { encoding: "utf-8" });
|
|
27
31
|
}
|
|
28
|
-
export function
|
|
29
|
-
update.file_errors.push(err);
|
|
30
|
-
}
|
|
31
|
-
export function loadLastFilesystemUpdate() {
|
|
32
|
+
export function loadLastFilesystemUpdate(source) {
|
|
32
33
|
const empty_update = {
|
|
33
|
-
updateSource:
|
|
34
|
+
updateSource: source,
|
|
34
35
|
file_errors: [],
|
|
35
36
|
date_start: new Date()
|
|
36
37
|
};
|
|
37
|
-
if (!fs.existsSync(
|
|
38
|
+
if (!fs.existsSync(JURIS_UPDATE_DIR))
|
|
38
39
|
return empty_update;
|
|
39
|
-
const files = fs.readdirSync(
|
|
40
|
+
const files = fs.readdirSync(JURIS_UPDATE_DIR);
|
|
40
41
|
for (const file of files) {
|
|
41
|
-
const fullPath = path.join(
|
|
42
|
+
const fullPath = path.join(JURIS_UPDATE_DIR, file);
|
|
42
43
|
if (fs.statSync(fullPath).isFile() && file.toLowerCase().includes("log")) {
|
|
43
44
|
const jsonString = fs.readFileSync(fullPath, 'utf-8');
|
|
44
45
|
const parsed = JSON.parse(jsonString);
|
package/dist/types.d.ts
CHANGED
|
@@ -7,7 +7,10 @@ export declare const SHAREPOINT_COPY_PATH = "/Sharepoint";
|
|
|
7
7
|
export declare const DETAILS_NAME = "Detalhes";
|
|
8
8
|
export declare const ORIGINAL_NAME = "Original";
|
|
9
9
|
export declare const LOGS_PATH = "/Updates";
|
|
10
|
-
export declare const
|
|
10
|
+
export declare const SHAREPOINT_LOGS_PATH = "/Updates/Sharepoint";
|
|
11
|
+
export declare const JURIS_LOGS_PATH = "/Updates/Juris";
|
|
12
|
+
export declare const SHAREPOINT_UPDATE_DIR: string;
|
|
13
|
+
export declare const JURIS_UPDATE_DIR: string;
|
|
11
14
|
export type FilesystemUpdate = {
|
|
12
15
|
updateSource: SupportedUpdateSources;
|
|
13
16
|
date_start: Date;
|
package/dist/types.js
CHANGED
|
@@ -7,7 +7,10 @@ export const SHAREPOINT_COPY_PATH = `/Sharepoint`;
|
|
|
7
7
|
export const DETAILS_NAME = "Detalhes";
|
|
8
8
|
export const ORIGINAL_NAME = "Original";
|
|
9
9
|
export const LOGS_PATH = "/Updates";
|
|
10
|
-
export const
|
|
10
|
+
export const SHAREPOINT_LOGS_PATH = `${LOGS_PATH}/Sharepoint`;
|
|
11
|
+
export const JURIS_LOGS_PATH = `${LOGS_PATH}/Juris`;
|
|
12
|
+
export const SHAREPOINT_UPDATE_DIR = `${ROOT_PATH}${SHAREPOINT_LOGS_PATH}`;
|
|
13
|
+
export const JURIS_UPDATE_DIR = `${ROOT_PATH}${JURIS_LOGS_PATH}`;
|
|
11
14
|
export const SUPPORTED_EXTENSIONS = ["txt", "pdf", "docx"];
|
|
12
15
|
export function isSupportedExtension(ext) {
|
|
13
16
|
return SUPPORTED_EXTENSIONS.includes(ext);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mdgf11/filesystem-lib",
|
|
3
|
-
"version": "2.0
|
|
3
|
+
"version": "2.2.0",
|
|
4
4
|
"description": "Library to extend usage of jurisprudencia-document",
|
|
5
5
|
"license": "ISC",
|
|
6
6
|
"author": "Miguel Fonseca",
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"start": "npm run build && npm run run"
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@stjiris/jurisprudencia-document": "npm:@mdgf11/jurisprudencia-document@^13.
|
|
16
|
+
"@stjiris/jurisprudencia-document": "npm:@mdgf11/jurisprudencia-document@^13.2.0",
|
|
17
17
|
"axios": "^1.13.1",
|
|
18
18
|
"body-parser": "^2.2.0",
|
|
19
19
|
"canvas": "^2.11.2",
|
|
@@ -122,8 +122,8 @@ export async function createJurisprudenciaDocument(retrievable_Metadata: Retriev
|
|
|
122
122
|
...obj,
|
|
123
123
|
Original: obj.Original,
|
|
124
124
|
"Número de Processo": obj["Número de Processo"] || "",
|
|
125
|
-
|
|
126
|
-
|
|
125
|
+
Data: obj.Data || "",
|
|
126
|
+
"Meio Processual": obj["Meio Processual"],
|
|
127
127
|
})
|
|
128
128
|
|
|
129
129
|
obj["UUID"] = calculateUUID(obj["HASH"]);
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import path from "path";
|
|
2
2
|
import fs from "fs";
|
|
3
|
-
import { FilesystemDocument, FilesystemUpdate,
|
|
3
|
+
import { FilesystemDocument, FilesystemUpdate, JURIS_UPDATE_DIR, SHAREPOINT_LOGS_PATH, SHAREPOINT_UPDATE_DIR, SupportedUpdateSources } from "./types.js";
|
|
4
4
|
|
|
5
|
+
export function logDocumentProcessingError(update: FilesystemUpdate, err: string) {
|
|
6
|
+
update.file_errors.push(err);
|
|
7
|
+
}
|
|
5
8
|
|
|
6
9
|
export function addFileToUpdate(update: FilesystemUpdate, filesystem_document: FilesystemDocument): void {
|
|
7
10
|
if (!filesystem_document.file_path) {
|
|
@@ -10,53 +13,52 @@ export function addFileToUpdate(update: FilesystemUpdate, filesystem_document: F
|
|
|
10
13
|
if (!update.created) {
|
|
11
14
|
update.created = [];
|
|
12
15
|
}
|
|
16
|
+
|
|
13
17
|
if (!update.created_num) {
|
|
14
18
|
update.created_num = 0;
|
|
15
19
|
}
|
|
20
|
+
|
|
16
21
|
update.created_num += 1;
|
|
17
22
|
update.created.push(filesystem_document.file_path);
|
|
18
23
|
}
|
|
19
24
|
|
|
20
|
-
export function writeFilesystemUpdate(update: FilesystemUpdate): void {
|
|
25
|
+
export function writeFilesystemUpdate(update: FilesystemUpdate, source: SupportedUpdateSources): void {
|
|
21
26
|
update.date_end = new Date();
|
|
22
27
|
|
|
23
|
-
|
|
24
|
-
|
|
28
|
+
let log_path: string = source === "STJ (Sharepoint)" ? SHAREPOINT_UPDATE_DIR : JURIS_UPDATE_DIR
|
|
29
|
+
|
|
30
|
+
fs.mkdirSync(log_path, { recursive: true });
|
|
31
|
+
const updates_file_path = `${log_path}/log_${formatUpdateDate(update.date_end)}.json`;
|
|
25
32
|
|
|
26
|
-
const drive_dir_path = `${
|
|
33
|
+
const drive_dir_path = `${log_path}/All`
|
|
27
34
|
fs.mkdirSync(drive_dir_path, { recursive: true });
|
|
28
35
|
const drive_file_path = `${drive_dir_path}/log_${formatUpdateDate(update.date_end)}.json`;
|
|
29
36
|
|
|
30
|
-
removeOldUpdate(
|
|
37
|
+
removeOldUpdate(log_path);
|
|
31
38
|
|
|
32
39
|
fs.writeFileSync(drive_file_path, JSON.stringify(update, null, 2), { encoding: "utf-8" });
|
|
33
40
|
fs.writeFileSync(updates_file_path, JSON.stringify(update, null, 2), { encoding: "utf-8" });
|
|
34
41
|
}
|
|
35
42
|
|
|
36
|
-
export function
|
|
37
|
-
update.file_errors.push(err);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export function loadLastFilesystemUpdate(): FilesystemUpdate {
|
|
43
|
+
export function loadLastFilesystemUpdate(source: SupportedUpdateSources): FilesystemUpdate {
|
|
41
44
|
const empty_update: FilesystemUpdate = {
|
|
42
|
-
updateSource:
|
|
45
|
+
updateSource: source,
|
|
43
46
|
file_errors: [],
|
|
44
47
|
date_start: new Date()
|
|
45
48
|
}
|
|
46
49
|
|
|
47
|
-
if (!fs.existsSync(
|
|
50
|
+
if (!fs.existsSync(JURIS_UPDATE_DIR))
|
|
48
51
|
return empty_update;
|
|
49
52
|
|
|
50
|
-
const files = fs.readdirSync(
|
|
53
|
+
const files = fs.readdirSync(JURIS_UPDATE_DIR);
|
|
51
54
|
for (const file of files) {
|
|
52
|
-
const fullPath = path.join(
|
|
55
|
+
const fullPath = path.join(JURIS_UPDATE_DIR, file);
|
|
53
56
|
if (fs.statSync(fullPath).isFile() && file.toLowerCase().includes("log")) {
|
|
54
57
|
const jsonString = fs.readFileSync(fullPath, 'utf-8');
|
|
55
58
|
const parsed: FilesystemUpdate = JSON.parse(jsonString);
|
|
56
59
|
return parsed;
|
|
57
60
|
}
|
|
58
61
|
}
|
|
59
|
-
|
|
60
62
|
return empty_update;
|
|
61
63
|
}
|
|
62
64
|
|
package/src/types.ts
CHANGED
|
@@ -11,7 +11,12 @@ export const SHAREPOINT_COPY_PATH = `/Sharepoint`
|
|
|
11
11
|
export const DETAILS_NAME = "Detalhes"
|
|
12
12
|
export const ORIGINAL_NAME = "Original"
|
|
13
13
|
export const LOGS_PATH = "/Updates"
|
|
14
|
-
|
|
14
|
+
|
|
15
|
+
export const SHAREPOINT_LOGS_PATH = `${LOGS_PATH}/Sharepoint`
|
|
16
|
+
export const JURIS_LOGS_PATH = `${LOGS_PATH}/Juris`
|
|
17
|
+
|
|
18
|
+
export const SHAREPOINT_UPDATE_DIR = `${ROOT_PATH}${SHAREPOINT_LOGS_PATH}`;
|
|
19
|
+
export const JURIS_UPDATE_DIR = `${ROOT_PATH}${JURIS_LOGS_PATH}`;
|
|
15
20
|
|
|
16
21
|
export type FilesystemUpdate = {
|
|
17
22
|
updateSource: SupportedUpdateSources,
|