Files
doc-forge-reborn/web/src/api/templates.ts
T
2026-07-08 20:02:29 +08:00

38 lines
1.2 KiB
TypeScript

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}`;
}