From e4018a7008da265b9d642dcb5039ab7eeb2026d2 Mon Sep 17 00:00:00 2001 From: mat <27899617+mat-1@users.noreply.github.com> Date: Sun, 28 Feb 2021 21:31:42 -0600 Subject: actually fix cache --- build/constants.js | 10 ++++++++-- src/constants.ts | 10 ++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/build/constants.js b/build/constants.js index 5e09240..961e998 100644 --- a/build/constants.js +++ b/build/constants.js @@ -57,6 +57,7 @@ async function fetchFile(path) { sha: data.sha }; fileCache.set(path, file); + return file; } /** * Edit a file on skyblock-constants @@ -65,13 +66,18 @@ async function fetchFile(path) { * @param newContent The new content in the file */ async function editFile(file, message, newContent) { - fileCache.set(file.path, newContent); - await fetchGithubApi('PUT', `/repos/${owner}/${repo}/contents/${file.path}`, { 'Content-Type': 'application/json' }, { + const r = await fetchGithubApi('PUT', `/repos/${owner}/${repo}/contents/${file.path}`, { 'Content-Type': 'application/json' }, { message: message, content: Buffer.from(newContent).toString('base64'), sha: file.sha, branch: 'main' }); + const data = await r.json(); + fileCache.set(file.path, { + path: data.content.path, + content: newContent, + sha: data.content.sha + }); } /** Fetch all the known SkyBlock stats as an array of strings */ async function fetchStats() { diff --git a/src/constants.ts b/src/constants.ts index 1792b94..610d1a8 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -72,6 +72,7 @@ async function fetchFile(path: string): Promise { sha: data.sha } fileCache.set(path, file) + return file } /** @@ -81,8 +82,7 @@ async function fetchFile(path: string): Promise { * @param newContent The new content in the file */ async function editFile(file: GithubFile, message: string, newContent: string) { - fileCache.set(file.path, newContent) - await fetchGithubApi( + const r = await fetchGithubApi( 'PUT', `/repos/${owner}/${repo}/contents/${file.path}`, { 'Content-Type': 'application/json' }, @@ -93,6 +93,12 @@ async function editFile(file: GithubFile, message: string, newContent: string) { branch: 'main' } ) + const data = await r.json() + fileCache.set(file.path, { + path: data.content.path, + content: newContent, + sha: data.content.sha + }) } /** Fetch all the known SkyBlock stats as an array of strings */ -- cgit