init: 初始化项目
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
import request from "./request";
|
||||
import type { Template, TemplateListItem } from "../types";
|
||||
|
||||
export async function listTemplates() {
|
||||
const { data } = await request.get<TemplateListItem[]>("/templates");
|
||||
return data;
|
||||
}
|
||||
|
||||
export async function getTemplate(id: string) {
|
||||
const { data } = await request.get<Template>(`/templates/${id}`);
|
||||
return data;
|
||||
}
|
||||
|
||||
export async function uploadTemplate(file: File, name?: string) {
|
||||
const formData = new FormData();
|
||||
formData.append("file", file);
|
||||
if (name) formData.append("name", name);
|
||||
const { data } = await request.post<Template>("/templates", formData);
|
||||
return data;
|
||||
}
|
||||
|
||||
export async function getTemplateHtml(id: string) {
|
||||
const { data } = await request.get<{ html_content: string }>(`/templates/${id}/html`);
|
||||
return data.html_content;
|
||||
}
|
||||
|
||||
export async function updateTemplateHtml(id: string, html_content: string) {
|
||||
await request.put(`/templates/${id}/html`, { html_content });
|
||||
}
|
||||
|
||||
export async function deleteTemplate(id: string) {
|
||||
await request.delete(`/templates/${id}`);
|
||||
}
|
||||
|
||||
export function getDownloadUrl(id: string, format: "docx" | "pdf" = "docx") {
|
||||
return `/api/v1/templates/${id}/download?format=${format}`;
|
||||
}
|
||||
Reference in New Issue
Block a user