mirror of
https://github.com/HKUDS/DeepTutor.git
synced 2026-12-04 00:51:17 +08:00
fix(calendar): refresh the router index and keep export off the shared client
The new export.ics route needs a regenerated lazy-routing fingerprint. Move the .ics download helper out of the shared calendar transport so the workspace reminder runtime does not add blob-saving code to every layout.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"fingerprint": "83363f052eafc8a39b8d91e575ee819a8aa01b7b86d06a19167c718f5abcf757",
|
||||
"fingerprint": "553b7ccd8070c649ca44126cc942f7600f0df6e5c054e902b0d84e5136f59b99",
|
||||
"routers": {
|
||||
"deeptutor.api.routers.auth:router": [
|
||||
{
|
||||
@@ -1923,6 +1923,14 @@
|
||||
}
|
||||
],
|
||||
"deeptutor.api.routers.calendar:router": [
|
||||
{
|
||||
"path": "/export.ics",
|
||||
"name": "export_ics",
|
||||
"kind": "http",
|
||||
"methods": [
|
||||
"GET"
|
||||
]
|
||||
},
|
||||
{
|
||||
"path": "/calendars",
|
||||
"name": "calendars",
|
||||
|
||||
@@ -11,6 +11,7 @@ import { useActiveWorkspaceId } from '@/hooks/useActiveWorkspaceId'
|
||||
import { useTaskBoard } from '@/lib/task-board-store'
|
||||
import { DEFAULT_TASK_COLORS, updateTaskCard } from '@/lib/task-board-api'
|
||||
import * as api from '../transport/api'
|
||||
import { exportIcs } from '../transport/export'
|
||||
import {
|
||||
noteCalendarRevision,
|
||||
refreshCalendars,
|
||||
@@ -294,7 +295,7 @@ export default function CalendarPage() {
|
||||
const downloadIcs = async (calendarId?: string) => {
|
||||
setError('')
|
||||
try {
|
||||
await api.exportIcs(calendarId)
|
||||
await exportIcs(calendarId)
|
||||
} catch (e) {
|
||||
setError(
|
||||
e instanceof api.CalendarRequestError && e.detail
|
||||
|
||||
@@ -225,45 +225,3 @@ export function restoreEvent(token: string) {
|
||||
export function getTaskBlocks(signal?: AbortSignal) {
|
||||
return json<Record<string, number>>('/task-blocks', { signal })
|
||||
}
|
||||
|
||||
function filenameFromDisposition(header: string | null, fallback: string): string {
|
||||
if (!header) return fallback
|
||||
const encoded = /filename\*=UTF-8''([^;]+)/i.exec(header)
|
||||
if (encoded?.[1]) {
|
||||
try {
|
||||
return decodeURIComponent(encoded[1].trim())
|
||||
} catch {
|
||||
/* malformed percent-encoding — use the quoted form */
|
||||
}
|
||||
}
|
||||
const plain = /filename="?([^";]+)"?/i.exec(header)
|
||||
return plain?.[1]?.trim() || fallback
|
||||
}
|
||||
|
||||
function saveBlob(blob: Blob, filename: string): void {
|
||||
const url = URL.createObjectURL(blob)
|
||||
const anchor = document.createElement('a')
|
||||
anchor.href = url
|
||||
anchor.download = filename
|
||||
anchor.click()
|
||||
URL.revokeObjectURL(url)
|
||||
}
|
||||
|
||||
export async function exportIcs(calendarId?: string): Promise<void> {
|
||||
const response = await apiFetch(`${endpoint}/export.ics${query({ calendar_id: calendarId })}`, {
|
||||
cache: 'no-store',
|
||||
})
|
||||
if (!response.ok) {
|
||||
let detail = ''
|
||||
try {
|
||||
detail = String((await response.json())?.detail ?? '')
|
||||
} catch {
|
||||
/* no body */
|
||||
}
|
||||
throw new CalendarRequestError(response.status, detail)
|
||||
}
|
||||
saveBlob(
|
||||
await response.blob(),
|
||||
filenameFromDisposition(response.headers.get('content-disposition'), 'calendar.ics')
|
||||
)
|
||||
}
|
||||
|
||||
52
web/features/calendar/transport/export.ts
Normal file
52
web/features/calendar/transport/export.ts
Normal file
@@ -0,0 +1,52 @@
|
||||
import { apiFetch } from '@/shared/api/client'
|
||||
import { CalendarRequestError } from './api'
|
||||
|
||||
/**
|
||||
* Calendar-page download helper. Keep this out of `api.ts` so the workspace
|
||||
* reminder runtime does not pull blob-saving code into every layout.
|
||||
*/
|
||||
|
||||
const endpoint = '/api/calendar'
|
||||
|
||||
function filenameFromDisposition(header: string | null, fallback: string): string {
|
||||
if (!header) return fallback
|
||||
const encoded = /filename\*=UTF-8''([^;]+)/i.exec(header)
|
||||
if (encoded?.[1]) {
|
||||
try {
|
||||
return decodeURIComponent(encoded[1].trim())
|
||||
} catch {
|
||||
/* malformed percent-encoding — use the quoted form */
|
||||
}
|
||||
}
|
||||
const plain = /filename="?([^";]+)"?/i.exec(header)
|
||||
return plain?.[1]?.trim() || fallback
|
||||
}
|
||||
|
||||
function saveBlob(blob: Blob, filename: string): void {
|
||||
const url = URL.createObjectURL(blob)
|
||||
const anchor = document.createElement('a')
|
||||
anchor.href = url
|
||||
anchor.download = filename
|
||||
anchor.click()
|
||||
URL.revokeObjectURL(url)
|
||||
}
|
||||
|
||||
export async function exportIcs(calendarId?: string): Promise<void> {
|
||||
const search = calendarId ? `?calendar_id=${encodeURIComponent(calendarId)}` : ''
|
||||
const response = await apiFetch(`${endpoint}/export.ics${search}`, {
|
||||
cache: 'no-store',
|
||||
})
|
||||
if (!response.ok) {
|
||||
let detail = ''
|
||||
try {
|
||||
detail = String((await response.json())?.detail ?? '')
|
||||
} catch {
|
||||
/* no body */
|
||||
}
|
||||
throw new CalendarRequestError(response.status, detail)
|
||||
}
|
||||
saveBlob(
|
||||
await response.blob(),
|
||||
filenameFromDisposition(response.headers.get('content-disposition'), 'calendar.ics')
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user