Skip to content

Commit b6d398c

Browse files
authored
Fix Github PAT saving (#331)
* ♻ refactor: Clearer control flow * 🐛 fix: Error in options to `createGistWithFile` was providing `filename` instead of `file` (#323) * 🐛 fix: Clean `__syncId` from papers And make `cleanPapers` generally handle private keys starting with `__` * ♻ refactor: Refactor & improve clarity * 🏗 build: gulp build
1 parent 8ae7683 commit b6d398c

File tree

4 files changed

+19
-16
lines changed

4 files changed

+19
-16
lines changed

src/background/background.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -278,10 +278,13 @@ const pullSyncPapers = async () => {
278278
});
279279
const remoteSyncId = global.state.gistData["__syncId"];
280280
delete global.state.gistData["__syncId"];
281-
const remotePapers =
282-
remoteSyncId === localSyncID
283-
? (await getStorage("papers")) ?? {}
284-
: global.state.gistData;
281+
282+
let remotePapers;
283+
if (remoteSyncId === localSyncID) {
284+
remotePapers = (await getStorage("papers")) ?? {};
285+
} else {
286+
remotePapers = global.state.gistData;
287+
}
285288
if (remoteSyncId === localSyncID) {
286289
warn("Pulled sync data from same device, ignoring.");
287290
}

src/shared/js/utils/functions.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,11 @@ function delay(fn, ms) {
199199
*/
200200
const cleanPapers = (papers) => {
201201
let cleaned = { ...papers };
202-
delete cleaned["__dataVersion"];
202+
Object.keys(cleaned).forEach((k) => {
203+
if (k.startsWith("__")) {
204+
delete cleaned[k];
205+
}
206+
});
203207
return cleaned;
204208
};
205209

src/shared/js/utils/sync.js

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,7 @@ const getIdentifier = async () => {
3131
* @param {boolean} options.patError - Whether to raise an error if no PAT
3232
* @returns {Promise<{ ok: boolean, payload: { file: { filename: string, raw_url: string, content: object }, pat: string, gistId: string } }>}
3333
*/
34-
const getGist = async (options) => {
35-
options = options ?? {};
36-
let pat = options.pat;
37-
let store = options.store ?? true;
38-
let patError = options.patError ?? true;
34+
const getGist = async ({ pat, store = true, patError = true }) => {
3935
try {
4036
if (!pat) pat = await getPat(patError);
4137

@@ -61,7 +57,7 @@ const getGist = async (options) => {
6157
info("No Gist found. Creating new one...");
6258
const papers = await getStorage("papers");
6359
gist = await createGistWithFile({
64-
filename,
60+
file: filename,
6561
pat,
6662
description,
6763
content: papers,
@@ -246,9 +242,9 @@ const initSyncAndState = async ({
246242
stateIsReady = () => {},
247243
remoteIsReady = () => {},
248244
} = {}) => {
249-
(!global.state.dataVersion || forceInit) &&
250-
(await initState({ papers, isContentScript }));
251-
245+
if (!global.state.dataVersion || forceInit) {
246+
await initState({ papers, isContentScript });
247+
}
252248
stateIsReady();
253249

254250
if (!(await shouldSync())) {

src/shared/min/utils.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)