feat: add chat page export actions
This commit is contained in:
@@ -958,6 +958,41 @@ export async function quickShareFromChat(input: {
|
||||
return result.data;
|
||||
}
|
||||
|
||||
export async function downloadChatMessageDocx(input: {
|
||||
sessionId: string;
|
||||
messageId: string;
|
||||
selectedLinkIndex?: number;
|
||||
}): Promise<{ blob: Blob; filename: string }> {
|
||||
let res: Response;
|
||||
try {
|
||||
res = await fetch(`${API}/mindspace/v1/pages/chat-save-docx`, {
|
||||
method: 'POST',
|
||||
credentials: 'same-origin',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
session_id: input.sessionId,
|
||||
message_id: input.messageId,
|
||||
selected_link_index: input.selectedLinkIndex ?? 0,
|
||||
}),
|
||||
});
|
||||
} catch (err) {
|
||||
throw new ApiError(0, formatNetworkError(err));
|
||||
}
|
||||
if (res.status === 401) {
|
||||
notifyUnauthorized();
|
||||
throw new ApiError(401, '未授权,请重新登录');
|
||||
}
|
||||
if (!res.ok) {
|
||||
const parsed = await parseErrorResponse(res);
|
||||
throw new ApiError(res.status, parsed.message || `${res.status} ${res.statusText}`, parsed.code);
|
||||
}
|
||||
const disposition = res.headers.get('Content-Disposition') ?? '';
|
||||
const filenameMatch =
|
||||
disposition.match(/filename\*=UTF-8''([^;]+)/i) || disposition.match(/filename="?([^";]+)"?/i);
|
||||
const filename = filenameMatch ? decodeURIComponent(filenameMatch[1]) : 'mindspace-document.docx';
|
||||
return { blob: await res.blob(), filename };
|
||||
}
|
||||
|
||||
export async function fetchPreviewAsset(path: string): Promise<string> {
|
||||
let res: Response;
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user