mirror of
https://github.com/docmost/docmost.git
synced 2026-05-18 23:44:24 +08:00
f388540293
* fix maths node * render default html width * Add page export module * with support for html and markdown exports * Page export UI * Add PDF print too * remove unused import
83 lines
2.1 KiB
TypeScript
83 lines
2.1 KiB
TypeScript
import api from "@/lib/api-client";
|
|
import {
|
|
IExportPageParams,
|
|
IMovePage,
|
|
IPage,
|
|
IPageInput,
|
|
SidebarPagesParams,
|
|
} from "@/features/page/types/page.types";
|
|
import { IAttachment, IPagination } from "@/lib/types.ts";
|
|
import { saveAs } from "file-saver";
|
|
|
|
export async function createPage(data: Partial<IPage>): Promise<IPage> {
|
|
const req = await api.post<IPage>("/pages/create", data);
|
|
return req.data;
|
|
}
|
|
|
|
export async function getPageById(
|
|
pageInput: Partial<IPageInput>,
|
|
): Promise<IPage> {
|
|
const req = await api.post<IPage>("/pages/info", pageInput);
|
|
return req.data;
|
|
}
|
|
|
|
export async function updatePage(data: Partial<IPageInput>): Promise<IPage> {
|
|
const req = await api.post<IPage>("/pages/update", data);
|
|
return req.data;
|
|
}
|
|
|
|
export async function deletePage(pageId: string): Promise<void> {
|
|
await api.post("/pages/delete", { pageId });
|
|
}
|
|
|
|
export async function movePage(data: IMovePage): Promise<void> {
|
|
await api.post<void>("/pages/move", data);
|
|
}
|
|
|
|
export async function getSidebarPages(
|
|
params: SidebarPagesParams,
|
|
): Promise<IPagination<IPage>> {
|
|
const req = await api.post("/pages/sidebar-pages", params);
|
|
return req.data;
|
|
}
|
|
|
|
export async function getPageBreadcrumbs(
|
|
pageId: string,
|
|
): Promise<Partial<IPage[]>> {
|
|
const req = await api.post("/pages/breadcrumbs", { pageId });
|
|
return req.data;
|
|
}
|
|
|
|
export async function getRecentChanges(
|
|
spaceId?: string,
|
|
): Promise<IPagination<IPage>> {
|
|
const req = await api.post("/pages/recent", { spaceId });
|
|
return req.data;
|
|
}
|
|
|
|
export async function exportPage(data: IExportPageParams): Promise<void> {
|
|
const req = await api.post("/pages/export", data, {
|
|
responseType: "blob",
|
|
});
|
|
|
|
const fileName = req?.headers["content-disposition"]
|
|
.split("filename=")[1]
|
|
.replace(/"/g, "");
|
|
|
|
saveAs(req.data, fileName);
|
|
}
|
|
|
|
export async function uploadFile(file: File, pageId: string) {
|
|
const formData = new FormData();
|
|
formData.append("pageId", pageId);
|
|
formData.append("file", file);
|
|
|
|
const req = await api.post<IAttachment>("/files/upload", formData, {
|
|
headers: {
|
|
"Content-Type": "multipart/form-data",
|
|
},
|
|
});
|
|
|
|
return req;
|
|
}
|