Revision loading, sync isses fix

This commit is contained in:
2025-09-24 07:34:25 +00:00
parent 4f120b68f5
commit 9f7f4c470e
5 changed files with 143 additions and 120 deletions

64
revision.js Normal file
View File

@@ -0,0 +1,64 @@
export async function saveRevision() {
console.log('ASDF');
const tree = await chrome.bookmarks.getTree();
const apiUrl = await chrome.storage.sync.get('apiUrl');
const syncToken = await chrome.storage.sync.get("syncToken");
if (!apiUrl || !syncToken)
return;
const savedRev = await chrome.storage.sync.get('revId');
const url = apiUrl.apiUrl + '/saveRevision';
const options = {
headers: {
'content-type': 'application/json',
'syncToken': syncToken.syncToken
},
method: 'POST',
body: JSON.stringify({
'revId': savedRev.revId,
'bookmarks': tree
})
};
try {
const response = await fetch(url, options);
if (!response.ok) {
throw new Error(`HTTP error! Status: ${response.status}`);
}
const data = await response.json(); // Convert to JSON
chrome.storage.sync.set({ revId: data.revId });
} catch (e) {
// TODO GD: Indicate error
}
}
export async function getRevision() {
const apiUrl = await chrome.storage.sync.get('apiUrl');
const syncToken = await chrome.storage.sync.get("syncToken");
if (!apiUrl || !syncToken)
return;
const url = apiUrl.apiUrl + '/getRevision';
const options = {
headers: {
'content-type': 'application/json',
'syncToken': syncToken.syncToken
},
method: 'GET'
};
try {
const response = await fetch(url, options);
if (!response.ok)
throw new Error(`HTTP error! Status: ${response.status}`);
return await response.json();
} catch (e) {
console.log(e);
return null;
}
}