- apps/web: Vite + React 19 + TanStack Router/Query + shadcn/ui - apps/api: Hono + Bun on :3001 with /api/health, /api/auth/*, /mcp stubs - apps/worker: Bun worker stub, DB connection, graceful SIGTERM - apps/web-legacy/: old Next.js code moved aside (preserved for T2-T8 reference) - Dockerfiles: api (Bun), worker (Bun), spa (multi-stage Caddy) - Caddyfile: serves dist + reverse-proxies /api/* + /mcp to api - docker-compose.yml: 4-service target (api, spa, db, worker) - packages/db/src/client.ts: shared Drizzle client for api + worker - db/client.ts: root-level alias for convenience Parent: t_e1cbd87d -> t_24c9c3fd (T0)
87 lines
2.2 KiB
TypeScript
87 lines
2.2 KiB
TypeScript
// AGENT INSTRUCTION: After every write (INSERT/UPDATE/DELETE), you MUST:
|
|
// 1. Insert activity feed entry
|
|
// 2. Call pg.notify('project_e_events', JSON.stringify({ type, action, id, workspace_id }))
|
|
// See AGENTS.md for full rules.
|
|
|
|
import { NextRequest, NextResponse } from 'next/server';
|
|
import { withAuth, createErrorResponse } from '@/lib/auth';
|
|
import { createPocketBaseClient } from '@/lib/pocketbase';
|
|
|
|
const COLLECTIONS = [
|
|
'tasks',
|
|
'habits',
|
|
'projects',
|
|
'notes',
|
|
'reports',
|
|
'milestones',
|
|
'domains',
|
|
'tags',
|
|
'agents',
|
|
'webhooks',
|
|
] as const;
|
|
|
|
type ImportCollection = (typeof COLLECTIONS)[number];
|
|
|
|
interface ImportResult {
|
|
collection: string;
|
|
imported: number;
|
|
failed: number;
|
|
errors: string[];
|
|
}
|
|
|
|
// POST /api/import — Import data from JSON
|
|
export const POST = withAuth(async (request: NextRequest, _user) => {
|
|
const body = await request.json();
|
|
|
|
if (!body || typeof body !== 'object') {
|
|
return createErrorResponse('INVALID_DATA', 'Invalid import data format', 400);
|
|
}
|
|
|
|
if (!body.version) {
|
|
return createErrorResponse('INVALID_DATA', 'Missing version field — is this a valid Project E export?', 400);
|
|
}
|
|
|
|
const pb = createPocketBaseClient();
|
|
const results: ImportResult[] = [];
|
|
let totalImported = 0;
|
|
let totalFailed = 0;
|
|
|
|
for (const collection of COLLECTIONS) {
|
|
const items = body[collection];
|
|
if (!Array.isArray(items) || items.length === 0) continue;
|
|
|
|
const result: ImportResult = {
|
|
collection,
|
|
imported: 0,
|
|
failed: 0,
|
|
errors: [],
|
|
};
|
|
|
|
for (const item of items) {
|
|
try {
|
|
// Strip id, created, updated to let PocketBase generate new ones
|
|
const { id: _id, created: _created, updated: _updated, ...data } = item;
|
|
await pb.collection(collection).create(data);
|
|
result.imported++;
|
|
} catch (error) {
|
|
result.failed++;
|
|
const message = error instanceof Error ? error.message : String(error);
|
|
if (result.errors.length < 5) {
|
|
result.errors.push(message);
|
|
}
|
|
}
|
|
}
|
|
|
|
results.push(result);
|
|
totalImported += result.imported;
|
|
totalFailed += result.failed;
|
|
}
|
|
|
|
return NextResponse.json({
|
|
success: totalFailed === 0,
|
|
imported: totalImported,
|
|
failed: totalFailed,
|
|
results,
|
|
});
|
|
});
|