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,10 +1,25 @@
import {getFileBlob, putFile} from "@/api";
import {getFileBlob, putFile, upload} from "@/api";
import {ASSETS_PATH} from "@/const";
import {assetPathToIDs} from "@/helper";
function toFile(title: string, content: string, mimeType: string){
const blob = new Blob([content], { type: mimeType });
return new File([blob], title, { type: mimeType });
}
// upload asset to the assets folder, return fileID and syncID
export async function uploadAsset(fileID: string, mimeType: string, content: string) {
const file = toFile(fileID + ".svg", content, mimeType);
let r = await upload('/' + ASSETS_PATH, [file]);
if(r.errFiles) {
throw new Error("Failed to upload file");
}
return assetPathToIDs(r.succMap[file.name]);
}
export function saveFile(path: string, mimeType: string, content: string) {
const file = toFile(path.split('/').pop(), content, mimeType);