Fix sync inconsistencies across devices

Changed APIs to upload assets, reworked saving logic so that files are synced across devices when changed locally.
This commit is contained in:
MassiveBox 2025-04-05 19:30:31 +02:00
parent e165c69664
commit 4555ec275f
Signed by: massivebox
GPG key ID: 9B74D3A59181947D
5 changed files with 104 additions and 60 deletions

View file

@ -1,5 +1,5 @@
import {getBlockByID, sql, updateBlock} from "@/api";
import {DUMMY_HOST} from "@/const";
import {IDsToAssetPath} from "@/helper";
export async function findImageBlocks(src: string) {
@ -45,9 +45,9 @@ export async function replaceBlockContent(
}
}
export async function replaceAntiCacheID(src: string) {
export async function replaceSyncID(fileID: string, oldSyncID: string, newSyncID: string) {
const search = encodeURI(src); // the API uses URI-encoded
const search = encodeURI(IDsToAssetPath(fileID, oldSyncID)); // the API uses URI-encoded
// find blocks containing that image
const blocks = await findImageBlocks(search);
@ -61,9 +61,7 @@ export async function replaceAntiCacheID(src: string) {
.filter(source => source.startsWith(search)) // discard other images
for(const source of sources) {
const url = new URL(source, DUMMY_HOST);
url.searchParams.set('antiCache', Date.now().toString()); // set or replace antiCache
const newSource = url.href.replace(DUMMY_HOST, '');
const newSource = IDsToAssetPath(fileID, newSyncID);
await replaceBlockContent(block.id, source, newSource);
}
}