Skip to content

Commit

Permalink
Merge pull request #448 from fastrodev/store
Browse files Browse the repository at this point in the history
Store
  • Loading branch information
ynwd authored Sep 23, 2024
2 parents 2e0ce1e + e7e9762 commit 4318826
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion core/map/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export class Store<K extends string | number | symbol, V> {
constructor(options: StoreOptions = null) {
this.map = new Map<K, { value: V; expiry?: number }>();
this.options = options;
// this.init();
}

/**
Expand Down Expand Up @@ -153,6 +154,8 @@ export class Store<K extends string | number | symbol, V> {
branch: this.options.branch,
},
);
} catch (error) {
console.log(error);
} finally {
this.isCommitting = false;
}
Expand Down Expand Up @@ -246,7 +249,10 @@ function recordToMap<K extends string | number | symbol, V>(
const map = new Map<K, { value: V; expiry: number }>();

Object.entries(record).forEach(([key, value]) => {
map.set(key as K, value as { value: V; expiry: number });
const entry = value as { value: V; expiry: number };
if (entry.expiry === undefined || Date.now() < entry.expiry) {
map.set(key as K, entry);
}
});

return map;
Expand Down Expand Up @@ -316,6 +322,9 @@ async function getMap<K extends string | number | symbol, V>(
return recordToMap<K, V>(JSON.parse(data));
}

/**
* Gets the contents of a file in a repository (1-100 MB)
*/
async function getFileFromGithub(options: StoreOptions) {
if (!options || !options.token) throw new Error("GITHUB_TOKEN is needed");
const octokit = new Octokit({ auth: options.token });
Expand All @@ -325,6 +334,7 @@ async function getFileFromGithub(options: StoreOptions) {
repo: options.repo,
path: options.path,
ref: options.branch,
mediaType: { format: "raw" },
});
return res.data;
} catch {
Expand Down

0 comments on commit 4318826

Please sign in to comment.