kvitton-cli 0.4.5 → 0.4.6
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/index.js +33 -9
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -9568,13 +9568,13 @@ async function uploadDocumentsForEntry(client2, storage2, absoluteDirPath, relat
|
|
|
9568
9568
|
const { content } = await storage2.readFile(documentsYamlPath);
|
|
9569
9569
|
existingDocs = parseYaml2(content) || [];
|
|
9570
9570
|
} catch {}
|
|
9571
|
-
const
|
|
9571
|
+
const linkedFiles = new Set(existingDocs.filter((d) => d.sourceIntegration === "bokio" && d.linkedToJournalEntry).map((d) => d.fileName));
|
|
9572
9572
|
for (const filename of files) {
|
|
9573
9573
|
const ext = path6.extname(filename).toLowerCase();
|
|
9574
9574
|
if (!UPLOADABLE_EXTENSIONS.includes(ext)) {
|
|
9575
9575
|
continue;
|
|
9576
9576
|
}
|
|
9577
|
-
if (
|
|
9577
|
+
if (linkedFiles.has(filename)) {
|
|
9578
9578
|
continue;
|
|
9579
9579
|
}
|
|
9580
9580
|
try {
|
|
@@ -9592,12 +9592,27 @@ async function uploadDocumentsForEntry(client2, storage2, absoluteDirPath, relat
|
|
|
9592
9592
|
filename,
|
|
9593
9593
|
journalEntryId
|
|
9594
9594
|
});
|
|
9595
|
-
existingDocs.
|
|
9596
|
-
|
|
9597
|
-
|
|
9598
|
-
|
|
9599
|
-
|
|
9600
|
-
|
|
9595
|
+
const existingDoc = existingDocs.find((d) => d.fileName === filename);
|
|
9596
|
+
if (existingDoc) {
|
|
9597
|
+
const previousSourceIds = [
|
|
9598
|
+
...existingDoc.previousSourceIds || [],
|
|
9599
|
+
...existingDoc.sourceId ? [existingDoc.sourceId] : []
|
|
9600
|
+
];
|
|
9601
|
+
existingDoc.sourceId = upload.id;
|
|
9602
|
+
existingDoc.sourceIntegration = "bokio";
|
|
9603
|
+
existingDoc.linkedToJournalEntry = true;
|
|
9604
|
+
if (previousSourceIds.length > 0) {
|
|
9605
|
+
existingDoc.previousSourceIds = previousSourceIds;
|
|
9606
|
+
}
|
|
9607
|
+
} else {
|
|
9608
|
+
existingDocs.push({
|
|
9609
|
+
fileName: filename,
|
|
9610
|
+
mimeType,
|
|
9611
|
+
sourceIntegration: "bokio",
|
|
9612
|
+
sourceId: upload.id,
|
|
9613
|
+
linkedToJournalEntry: true
|
|
9614
|
+
});
|
|
9615
|
+
}
|
|
9601
9616
|
await storage2.writeFile(documentsYamlPath, toYaml2(existingDocs));
|
|
9602
9617
|
console.log(` Uploaded file: ${filename}`);
|
|
9603
9618
|
} catch (fileError) {
|
|
@@ -9870,6 +9885,15 @@ async function isAlreadyDownloaded2(cwd, sourceId) {
|
|
|
9870
9885
|
path7.join(cwd, "inbox"),
|
|
9871
9886
|
path7.join(cwd, "drafts")
|
|
9872
9887
|
];
|
|
9888
|
+
const journalEntriesDir = path7.join(cwd, "journal-entries");
|
|
9889
|
+
try {
|
|
9890
|
+
const fyDirs = await fs12.readdir(journalEntriesDir, { withFileTypes: true });
|
|
9891
|
+
for (const fyDir of fyDirs) {
|
|
9892
|
+
if (fyDir.isDirectory() && fyDir.name.startsWith("FY-")) {
|
|
9893
|
+
dirsToCheck.push(path7.join(journalEntriesDir, fyDir.name));
|
|
9894
|
+
}
|
|
9895
|
+
}
|
|
9896
|
+
} catch {}
|
|
9873
9897
|
for (const baseDir of dirsToCheck) {
|
|
9874
9898
|
try {
|
|
9875
9899
|
const dirs = await fs12.readdir(baseDir, { withFileTypes: true });
|
|
@@ -9880,7 +9904,7 @@ async function isAlreadyDownloaded2(cwd, sourceId) {
|
|
|
9880
9904
|
try {
|
|
9881
9905
|
const content = await fs12.readFile(documentsPath, "utf-8");
|
|
9882
9906
|
const documents = parseYaml2(content);
|
|
9883
|
-
if (documents?.some((doc) => doc.sourceId === sourceId)) {
|
|
9907
|
+
if (documents?.some((doc) => doc.sourceId === sourceId || doc.previousSourceIds?.includes(sourceId))) {
|
|
9884
9908
|
return true;
|
|
9885
9909
|
}
|
|
9886
9910
|
} catch {}
|