Initial Upload
Some checks failed
Create Release on Tag Push / build (push) Has been cancelled

This commit is contained in:
MassiveBox 2025-03-31 19:14:17 +02:00
parent 777f31761c
commit eaca7fc192
Signed by: massivebox
GPG key ID: 9B74D3A59181947D
20 changed files with 469 additions and 1718 deletions

37
src/file.ts Normal file
View file

@ -0,0 +1,37 @@
import {getFileBlob, putFile} from "@/api";
function toFile(title: string, content: string, mimeType: string){
const blob = new Blob([content], { type: mimeType });
return new File([blob], title, { type: mimeType });
}
export function saveFile(path: string, mimeType: string, content: string) {
const file = toFile(path.split('/').pop(), content, mimeType);
try {
putFile(path, false, file);
} catch (error) {
console.error("Error saving file:", error);
throw error;
}
}
export async function getFile(path: string) {
const blob = await getFileBlob(path);
const jsonText = await blob.text();
// if we got a 404 api response, we will return null
try {
const res = JSON.parse(jsonText);
if(res.code == 404) {
return null;
}
}catch {}
// js-draw expects a string!
return jsonText;
}