31 lines
1.2 KiB
JavaScript
31 lines
1.2 KiB
JavaScript
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.ItemStorage = void 0;
|
|
const FileUtils_1 = require("../FileUtils");
|
|
const path = require("node:path");
|
|
const fs = require("node:fs");
|
|
class ItemStorage {
|
|
constructor(itemDir) {
|
|
this.itemDir = itemDir;
|
|
FileUtils_1.FileUtils.prepareDirectoryFroWriting(this.itemDir);
|
|
}
|
|
storeItem(storedItems) {
|
|
this.persistDeletedItems(storedItems);
|
|
storedItems.forEach(item => this.storeSingleItem(item));
|
|
}
|
|
persistDeletedItems(existingItems) {
|
|
const itemFiles = FileUtils_1.FileUtils.listFilesInDirectory(this.itemDir);
|
|
itemFiles.forEach(itemFile => {
|
|
const itemFileName = path.parse(path.basename(itemFile)).name;
|
|
if (existingItems.find(item => item.fileName === itemFileName) == undefined) {
|
|
fs.unlinkSync(itemFile);
|
|
}
|
|
});
|
|
}
|
|
storeSingleItem(item) {
|
|
const completeItemFile = path.join(this.itemDir, item.fileName + ".json");
|
|
fs.writeFileSync(completeItemFile, item.jsonString, 'utf-8');
|
|
}
|
|
}
|
|
exports.ItemStorage = ItemStorage;
|
|
//# sourceMappingURL=ItemStorage.js.map
|