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:
parent
e165c69664
commit
4555ec275f
5 changed files with 104 additions and 60 deletions
17
src/file.ts
17
src/file.ts
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue