Files
2026-11-12 06:29:38 +08:00

2 lines
3.0 KiB
JavaScript

import{z as r}from"./react-hot-toast-cGcFZPSt.js";import{L as o}from"./index-DiaaLdUu.js";class p{static async listFiles(t="/"){const{data:a}=await o.get(`/File/list?path=${encodeURIComponent(t)}`);return a.data}static async listDirectories(t="/"){const{data:a}=await o.get(`/File/list?path=${encodeURIComponent(t)}&onlyDirectory=true`);return a.data}static async createDirectory(t){const{data:a}=await o.post("/File/mkdir",{path:t});return a.data}static async delete(t){const{data:a}=await o.post("/File/delete",{path:t});return a.data}static async readFile(t){const{data:a}=await o.get(`/File/read?path=${encodeURIComponent(t)}`);return a.data}static async writeFile(t,a){const{data:e}=await o.post("/File/write",{path:t,content:a});return e.data}static async createFile(t){const{data:a}=await o.post("/File/create",{path:t});return a.data}static async batchDelete(t){const{data:a}=await o.post("/File/batchDelete",{paths:t});return a.data}static async rename(t,a){const{data:e}=await o.post("/File/rename",{oldPath:t,newPath:a});return e.data}static async move(t,a){const{data:e}=await o.post("/File/move",{sourcePath:t,targetPath:a});return e.data}static async batchMove(t){const{data:a}=await o.post("/File/batchMove",{items:t});return a.data}static download(t){const a=`/File/download?path=${encodeURIComponent(t)}`;r.promise(o.post(a,void 0,{responseType:"blob"}).catch(e=>{throw console.error(e),new Error("下载失败")}),{loading:"正在下载文件...",success:"下载成功",error:"下载失败"}).then(e=>{const s=window.URL.createObjectURL(new Blob([e.data])),n=document.createElement("a");n.href=s;let c=t.split("/").pop()||"";t.split(".").length===1&&(c+=".zip"),n.setAttribute("download",c),document.body.appendChild(n),n.click(),document.body.removeChild(n)}).catch(e=>{console.error(e)})}static async batchDownload(t){r.promise(o.post("/File/batchDownload",{paths:t},{responseType:"blob"}).catch(e=>{throw console.error(e),new Error("下载失败")}),{loading:"正在下载文件...",success:"下载成功",error:"下载失败"}).then(e=>{const s=window.URL.createObjectURL(new Blob([e.data])),n=document.createElement("a");n.href=s,n.setAttribute("download","files.zip"),document.body.appendChild(n),n.click(),document.body.removeChild(n)}).catch(e=>{console.error(e)})}static async downloadToURL(t){const a=`/File/download?path=${encodeURIComponent(t)}`,e=await o.post(a,void 0,{responseType:"blob"});return window.URL.createObjectURL(new Blob([e.data]))}static async upload(t,a){const e=new FormData;a.forEach(n=>{e.append("files",n)});const{data:s}=await o.post(`/File/upload?path=${encodeURIComponent(t)}`,e,{headers:{"Content-Type":"multipart/form-data"}});return s.data}static async uploadWebUIFont(t){const a=new FormData;a.append("file",t);const{data:e}=await o.post("/File/font/upload/webui",a,{headers:{"Content-Type":"multipart/form-data"}});return e.data}static async deleteWebUIFont(){const{data:t}=await o.post("/File/font/delete/webui");return t.data}static async checkWebUIFontExists(){const{data:t}=await o.get("/File/font/exists/webui");return t.data}}export{p as F};