mirror of
https://github.com/docmost/docmost.git
synced 2026-05-07 06:23:06 +08:00
feat(base): add client csv export service call
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
import api from "@/lib/api-client";
|
import api from "@/lib/api-client";
|
||||||
|
import { saveAs } from "file-saver";
|
||||||
import {
|
import {
|
||||||
IBase,
|
IBase,
|
||||||
IBaseProperty,
|
IBaseProperty,
|
||||||
@@ -46,6 +47,26 @@ export async function deleteBase(baseId: string): Promise<void> {
|
|||||||
await api.post("/bases/delete", { baseId });
|
await api.post("/bases/delete", { baseId });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function exportBaseToCsv(baseId: string): Promise<void> {
|
||||||
|
const req = await api.post(
|
||||||
|
"/bases/export-csv",
|
||||||
|
{ baseId },
|
||||||
|
{ responseType: "blob" },
|
||||||
|
);
|
||||||
|
|
||||||
|
const header = (req?.headers?.["content-disposition"] as string) ?? "";
|
||||||
|
const utf8Match = header.match(/filename\*=UTF-8''([^;]+)/i);
|
||||||
|
const plainMatch = header.match(/filename="?([^";]+)"?/i);
|
||||||
|
let fileName = utf8Match?.[1] ?? plainMatch?.[1] ?? "base.csv";
|
||||||
|
try {
|
||||||
|
fileName = decodeURIComponent(fileName);
|
||||||
|
} catch {
|
||||||
|
// fallback to raw filename
|
||||||
|
}
|
||||||
|
|
||||||
|
saveAs(req.data, fileName);
|
||||||
|
}
|
||||||
|
|
||||||
export async function listBases(
|
export async function listBases(
|
||||||
spaceId: string,
|
spaceId: string,
|
||||||
params?: { cursor?: string; limit?: number },
|
params?: { cursor?: string; limit?: number },
|
||||||
|
|||||||
Reference in New Issue
Block a user