@knotpad/app 0.1.0 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/brief.js +165 -78
- package/package.json +6 -86
- package/app/(app)/calendar/page.tsx +0 -57
- package/app/(app)/error.tsx +0 -35
- package/app/(app)/graph/page.tsx +0 -32
- package/app/(app)/guide/page.tsx +0 -21
- package/app/(app)/kanban/loading.tsx +0 -24
- package/app/(app)/kanban/page.tsx +0 -59
- package/app/(app)/layout.tsx +0 -122
- package/app/(app)/list/loading.tsx +0 -21
- package/app/(app)/list/page.tsx +0 -137
- package/app/(app)/loading.tsx +0 -18
- package/app/(app)/notes/[noteId]/page.tsx +0 -84
- package/app/(app)/notes/layout.tsx +0 -30
- package/app/(app)/notes/page.tsx +0 -39
- package/app/(app)/page.tsx +0 -5
- package/app/(app)/settings/agent-token/page.tsx +0 -59
- package/app/(app)/settings/backup/page.tsx +0 -49
- package/app/(app)/settings/billing/page.tsx +0 -53
- package/app/(app)/settings/calendar/page.tsx +0 -41
- package/app/(app)/settings/layout.test.tsx +0 -39
- package/app/(app)/settings/layout.tsx +0 -71
- package/app/(app)/settings/page.tsx +0 -4
- package/app/(app)/settings/security/page.tsx +0 -43
- package/app/(app)/settings/team/page.tsx +0 -74
- package/app/(app)/settings/workspace/page.tsx +0 -27
- package/app/(app)/tasks/[taskId]/page.tsx +0 -79
- package/app/(auth)/forgot-password/page.tsx +0 -106
- package/app/(auth)/guest/page.tsx +0 -56
- package/app/(auth)/layout.tsx +0 -13
- package/app/(auth)/login/page.tsx +0 -14
- package/app/(auth)/register/page.tsx +0 -193
- package/app/(auth)/reset-password/page.tsx +0 -138
- package/app/api/account/claim/route.tsx +0 -135
- package/app/api/admin/backfill-encryption/route.tsx +0 -43
- package/app/api/admin/license/route.tsx +0 -42
- package/app/api/auth/2fa/route.tsx +0 -148
- package/app/api/auth/[...nextauth]/route.tsx +0 -3
- package/app/api/auth/change-password/route.tsx +0 -61
- package/app/api/auth/check-2fa/route.tsx +0 -19
- package/app/api/auth/forgot-password/route.tsx +0 -65
- package/app/api/auth/reset-password/route.tsx +0 -52
- package/app/api/auth/verify-2fa/route.tsx +0 -88
- package/app/api/backup/download/db/route.ts +0 -29
- package/app/api/backup/download/notes/route.ts +0 -25
- package/app/api/backup/settings/route.ts +0 -92
- package/app/api/billing/checkout/route.tsx +0 -81
- package/app/api/billing/migrate/route.tsx +0 -163
- package/app/api/billing/portal/route.tsx +0 -24
- package/app/api/billing/setup-intent/route.tsx +0 -55
- package/app/api/billing/status/route.tsx +0 -36
- package/app/api/billing/subscribe/route.tsx +0 -85
- package/app/api/billing/webhook/route.tsx +0 -199
- package/app/api/calendar-feeds/[feedId]/route.tsx +0 -67
- package/app/api/calendar-feeds/[feedId]/sync/route.tsx +0 -37
- package/app/api/calendar-feeds/events/route.tsx +0 -82
- package/app/api/calendar-feeds/route.tsx +0 -52
- package/app/api/calendar-feeds/sync-all/route.tsx +0 -34
- package/app/api/cron/calendar-feeds/route.tsx +0 -31
- package/app/api/cron/stale-tasks/route.tsx +0 -51
- package/app/api/cron/sync/route.tsx +0 -34
- package/app/api/devices/[deviceId]/route.tsx +0 -25
- package/app/api/devices/route.tsx +0 -41
- package/app/api/export/route.tsx +0 -40
- package/app/api/feedback/route.tsx +0 -54
- package/app/api/folders/[folderId]/route.tsx +0 -51
- package/app/api/folders/route.tsx +0 -37
- package/app/api/graph/route.tsx +0 -242
- package/app/api/guest/route.tsx +0 -58
- package/app/api/health/route.tsx +0 -10
- package/app/api/holidays/countries/route.tsx +0 -14
- package/app/api/holidays/route.tsx +0 -49
- package/app/api/holidays/states/route.tsx +0 -21
- package/app/api/invites/[token]/route.tsx +0 -131
- package/app/api/invites/route.tsx +0 -74
- package/app/api/mcp/generate-token/route.tsx +0 -55
- package/app/api/mcp/revoke-token/[tokenId]/route.tsx +0 -30
- package/app/api/mcp/update-alias/[tokenId]/route.tsx +0 -22
- package/app/api/notes/[noteId]/export/route.tsx +0 -45
- package/app/api/notes/[noteId]/route.tsx +0 -360
- package/app/api/notes/route.tsx +0 -112
- package/app/api/notifications/route.tsx +0 -44
- package/app/api/register/route.tsx +0 -67
- package/app/api/restore/route.tsx +0 -148
- package/app/api/sync/conflicts/[conflictId]/route.tsx +0 -134
- package/app/api/sync/conflicts/route.tsx +0 -48
- package/app/api/sync/status/route.tsx +0 -49
- package/app/api/sync/trigger/route.tsx +0 -15
- package/app/api/tasks/[taskId]/detail/route.tsx +0 -68
- package/app/api/tasks/[taskId]/route.tsx +0 -259
- package/app/api/tasks/bulk/route.tsx +0 -133
- package/app/api/tasks/route.tsx +0 -36
- package/app/api/workspace/active/route.tsx +0 -39
- package/app/api/workspace/create-team/route.tsx +0 -42
- package/app/api/workspace/kanban-statuses/route.tsx +0 -71
- package/app/api/workspace/members/[memberId]/route.tsx +0 -69
- package/app/api/workspace/route.tsx +0 -24
- package/app/download/page.tsx +0 -170
- package/app/favicon.ico +0 -0
- package/app/generated/prisma/client.d.ts +0 -1
- package/app/generated/prisma/client.js +0 -5
- package/app/generated/prisma/default.d.ts +0 -1
- package/app/generated/prisma/default.js +0 -5
- package/app/generated/prisma/edge.d.ts +0 -1
- package/app/generated/prisma/edge.js +0 -497
- package/app/generated/prisma/index-browser.js +0 -523
- package/app/generated/prisma/index.d.ts +0 -46376
- package/app/generated/prisma/index.js +0 -497
- package/app/generated/prisma/package.json +0 -144
- package/app/generated/prisma/query_compiler_fast_bg.js +0 -2
- package/app/generated/prisma/query_compiler_fast_bg.wasm +0 -0
- package/app/generated/prisma/query_compiler_fast_bg.wasm-base64.js +0 -2
- package/app/generated/prisma/runtime/client.d.ts +0 -3386
- package/app/generated/prisma/runtime/client.js +0 -86
- package/app/generated/prisma/runtime/index-browser.d.ts +0 -90
- package/app/generated/prisma/runtime/index-browser.js +0 -6
- package/app/generated/prisma/runtime/wasm-compiler-edge.js +0 -76
- package/app/generated/prisma/schema.prisma +0 -456
- package/app/generated/prisma/wasm-edge-light-loader.mjs +0 -5
- package/app/generated/prisma/wasm-worker-loader.mjs +0 -5
- package/app/globals.css +0 -54
- package/app/invite/[token]/page.tsx +0 -52
- package/app/layout.tsx +0 -90
- package/app/mcp/route.tsx +0 -430
- package/app/opengraph-image.tsx +0 -120
- package/app/page.tsx +0 -398
- package/app/privacy/page.tsx +0 -69
- package/app/robots.tsx +0 -25
- package/app/sitemap.tsx +0 -36
- package/app/terms/page.tsx +0 -69
- package/app/upgrade/page.tsx +0 -75
- package/auth.config.ts +0 -33
- package/auth.ts +0 -79
- package/components/auth/login-form.tsx +0 -302
- package/components/auth/password-checklist.tsx +0 -31
- package/components/auth/password-input.tsx +0 -36
- package/components/auth/switch-account-button.test.tsx +0 -22
- package/components/auth/switch-account-button.tsx +0 -19
- package/components/auth/two-factor-input.tsx +0 -116
- package/components/billing/billing-dashboard.tsx +0 -265
- package/components/billing/card-form.tsx +0 -210
- package/components/billing/claim-account-form.tsx +0 -99
- package/components/branding/app-logo.test.tsx +0 -20
- package/components/branding/app-logo.tsx +0 -25
- package/components/calendar/calendar-agenda.tsx +0 -150
- package/components/calendar/calendar-drag.test.tsx +0 -177
- package/components/calendar/calendar-grid.tsx +0 -357
- package/components/calendar/calendar-hooks.test.tsx +0 -27
- package/components/calendar/calendar-hooks.ts +0 -351
- package/components/calendar/calendar-toolbar.test.tsx +0 -68
- package/components/calendar/calendar-toolbar.tsx +0 -291
- package/components/calendar/calendar-types.ts +0 -148
- package/components/calendar/calendar-view.test.tsx +0 -295
- package/components/calendar/calendar-view.tsx +0 -307
- package/components/calendar/day-detail-popover.tsx +0 -174
- package/components/calendar/task-chip.tsx +0 -86
- package/components/command/command-palette.test.tsx +0 -33
- package/components/command/command-palette.tsx +0 -310
- package/components/download-cta.tsx +0 -87
- package/components/feedback/feedback-popup.tsx +0 -207
- package/components/graph/graph-draw.ts +0 -337
- package/components/graph/graph-overlays.tsx +0 -160
- package/components/graph/graph-page.test.tsx +0 -131
- package/components/graph/graph-page.tsx +0 -263
- package/components/graph/graph-types.ts +0 -47
- package/components/graph/graph-view.tsx +0 -322
- package/components/guide/guide-view.tsx +0 -522
- package/components/kanban/kanban-board.test.tsx +0 -128
- package/components/kanban/kanban-board.tsx +0 -361
- package/components/kanban/kanban-card-menu.tsx +0 -102
- package/components/kanban/kanban-card.tsx +0 -227
- package/components/kanban/kanban-column.tsx +0 -49
- package/components/kanban/kanban-status-context.tsx +0 -28
- package/components/landing/calendar-sandbox.test.tsx +0 -15
- package/components/landing/calendar-sandbox.tsx +0 -107
- package/components/landing/graph-sandbox.test.tsx +0 -27
- package/components/landing/graph-sandbox.tsx +0 -80
- package/components/landing/kanban-sandbox.test.tsx +0 -24
- package/components/landing/kanban-sandbox.tsx +0 -101
- package/components/landing/landing-showcase.test.tsx +0 -21
- package/components/landing/landing-showcase.tsx +0 -54
- package/components/landing/list-sandbox.tsx +0 -86
- package/components/landing/mock-workspace.ts +0 -168
- package/components/landing/notes-sandbox.test.tsx +0 -14
- package/components/landing/notes-sandbox.tsx +0 -88
- package/components/layout/app-shell.tsx +0 -83
- package/components/layout/backup-scheduler.tsx +0 -122
- package/components/layout/bottom-nav.tsx +0 -43
- package/components/layout/icon-bar.test.tsx +0 -29
- package/components/layout/icon-bar.tsx +0 -118
- package/components/layout/mobile-top-bar.tsx +0 -68
- package/components/layout/notes-panel-folder.tsx +0 -127
- package/components/layout/notes-panel-note-item.tsx +0 -140
- package/components/layout/notes-panel-task-tab.tsx +0 -63
- package/components/layout/notes-panel-types.ts +0 -44
- package/components/layout/notes-panel.tsx +0 -476
- package/components/layout/notification-bell.tsx +0 -251
- package/components/layout/paywall-screen.tsx +0 -41
- package/components/layout/pro-banner.tsx +0 -76
- package/components/layout/sw-register.tsx +0 -27
- package/components/layout/workspace-switcher.tsx +0 -90
- package/components/notes/mobile-bottom-sheet.tsx +0 -99
- package/components/notes/note-editor-context-menu.tsx +0 -47
- package/components/notes/note-editor-dom.ts +0 -33
- package/components/notes/note-editor-dropdowns.tsx +0 -484
- package/components/notes/note-editor-hooks.ts +0 -692
- package/components/notes/note-editor-keyboard.ts +0 -305
- package/components/notes/note-editor-overlay.tsx +0 -90
- package/components/notes/note-editor.test.tsx +0 -372
- package/components/notes/note-editor.tsx +0 -662
- package/components/notes/note-preview-pane.tsx +0 -156
- package/components/notes/note-tabs.tsx +0 -120
- package/components/notes/note-types.tsx +0 -157
- package/components/settings/accept-invite.tsx +0 -108
- package/components/settings/agent-token-settings.tsx +0 -369
- package/components/settings/backup-restore-settings.test.tsx +0 -25
- package/components/settings/backup-restore-settings.tsx +0 -327
- package/components/settings/calendar-feeds-settings.tsx +0 -489
- package/components/settings/calendar-general-settings.tsx +0 -174
- package/components/settings/confirm-danger-action.test.tsx +0 -215
- package/components/settings/confirm-danger-action.tsx +0 -65
- package/components/settings/security-settings.tsx +0 -252
- package/components/settings/settings-guidance.test.tsx +0 -98
- package/components/settings/team-settings.tsx +0 -319
- package/components/settings/two-factor-auth.tsx +0 -296
- package/components/settings/workspace-settings-client.tsx +0 -363
- package/components/settings/workspace-settings-form.tsx +0 -73
- package/components/sync/conflict-viewer.tsx +0 -247
- package/components/sync/sync-indicator.tsx +0 -171
- package/components/tasks/snippet-thread.tsx +0 -119
- package/components/tasks/status-dot.tsx +0 -47
- package/components/tasks/task-badge.tsx +0 -43
- package/components/tasks/task-detail.test.tsx +0 -187
- package/components/tasks/task-detail.tsx +0 -458
- package/components/tasks/task-list-filters.test.tsx +0 -75
- package/components/tasks/task-list-filters.tsx +0 -163
- package/components/tasks/task-list-types.ts +0 -20
- package/components/tasks/task-list.test.tsx +0 -175
- package/components/tasks/task-list.tsx +0 -481
- package/components/tasks/task-row.tsx +0 -85
- package/components/tasks/task-table-row.tsx +0 -259
- package/components/ui/skeleton.tsx +0 -3
- package/components/ui/toast.test.tsx +0 -42
- package/components/ui/toast.tsx +0 -70
- package/electron/main.ts +0 -251
- package/electron/preload.ts +0 -56
- package/instrumentation.tsx +0 -23
- package/lib/api-error.ts +0 -50
- package/lib/backup/backup-runner.test.ts +0 -32
- package/lib/backup/backup-runner.ts +0 -19
- package/lib/backup/backup-schedule.test.ts +0 -23
- package/lib/backup/backup-schedule.ts +0 -55
- package/lib/backup/backup-settings.test.ts +0 -30
- package/lib/backup/backup-settings.ts +0 -27
- package/lib/backup/export-notes-zip.test.ts +0 -26
- package/lib/backup/export-notes-zip.ts +0 -82
- package/lib/backup/export-workspace-backup.test.ts +0 -17
- package/lib/backup/export-workspace-backup.ts +0 -77
- package/lib/backup/restore-workspace-from-export.test.ts +0 -18
- package/lib/backup/restore-workspace-from-export.ts +0 -183
- package/lib/backup/types.ts +0 -14
- package/lib/brand-icons.ts +0 -1
- package/lib/calendar-feed-crypto.ts +0 -38
- package/lib/calendar-feed.ts +0 -239
- package/lib/client/online-status.ts +0 -47
- package/lib/conflict-resolver.test.ts +0 -57
- package/lib/conflict-resolver.ts +0 -240
- package/lib/db-init.ts +0 -79
- package/lib/email.ts +0 -159
- package/lib/encryption.test.ts +0 -41
- package/lib/encryption.ts +0 -98
- package/lib/extract-snippet.test.ts +0 -123
- package/lib/extract-snippet.ts +0 -69
- package/lib/kanban-status.ts +0 -55
- package/lib/license.ts +0 -21
- package/lib/limits.ts +0 -31
- package/lib/mcp-auth.test.ts +0 -58
- package/lib/mcp-auth.ts +0 -65
- package/lib/mcp-contract.test.ts +0 -25
- package/lib/mcp-contract.ts +0 -210
- package/lib/mcp-handler.ts +0 -31
- package/lib/mcp-url.test.ts +0 -12
- package/lib/mcp-url.ts +0 -7
- package/lib/mentions.test.ts +0 -45
- package/lib/mentions.ts +0 -73
- package/lib/note-crypto.ts +0 -108
- package/lib/note-sync.ts +0 -201
- package/lib/note-title.ts +0 -93
- package/lib/prisma.ts +0 -193
- package/lib/pro-flush.ts +0 -292
- package/lib/rate-limit.ts +0 -57
- package/lib/stripe.ts +0 -38
- package/lib/sync-worker.ts +0 -388
- package/lib/task-parser.test.ts +0 -91
- package/lib/task-parser.ts +0 -81
- package/lib/task-utils.ts +0 -52
- package/lib/use-is-electron.ts +0 -19
- package/lib/use-is-mobile.ts +0 -22
- package/lib/validation/calendar-feed.ts +0 -31
- package/lib/validation/note.ts +0 -27
- package/lib/validation/task.ts +0 -26
- package/lib/view-preferences.test.ts +0 -54
- package/lib/view-preferences.ts +0 -28
- package/lib/workspace.ts +0 -66
- package/next.config.ts +0 -21
- package/postcss.config.mjs +0 -7
- package/prisma/migrations/20260519021916_init/migration.sql +0 -388
- package/prisma/migrations/20260519061113_drop_sync_password/migration.sql +0 -8
- package/prisma/migrations/20260520065016_add_task_start_date/migration.sql +0 -2
- package/prisma/migrations/20260529010600_remove_encryption_fields/migration.sql +0 -12
- package/prisma/migrations/20260529020000_restore_encryption_salt/migration.sql +0 -3
- package/prisma/migrations/20260529030000_add_folders/migration.sql +0 -17
- package/prisma/migrations/20260605000000_deferred_fixes/migration.sql +0 -31
- package/prisma/migrations/20260605020806_add_pending_sync_to_note_and_task/migration.sql +0 -5
- package/prisma/migrations/20260605063634_add_stripe_webhook_event_sync_lock/migration.sql +0 -14
- package/prisma/migrations/20260605100000_add_prod_indexes/migration.sql +0 -26
- package/prisma/migrations/20260608081404_add_kanban_statuses/migration.sql +0 -23
- package/prisma/migrations/20260611032723_add_calendar_feeds/migration.sql +0 -43
- package/prisma/migrations/20260611040000_add_calendar_feed_color/migration.sql +0 -2
- package/prisma/migrations/20260611050000_add_task_priority/migration.sql +0 -14
- package/prisma/migrations/20260612060000_add_critical_priority/migration.sql +0 -2
- package/prisma/migrations/20260613090000_add_backup_settings/migration.sql +0 -25
- package/prisma/migrations/20260614160000_add_feedback/migration.sql +0 -20
- package/prisma/migrations/20260614210000_add_2fa/migration.sql +0 -4
- package/prisma/migrations/migration_lock.toml +0 -3
- package/prisma/schema.prisma +0 -457
- package/public/Logo_icon.svg +0 -1
- package/public/file.svg +0 -1
- package/public/globe.svg +0 -1
- package/public/icon-192.png +0 -0
- package/public/icon-512.png +0 -0
- package/public/icon.svg +0 -4
- package/public/icon_dark.svg +0 -1
- package/public/knotpad_icon.svg +0 -1
- package/public/knotpad_logo_full.svg +0 -1
- package/public/manifest.json +0 -14
- package/public/next.svg +0 -1
- package/public/sw.js +0 -137
- package/public/vercel.svg +0 -1
- package/public/window.svg +0 -1
- package/tsconfig.json +0 -35
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "vitest";
|
|
2
|
-
import {
|
|
3
|
-
cleanBackupContent,
|
|
4
|
-
getBackupFilename,
|
|
5
|
-
} from "@/lib/backup/export-workspace-backup";
|
|
6
|
-
|
|
7
|
-
describe("workspace backup export", () => {
|
|
8
|
-
it("removes internal task comments from exported note content", () => {
|
|
9
|
-
const input = "Hello<!--task::OPEN-->\nWorld";
|
|
10
|
-
expect(cleanBackupContent(input)).toBe("Hello\nWorld");
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
it("builds a timestamped backup filename", () => {
|
|
14
|
-
const filename = getBackupFilename(new Date("2026-06-13T09:15:00.000Z"));
|
|
15
|
-
expect(filename).toBe("brief-backup-2026-06-13.json");
|
|
16
|
-
});
|
|
17
|
-
});
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import { prisma } from "@/lib/prisma";
|
|
2
|
-
import { decryptContent } from "@/lib/note-crypto";
|
|
3
|
-
|
|
4
|
-
const BADGE_COMMENT_RE = /\s*<!--task::[^>]*-->/g;
|
|
5
|
-
|
|
6
|
-
export function cleanBackupContent(content: string): string {
|
|
7
|
-
return content
|
|
8
|
-
.split("\n")
|
|
9
|
-
.map((line) => line.replace(BADGE_COMMENT_RE, ""))
|
|
10
|
-
.join("\n");
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export function getBackupFilename(now = new Date()): string {
|
|
14
|
-
return `brief-backup-${now.toISOString().split("T")[0]}.json`;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export async function buildWorkspaceBackup(
|
|
18
|
-
workspaceId: string,
|
|
19
|
-
workspaceName: string,
|
|
20
|
-
workspaceSlug: string
|
|
21
|
-
) {
|
|
22
|
-
const notes = await prisma.note.findMany({
|
|
23
|
-
where: { workspaceId },
|
|
24
|
-
orderBy: { createdAt: "asc" },
|
|
25
|
-
include: {
|
|
26
|
-
tasks: {
|
|
27
|
-
orderBy: { createdAt: "asc" },
|
|
28
|
-
select: {
|
|
29
|
-
id: true,
|
|
30
|
-
title: true,
|
|
31
|
-
status: true,
|
|
32
|
-
assigneeType: true,
|
|
33
|
-
fileRefs: true,
|
|
34
|
-
dueDate: true,
|
|
35
|
-
createdAt: true,
|
|
36
|
-
updatedAt: true,
|
|
37
|
-
},
|
|
38
|
-
},
|
|
39
|
-
},
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
const decryptedNotes = await Promise.all(
|
|
43
|
-
notes.map(async (note) => ({
|
|
44
|
-
...note,
|
|
45
|
-
content: cleanBackupContent(await decryptContent(note.content, workspaceId)),
|
|
46
|
-
}))
|
|
47
|
-
);
|
|
48
|
-
|
|
49
|
-
return {
|
|
50
|
-
filename: getBackupFilename(),
|
|
51
|
-
payload: {
|
|
52
|
-
version: 1,
|
|
53
|
-
exportedAt: new Date().toISOString(),
|
|
54
|
-
workspace: {
|
|
55
|
-
name: workspaceName,
|
|
56
|
-
slug: workspaceSlug,
|
|
57
|
-
},
|
|
58
|
-
notes: decryptedNotes.map((note) => ({
|
|
59
|
-
id: note.id,
|
|
60
|
-
title: note.title,
|
|
61
|
-
content: note.content,
|
|
62
|
-
createdAt: note.createdAt.toISOString(),
|
|
63
|
-
updatedAt: note.updatedAt.toISOString(),
|
|
64
|
-
tasks: note.tasks.map((task) => ({
|
|
65
|
-
id: task.id,
|
|
66
|
-
title: task.title,
|
|
67
|
-
status: task.status,
|
|
68
|
-
assigneeType: task.assigneeType,
|
|
69
|
-
fileRefs: task.fileRefs,
|
|
70
|
-
dueDate: task.dueDate?.toISOString() ?? null,
|
|
71
|
-
createdAt: task.createdAt.toISOString(),
|
|
72
|
-
updatedAt: task.updatedAt.toISOString(),
|
|
73
|
-
})),
|
|
74
|
-
})),
|
|
75
|
-
},
|
|
76
|
-
};
|
|
77
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "vitest";
|
|
2
|
-
import { planRestoreChanges } from "@/lib/backup/restore-workspace-from-export";
|
|
3
|
-
|
|
4
|
-
describe("planRestoreChanges", () => {
|
|
5
|
-
it("tombstones records missing from the imported backup and clears tombstones for restored ids", () => {
|
|
6
|
-
const plan = planRestoreChanges({
|
|
7
|
-
existingNoteIds: ["old_note", "keep_note"],
|
|
8
|
-
existingTaskIds: ["old_task", "keep_task"],
|
|
9
|
-
importedNoteIds: ["keep_note", "new_note"],
|
|
10
|
-
importedTaskIds: ["keep_task", "new_task"],
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
expect(plan.noteIdsToTombstone).toEqual(["old_note"]);
|
|
14
|
-
expect(plan.taskIdsToTombstone).toEqual(["old_task"]);
|
|
15
|
-
expect(plan.noteIdsToClearTombstones).toEqual(["keep_note", "new_note"]);
|
|
16
|
-
expect(plan.taskIdsToClearTombstones).toEqual(["keep_task", "new_task"]);
|
|
17
|
-
});
|
|
18
|
-
});
|
|
@@ -1,183 +0,0 @@
|
|
|
1
|
-
import { getCloudPrisma, prisma } from "@/lib/prisma";
|
|
2
|
-
import { writeTombstone } from "@/lib/conflict-resolver";
|
|
3
|
-
import { saveSnapshots } from "@/lib/note-sync";
|
|
4
|
-
|
|
5
|
-
export type BriefExport = {
|
|
6
|
-
version: number;
|
|
7
|
-
exportedAt: string;
|
|
8
|
-
workspace: { name: string; slug: string };
|
|
9
|
-
notes: Array<{
|
|
10
|
-
id: string;
|
|
11
|
-
title: string;
|
|
12
|
-
content: string;
|
|
13
|
-
createdAt: string;
|
|
14
|
-
updatedAt: string;
|
|
15
|
-
tasks: Array<{
|
|
16
|
-
id: string;
|
|
17
|
-
title: string;
|
|
18
|
-
status: string;
|
|
19
|
-
assigneeType: string;
|
|
20
|
-
fileRefs: string[];
|
|
21
|
-
dueDate: string | null;
|
|
22
|
-
createdAt: string;
|
|
23
|
-
updatedAt: string;
|
|
24
|
-
}>;
|
|
25
|
-
}>;
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
export function planRestoreChanges(input: {
|
|
29
|
-
existingNoteIds: string[];
|
|
30
|
-
existingTaskIds: string[];
|
|
31
|
-
importedNoteIds: string[];
|
|
32
|
-
importedTaskIds: string[];
|
|
33
|
-
}) {
|
|
34
|
-
const importedNotes = new Set(input.importedNoteIds);
|
|
35
|
-
const importedTasks = new Set(input.importedTaskIds);
|
|
36
|
-
|
|
37
|
-
return {
|
|
38
|
-
noteIdsToTombstone: input.existingNoteIds.filter((id) => !importedNotes.has(id)),
|
|
39
|
-
taskIdsToTombstone: input.existingTaskIds.filter((id) => !importedTasks.has(id)),
|
|
40
|
-
noteIdsToClearTombstones: input.importedNoteIds,
|
|
41
|
-
taskIdsToClearTombstones: input.importedTaskIds,
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export async function restoreWorkspaceFromExport(params: {
|
|
46
|
-
workspaceId: string;
|
|
47
|
-
exportData: BriefExport;
|
|
48
|
-
pushToCloud: boolean;
|
|
49
|
-
}) {
|
|
50
|
-
const cloudPrisma = getCloudPrisma();
|
|
51
|
-
if (params.pushToCloud && !cloudPrisma) {
|
|
52
|
-
throw new Error("Cloud restore is not configured for this workspace.");
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
const [existingNotes, existingTasks] = await Promise.all([
|
|
56
|
-
prisma.note.findMany({
|
|
57
|
-
where: { workspaceId: params.workspaceId },
|
|
58
|
-
select: { id: true },
|
|
59
|
-
}),
|
|
60
|
-
prisma.task.findMany({
|
|
61
|
-
where: { workspaceId: params.workspaceId },
|
|
62
|
-
select: { id: true },
|
|
63
|
-
}),
|
|
64
|
-
]);
|
|
65
|
-
|
|
66
|
-
const importedNoteIds = params.exportData.notes.map((note) => note.id);
|
|
67
|
-
const importedTaskIds = params.exportData.notes.flatMap((note) =>
|
|
68
|
-
note.tasks.map((task) => task.id)
|
|
69
|
-
);
|
|
70
|
-
|
|
71
|
-
const plan = planRestoreChanges({
|
|
72
|
-
existingNoteIds: existingNotes.map((note) => note.id),
|
|
73
|
-
existingTaskIds: existingTasks.map((task) => task.id),
|
|
74
|
-
importedNoteIds,
|
|
75
|
-
importedTaskIds,
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
await Promise.all([
|
|
79
|
-
...plan.noteIdsToTombstone.map((id) =>
|
|
80
|
-
writeTombstone(params.workspaceId, "note", id)
|
|
81
|
-
),
|
|
82
|
-
...plan.taskIdsToTombstone.map((id) =>
|
|
83
|
-
writeTombstone(params.workspaceId, "task", id)
|
|
84
|
-
),
|
|
85
|
-
]);
|
|
86
|
-
|
|
87
|
-
const noteRows = params.exportData.notes.map((note) => ({
|
|
88
|
-
id: note.id,
|
|
89
|
-
title: note.title,
|
|
90
|
-
content: note.content,
|
|
91
|
-
workspaceId: params.workspaceId,
|
|
92
|
-
pendingSync: false,
|
|
93
|
-
createdAt: new Date(note.createdAt),
|
|
94
|
-
updatedAt: new Date(note.updatedAt),
|
|
95
|
-
}));
|
|
96
|
-
|
|
97
|
-
const taskRows = params.exportData.notes.flatMap((note) =>
|
|
98
|
-
note.tasks.map((task) => ({
|
|
99
|
-
id: task.id,
|
|
100
|
-
title: task.title,
|
|
101
|
-
status: task.status as never,
|
|
102
|
-
noteId: note.id,
|
|
103
|
-
workspaceId: params.workspaceId,
|
|
104
|
-
assigneeType: task.assigneeType as never,
|
|
105
|
-
fileRefs: task.fileRefs,
|
|
106
|
-
dueDate: task.dueDate ? new Date(task.dueDate) : null,
|
|
107
|
-
pendingSync: false,
|
|
108
|
-
createdAt: new Date(task.createdAt),
|
|
109
|
-
updatedAt: new Date(task.updatedAt),
|
|
110
|
-
}))
|
|
111
|
-
);
|
|
112
|
-
|
|
113
|
-
const importedEntityIds = [
|
|
114
|
-
...plan.noteIdsToClearTombstones,
|
|
115
|
-
...plan.taskIdsToClearTombstones,
|
|
116
|
-
];
|
|
117
|
-
|
|
118
|
-
const restoreLocal = prisma.$transaction(async (tx) => {
|
|
119
|
-
await tx.task.deleteMany({ where: { workspaceId: params.workspaceId } });
|
|
120
|
-
await tx.note.deleteMany({ where: { workspaceId: params.workspaceId } });
|
|
121
|
-
await tx.conflictLog.deleteMany({ where: { workspaceId: params.workspaceId } });
|
|
122
|
-
await tx.tombstone.deleteMany({
|
|
123
|
-
where: {
|
|
124
|
-
workspaceId: params.workspaceId,
|
|
125
|
-
entityId: { in: importedEntityIds },
|
|
126
|
-
},
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
if (noteRows.length > 0) {
|
|
130
|
-
await tx.note.createMany({ data: noteRows });
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
if (taskRows.length > 0) {
|
|
134
|
-
await tx.task.createMany({ data: taskRows });
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
await tx.syncState.upsert({
|
|
138
|
-
where: { workspaceId: params.workspaceId },
|
|
139
|
-
update: { lastSyncedAt: new Date() },
|
|
140
|
-
create: { workspaceId: params.workspaceId, lastSyncedAt: new Date() },
|
|
141
|
-
});
|
|
142
|
-
});
|
|
143
|
-
|
|
144
|
-
const restoreCloud =
|
|
145
|
-
params.pushToCloud && cloudPrisma
|
|
146
|
-
? cloudPrisma.$transaction(async (tx) => {
|
|
147
|
-
await tx.task.deleteMany({ where: { workspaceId: params.workspaceId } });
|
|
148
|
-
await tx.note.deleteMany({ where: { workspaceId: params.workspaceId } });
|
|
149
|
-
await tx.conflictLog.deleteMany({ where: { workspaceId: params.workspaceId } });
|
|
150
|
-
await tx.tombstone.deleteMany({
|
|
151
|
-
where: {
|
|
152
|
-
workspaceId: params.workspaceId,
|
|
153
|
-
entityId: { in: importedEntityIds },
|
|
154
|
-
},
|
|
155
|
-
});
|
|
156
|
-
|
|
157
|
-
if (noteRows.length > 0) {
|
|
158
|
-
await tx.note.createMany({ data: noteRows });
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
if (taskRows.length > 0) {
|
|
162
|
-
await tx.task.createMany({ data: taskRows });
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
await tx.syncState.upsert({
|
|
166
|
-
where: { workspaceId: params.workspaceId },
|
|
167
|
-
update: { lastSyncedAt: new Date() },
|
|
168
|
-
create: { workspaceId: params.workspaceId, lastSyncedAt: new Date() },
|
|
169
|
-
});
|
|
170
|
-
})
|
|
171
|
-
: Promise.resolve();
|
|
172
|
-
|
|
173
|
-
await Promise.all([restoreLocal, restoreCloud]);
|
|
174
|
-
|
|
175
|
-
const snapshots = Object.fromEntries(
|
|
176
|
-
params.exportData.notes.map((note) => [note.id, note.content])
|
|
177
|
-
);
|
|
178
|
-
|
|
179
|
-
await saveSnapshots(params.workspaceId, snapshots, undefined, prisma);
|
|
180
|
-
if (params.pushToCloud && cloudPrisma) {
|
|
181
|
-
await saveSnapshots(params.workspaceId, snapshots, undefined, cloudPrisma);
|
|
182
|
-
}
|
|
183
|
-
}
|
package/lib/backup/types.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
export type BackupCadence = "DAILY" | "WEEKLY" | "MONTHLY";
|
|
2
|
-
|
|
3
|
-
export type BackupRunStatus = "idle" | "success" | "error" | "running";
|
|
4
|
-
|
|
5
|
-
export type BackupSettingsRecord = {
|
|
6
|
-
workspaceId: string;
|
|
7
|
-
scheduleEnabled: boolean;
|
|
8
|
-
scheduleCadence: BackupCadence;
|
|
9
|
-
destinationPath: string | null;
|
|
10
|
-
includeMarkdownZip: boolean;
|
|
11
|
-
lastBackupAt: Date | null;
|
|
12
|
-
lastBackupStatus: BackupRunStatus;
|
|
13
|
-
lastBackupError: string | null;
|
|
14
|
-
};
|
package/lib/brand-icons.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export const WEB_ICON_PATH = "/icon_dark.svg";
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Encryption-at-rest for CalendarFeed subscription URLs.
|
|
3
|
-
*
|
|
4
|
-
* The .ics URL is effectively a credential — anyone with it can read the
|
|
5
|
-
* user's calendar — so it's encrypted with the same AES-256-GCM scheme as
|
|
6
|
-
* note content (lib/encryption.ts), but with a per-row salt stored on the
|
|
7
|
-
* CalendarFeed itself (CalendarFeed.urlSalt) rather than a per-workspace salt.
|
|
8
|
-
*
|
|
9
|
-
* In local-only mode (no cloud sync), URLs are stored as plaintext since
|
|
10
|
-
* the data never leaves the user's device.
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
import { encryptNote, decryptNote, isEncrypted } from "@/lib/encryption";
|
|
14
|
-
|
|
15
|
-
function isCloudEnabled(): boolean {
|
|
16
|
-
return process.env.IS_CLOUD === "true" || !!process.env.CLOUD_DATABASE_URL;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
function getPepper(): string {
|
|
20
|
-
const pepper = process.env.ENCRYPTION_PEPPER;
|
|
21
|
-
if (!pepper) {
|
|
22
|
-
throw new Error(
|
|
23
|
-
"[Brief] ENCRYPTION_PEPPER env var is required to encrypt calendar feed URLs at rest. " +
|
|
24
|
-
"Generate one with: openssl rand -base64 32"
|
|
25
|
-
);
|
|
26
|
-
}
|
|
27
|
-
return pepper;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export async function encryptFeedUrl(url: string, salt: string): Promise<string> {
|
|
31
|
-
if (!isCloudEnabled()) return url; // local-only: store plaintext
|
|
32
|
-
return encryptNote(url, getPepper(), salt);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export async function decryptFeedUrl(encrypted: string, salt: string): Promise<string> {
|
|
36
|
-
if (!isEncrypted(encrypted)) return encrypted; // plaintext / local-only safety
|
|
37
|
-
return decryptNote(encrypted, getPepper(), salt);
|
|
38
|
-
}
|
package/lib/calendar-feed.ts
DELETED
|
@@ -1,239 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Core sync logic for read-only calendar feed import.
|
|
3
|
-
*
|
|
4
|
-
* Fetches a user's .ics subscription URL, parses VEVENTs (expanding RRULE
|
|
5
|
-
* recurrences within a fixed past/future window), and caches the result as
|
|
6
|
-
* CalendarFeedEvent rows. Never throws — failures are recorded on
|
|
7
|
-
* CalendarFeed.lastError so the cron loop / on-demand sync can report
|
|
8
|
-
* cleanly without surfacing internals (e.g. the URL) to the client.
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
// Dynamic import: node-ical pulls in temporal-polyfill which uses BigInt at
|
|
12
|
-
// module-evaluation time. A static import breaks Turbopack's server bundle
|
|
13
|
-
// ("s.BigInt is not a function") during `next build` page-data collection.
|
|
14
|
-
import type * as icalNS from "node-ical";
|
|
15
|
-
import { prisma } from "@/lib/prisma";
|
|
16
|
-
import { decryptFeedUrl } from "@/lib/calendar-feed-crypto";
|
|
17
|
-
import {
|
|
18
|
-
ICS_FETCH_TIMEOUT_MS,
|
|
19
|
-
ICS_MAX_BYTES,
|
|
20
|
-
CALENDAR_FEED_PAST_DAYS,
|
|
21
|
-
CALENDAR_FEED_FUTURE_DAYS,
|
|
22
|
-
} from "@/lib/limits";
|
|
23
|
-
|
|
24
|
-
function summaryText(v: icalNS.ParameterValue<string> | undefined): string {
|
|
25
|
-
if (!v) return "Untitled event";
|
|
26
|
-
const text = typeof v === "string" ? v : v.val;
|
|
27
|
-
return text || "Untitled event";
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
function isDateExcluded(exdate: Date | Date[] | Record<string, Date> | undefined, date: Date): boolean {
|
|
31
|
-
if (!exdate) return false;
|
|
32
|
-
const targetTime = date.getTime();
|
|
33
|
-
if (exdate instanceof Date) {
|
|
34
|
-
return exdate.getTime() === targetTime;
|
|
35
|
-
}
|
|
36
|
-
if (Array.isArray(exdate)) {
|
|
37
|
-
return exdate.some((d) => d instanceof Date && d.getTime() === targetTime);
|
|
38
|
-
}
|
|
39
|
-
if (typeof exdate === "object") {
|
|
40
|
-
return Object.values(exdate).some((d) => d instanceof Date && d.getTime() === targetTime);
|
|
41
|
-
}
|
|
42
|
-
return false;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
type EventRow = { uid: string; title: string; start: Date; end: Date; allDay: boolean };
|
|
46
|
-
|
|
47
|
-
export async function fetchAndCacheFeed(feedId: string): Promise<{ ok: boolean; error?: string }> {
|
|
48
|
-
const feed = await prisma.calendarFeed.findUnique({ where: { id: feedId } });
|
|
49
|
-
if (!feed) return { ok: false, error: "Feed not found" };
|
|
50
|
-
|
|
51
|
-
let url: string;
|
|
52
|
-
try {
|
|
53
|
-
url = await decryptFeedUrl(feed.encryptedUrl, feed.urlSalt);
|
|
54
|
-
} catch {
|
|
55
|
-
await prisma.calendarFeed.update({
|
|
56
|
-
where: { id: feedId },
|
|
57
|
-
data: { lastError: "Failed to decrypt feed URL" },
|
|
58
|
-
});
|
|
59
|
-
return { ok: false, error: "Failed to decrypt feed URL" };
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
let text: string;
|
|
63
|
-
try {
|
|
64
|
-
text = await fetchIcsBody(url);
|
|
65
|
-
} catch (err) {
|
|
66
|
-
const message =
|
|
67
|
-
err instanceof Error && err.name === "AbortError"
|
|
68
|
-
? "Feed request timed out"
|
|
69
|
-
: err instanceof Error
|
|
70
|
-
? err.message
|
|
71
|
-
: "Failed to fetch feed";
|
|
72
|
-
await prisma.calendarFeed.update({
|
|
73
|
-
where: { id: feedId },
|
|
74
|
-
data: { lastError: message.slice(0, 200) },
|
|
75
|
-
});
|
|
76
|
-
return { ok: false, error: message };
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
const ical: typeof icalNS = await import("node-ical");
|
|
80
|
-
|
|
81
|
-
let parsed: icalNS.CalendarResponse;
|
|
82
|
-
try {
|
|
83
|
-
parsed = ical.sync.parseICS(text);
|
|
84
|
-
} catch {
|
|
85
|
-
await prisma.calendarFeed.update({
|
|
86
|
-
where: { id: feedId },
|
|
87
|
-
data: { lastError: "Could not parse calendar data" },
|
|
88
|
-
});
|
|
89
|
-
return { ok: false, error: "Could not parse calendar data" };
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
const now = new Date();
|
|
93
|
-
const windowStart = new Date(now.getTime() - CALENDAR_FEED_PAST_DAYS * 86_400_000);
|
|
94
|
-
const windowEnd = new Date(now.getTime() + CALENDAR_FEED_FUTURE_DAYS * 86_400_000);
|
|
95
|
-
|
|
96
|
-
const rows: EventRow[] = [];
|
|
97
|
-
const seenUids = new Set<string>();
|
|
98
|
-
|
|
99
|
-
// Pre-pass: collect all overridden occurrence start times by master event uid
|
|
100
|
-
const overridesByUid = new Map<string, Set<number>>();
|
|
101
|
-
for (const item of Object.values(parsed)) {
|
|
102
|
-
if (!item || typeof item !== "object" || (item as { type?: string }).type !== "VEVENT") continue;
|
|
103
|
-
const event = item as icalNS.VEvent;
|
|
104
|
-
if (event.uid && event.recurrenceid) {
|
|
105
|
-
const recIdDate = event.recurrenceid instanceof Date ? event.recurrenceid : new Date(event.recurrenceid);
|
|
106
|
-
if (!Number.isNaN(recIdDate.getTime())) {
|
|
107
|
-
if (!overridesByUid.has(event.uid)) {
|
|
108
|
-
overridesByUid.set(event.uid, new Set());
|
|
109
|
-
}
|
|
110
|
-
overridesByUid.get(event.uid)!.add(recIdDate.getTime());
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
for (const item of Object.values(parsed)) {
|
|
116
|
-
if (!item || typeof item !== "object" || (item as { type?: string }).type !== "VEVENT") continue;
|
|
117
|
-
const event = item as icalNS.VEvent;
|
|
118
|
-
|
|
119
|
-
if (event.rrule) {
|
|
120
|
-
const instances = ical.expandRecurringEvent(event, { from: windowStart, to: windowEnd });
|
|
121
|
-
for (const inst of instances) {
|
|
122
|
-
// Skip if this instance's start matches an overridden occurrence
|
|
123
|
-
if (event.uid && overridesByUid.get(event.uid)?.has(inst.start.getTime())) {
|
|
124
|
-
continue;
|
|
125
|
-
}
|
|
126
|
-
// Skip if this instance's start is excluded via EXDATE
|
|
127
|
-
if (isDateExcluded(event.exdate, inst.start)) {
|
|
128
|
-
continue;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
const uid = `${event.uid}-${inst.start.toISOString()}`;
|
|
132
|
-
if (seenUids.has(uid)) continue;
|
|
133
|
-
seenUids.add(uid);
|
|
134
|
-
|
|
135
|
-
let end = inst.end;
|
|
136
|
-
if (inst.isFullDay && end > inst.start) {
|
|
137
|
-
end = new Date(end.getTime() - 86_400_000);
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
rows.push({
|
|
141
|
-
uid,
|
|
142
|
-
title: summaryText(inst.summary),
|
|
143
|
-
start: inst.start,
|
|
144
|
-
end,
|
|
145
|
-
allDay: inst.isFullDay,
|
|
146
|
-
});
|
|
147
|
-
}
|
|
148
|
-
continue;
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
const start = event.start;
|
|
152
|
-
let end = event.end ?? event.start;
|
|
153
|
-
if (!start) continue;
|
|
154
|
-
if (end < windowStart || start > windowEnd) continue;
|
|
155
|
-
|
|
156
|
-
// Use suffix for overrides to prevent duplicate key constraint
|
|
157
|
-
const recIdDate = event.recurrenceid
|
|
158
|
-
? event.recurrenceid instanceof Date
|
|
159
|
-
? event.recurrenceid
|
|
160
|
-
: new Date(event.recurrenceid)
|
|
161
|
-
: null;
|
|
162
|
-
const uid = recIdDate ? `${event.uid}-${recIdDate.toISOString()}` : event.uid;
|
|
163
|
-
|
|
164
|
-
if (seenUids.has(uid)) continue;
|
|
165
|
-
seenUids.add(uid);
|
|
166
|
-
|
|
167
|
-
const allDay = event.datetype === "date";
|
|
168
|
-
if (allDay && end > start) {
|
|
169
|
-
end = new Date(end.getTime() - 86_400_000);
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
rows.push({ uid, title: summaryText(event.summary), start, end, allDay });
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
await prisma.$transaction(async (tx) => {
|
|
176
|
-
await tx.calendarFeedEvent.deleteMany({ where: { feedId } });
|
|
177
|
-
if (rows.length > 0) {
|
|
178
|
-
await tx.calendarFeedEvent.createMany({
|
|
179
|
-
data: rows.map((r) => ({
|
|
180
|
-
feedId,
|
|
181
|
-
uid: r.uid,
|
|
182
|
-
title: r.title,
|
|
183
|
-
start: r.start,
|
|
184
|
-
end: r.end,
|
|
185
|
-
allDay: r.allDay,
|
|
186
|
-
})),
|
|
187
|
-
});
|
|
188
|
-
}
|
|
189
|
-
await tx.calendarFeed.update({
|
|
190
|
-
where: { id: feedId },
|
|
191
|
-
data: { lastFetchedAt: new Date(), lastError: null },
|
|
192
|
-
});
|
|
193
|
-
});
|
|
194
|
-
|
|
195
|
-
return { ok: true };
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
/** Fetch the .ics body with a timeout and a hard size cap (Content-Length + streamed). */
|
|
199
|
-
async function fetchIcsBody(url: string): Promise<string> {
|
|
200
|
-
const controller = new AbortController();
|
|
201
|
-
const timeout = setTimeout(() => controller.abort(), ICS_FETCH_TIMEOUT_MS);
|
|
202
|
-
try {
|
|
203
|
-
const res = await fetch(url, {
|
|
204
|
-
signal: controller.signal,
|
|
205
|
-
headers: { Accept: "text/calendar, */*" },
|
|
206
|
-
});
|
|
207
|
-
if (!res.ok) throw new Error(`Upstream returned ${res.status}`);
|
|
208
|
-
|
|
209
|
-
const contentLength = res.headers.get("content-length");
|
|
210
|
-
if (contentLength && Number(contentLength) > ICS_MAX_BYTES) {
|
|
211
|
-
throw new Error("Feed is too large");
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
const reader = res.body?.getReader();
|
|
215
|
-
if (!reader) {
|
|
216
|
-
const body = await res.text();
|
|
217
|
-
if (Buffer.byteLength(body, "utf8") > ICS_MAX_BYTES) throw new Error("Feed is too large");
|
|
218
|
-
return body;
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
const chunks: Buffer[] = [];
|
|
222
|
-
let total = 0;
|
|
223
|
-
for (;;) {
|
|
224
|
-
const { done, value } = await reader.read();
|
|
225
|
-
if (done) break;
|
|
226
|
-
if (value) {
|
|
227
|
-
total += value.byteLength;
|
|
228
|
-
if (total > ICS_MAX_BYTES) {
|
|
229
|
-
await reader.cancel();
|
|
230
|
-
throw new Error("Feed is too large");
|
|
231
|
-
}
|
|
232
|
-
chunks.push(Buffer.from(value));
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
return Buffer.concat(chunks).toString("utf8");
|
|
236
|
-
} finally {
|
|
237
|
-
clearTimeout(timeout);
|
|
238
|
-
}
|
|
239
|
-
}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
|
|
3
|
-
import { useEffect, useState } from "react";
|
|
4
|
-
|
|
5
|
-
// Reachability probe: navigator.onLine only tells us the device has *a* network,
|
|
6
|
-
// not that our server is reachable. /api/health is a tiny always-200 endpoint we
|
|
7
|
-
// can ping to confirm the app is actually reachable.
|
|
8
|
-
export async function probeReachable(timeoutMs = 4000): Promise<boolean> {
|
|
9
|
-
if (typeof navigator !== "undefined" && navigator.onLine === false) return false;
|
|
10
|
-
try {
|
|
11
|
-
const ctrl = new AbortController();
|
|
12
|
-
const t = setTimeout(() => ctrl.abort(), timeoutMs);
|
|
13
|
-
const res = await fetch("/api/health", { cache: "no-store", signal: ctrl.signal });
|
|
14
|
-
clearTimeout(t);
|
|
15
|
-
return res.ok;
|
|
16
|
-
} catch {
|
|
17
|
-
return false;
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
// Subscribe to online/offline transitions. `onChange` is called with the new
|
|
22
|
-
// state. Uses the browser events for instant feedback (navigator.onLine).
|
|
23
|
-
export function useOnlineStatus(onChange?: (online: boolean) => void): boolean {
|
|
24
|
-
const [online, setOnline] = useState(
|
|
25
|
-
typeof navigator === "undefined" ? true : navigator.onLine
|
|
26
|
-
);
|
|
27
|
-
|
|
28
|
-
useEffect(() => {
|
|
29
|
-
function update(next: boolean) {
|
|
30
|
-
setOnline(next);
|
|
31
|
-
onChange?.(next);
|
|
32
|
-
}
|
|
33
|
-
const goOnline = () => update(true);
|
|
34
|
-
const goOffline = () => update(false);
|
|
35
|
-
window.addEventListener("online", goOnline);
|
|
36
|
-
window.addEventListener("offline", goOffline);
|
|
37
|
-
return () => {
|
|
38
|
-
window.removeEventListener("online", goOnline);
|
|
39
|
-
window.removeEventListener("offline", goOffline);
|
|
40
|
-
};
|
|
41
|
-
// onChange intentionally excluded — callers pass a stable callback or accept
|
|
42
|
-
// the latest closure is captured on mount; status value still updates via state.
|
|
43
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
44
|
-
}, []);
|
|
45
|
-
|
|
46
|
-
return online;
|
|
47
|
-
}
|