fix Vencord Backend Cloud Sync (#1234) (#1235)

This commit is contained in:
KRW 2026-07-09 22:28:31 +02:00 • committed by GitHub
parent 69418f8dd8
commit 665be44e16
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -137,19 +137,14 @@ function handleAuthFailure() {
async function doSyncV2(uploads: SyncRequest["uploads"], clientManifest: ManifestEntry[]): Promise<SyncResponse | null> {
let res: Response;
try {
res = await fetch(new URL("/v2/sync", getCloudUrl()), {
method: "POST",
headers: {
Authorization: await getCloudAuth(),
"Content-Type": "application/json",
},
body: JSON.stringify({ client_manifest: clientManifest, uploads } satisfies SyncRequest),
});
} catch (e) {
logger.error("v2 sync network error, will retry next sync", e);
return null;
}
res = await fetch(new URL("/v2/sync", getCloudUrl()), {
method: "POST",
headers: {
Authorization: await getCloudAuth(),
"Content-Type": "application/json",
},
body: JSON.stringify({ client_manifest: clientManifest, uploads } satisfies SyncRequest),
});
if (res.status === 404) {
logger.info("Server does not support v2, falling back to v1");
@ -275,6 +270,12 @@ async function deleteV2() {
headers: { Authorization: auth },
});
if (manifestRes.status === 404) {
logger.info("Server does not support v2, falling back to v1");
await setApiVersion("v1");
return;
}
if (!manifestRes.ok) {
showNotification({
title: "Cloud Settings",
@ -461,9 +462,15 @@ export async function putCloudSettings(manual?: boolean) {
try {
const version = await getApiVersion();
if (version === "v2") {
await putV2(manual);
if (await getApiVersion() === "v1")
try {
await putV2(manual);
if (await getApiVersion() === "v1")
await putV1(manual);
} catch (e) {
logger.info("v2 sync failed with network error, trying v1...");
await putV1(manual);
await setApiVersion("v1");
}
} else {
await putV1(manual);
}
@ -481,10 +488,17 @@ export async function getCloudSettings(shouldNotify = true, force = false) {
try {
const version = await getApiVersion();
if (version === "v2") {
const result = await getV2(shouldNotify, force);
if (await getApiVersion() === "v1")
return await getV1(shouldNotify, force);
return result;
try {
const result = await getV2(shouldNotify, force);
if (await getApiVersion() === "v1")
return await getV1(shouldNotify, force);
return result;
} catch (e) {
logger.info("v2 sync failed with network error, trying v1...");
const result = await getV1(shouldNotify, force);
await setApiVersion("v1");
return result;
}
}
return await getV1(shouldNotify, force);
} catch (e: any) {
@ -501,10 +515,20 @@ export async function getCloudSettings(shouldNotify = true, force = false) {
export async function deleteCloudSettings() {
try {
const version = await getApiVersion();
if (version === "v2")
await deleteV2();
else
if (version === "v2") {
try {
await deleteV2();
if (await getApiVersion() === "v1") {
await deleteV1();
}
} catch (e) {
logger.info("v2 sync failed with network error, trying v1...");
await deleteV1();
await setApiVersion("v1");
}
} else {
await deleteV1();
}
} catch (e: any) {
logger.error("Failed to delete", e);
showNotification({