Skip to content

Commit

Permalink
fix(storage): fix getLibraryEntry & saveLibraryEntry file handling
Browse files Browse the repository at this point in the history
  • Loading branch information
becem-gharbi committed May 22, 2023
1 parent a766797 commit b169400
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
5 changes: 5 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ const settings: LocalSettings = {
},
],
},
contextStorage: {
default: {
module: "localfilesystem",
},
},
};

const app = express();
Expand Down
26 changes: 17 additions & 9 deletions src/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,28 +42,31 @@ export const storageModule: StorageModule = {
name = "/" + name;
}

const library = await libraryStorage.getItem(name);
const library = await libraryStorage.getItem(name + ":" + type);

if (library) {
const parsedLibrary = JSON.parse(library);
const body = JSON.parse(library.body);
return body;
}

let libraryKeys = await libraryStorage.getKeys(name);

return parsedLibrary.body;
if (!libraryKeys) {
return [];
}

const libraryKeys = await libraryStorage.getKeys(name);
libraryKeys = libraryKeys.filter((el) => el.endsWith(type));

var dirs = [];
var files = [];

for (var i = 0; i < libraryKeys.length; i++) {
const library = await libraryStorage.getItem(libraryKeys[i]);

const parsedLibrary = JSON.parse(library);

var n = parsedLibrary.name;
var n = library.name;
n = n.replace(name, "");
if (n.indexOf("/") == -1) {
var f = parsedLibrary.meta;
var f = library.meta;
f.fn = n;
files.push(f);
} else {
Expand All @@ -85,6 +88,11 @@ export const storageModule: StorageModule = {
name = "/" + name;
}

return libraryStorage.setItem(name, { name, meta, body, type });
return libraryStorage.setItem(name + ":" + type, {
name,
meta,
body,
type,
});
},
};

0 comments on commit b169400

Please sign in to comment.