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:
Matt Van Horn
2026-10-27 22:08:10 +00:00
parent 9ede0fb10e
commit d7fb17ebfb
4 changed files with 63 additions and 44 deletions

View File

@@ -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",

View File

@@ -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

View File

@@ -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')
)
}

View 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')
)
}