Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions frontend/app/api/drive/source/tree/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { NextRequest, NextResponse } from "next/server";
import { mockStore } from "@/lib/mocks/store";

export async function GET(request: NextRequest) {
// Check source drive connection status
if (!mockStore.isSourceConnected) {
return NextResponse.json(
{ error: "source_not_connected", message: "Please connect a Source account" },
{ status: 401 }
);
}

const searchParams = request.nextUrl.searchParams;
const folderId = searchParams.get("folderId") || undefined;

Comment on lines +13 to +15
const tree = mockStore.getSourceTree(folderId);
return NextResponse.json(tree);
}
19 changes: 19 additions & 0 deletions frontend/app/api/jobs/[id]/cancel/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { NextRequest, NextResponse } from "next/server";
import { mockStore } from "@/lib/mocks/store";

export async function POST(
request: NextRequest,
context: { params: Promise<{ id: string }> }
) {
const { id } = await context.params;
const success = mockStore.cancelJob(id);
Comment on lines +4 to +9

if (!success) {
return NextResponse.json(
{ error: "invalid_state", message: "Only running, paused, or pending jobs can be cancelled" },
{ status: 400 }
);
}

return NextResponse.json({ id, status: "cancelled" });
}
19 changes: 19 additions & 0 deletions frontend/app/api/jobs/[id]/pause/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { NextRequest, NextResponse } from "next/server";
import { mockStore } from "@/lib/mocks/store";

export async function POST(
request: NextRequest,
context: { params: Promise<{ id: string }> }
) {
const { id } = await context.params;
const success = mockStore.pauseJob(id);
Comment on lines +4 to +9

if (!success) {
return NextResponse.json(
{ error: "invalid_state", message: "Only running jobs can be paused" },
{ status: 400 }
);
}

return NextResponse.json({ id, status: "paused" });
}
19 changes: 19 additions & 0 deletions frontend/app/api/jobs/[id]/resume/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { NextRequest, NextResponse } from "next/server";
import { mockStore } from "@/lib/mocks/store";

export async function POST(
request: NextRequest,
context: { params: Promise<{ id: string }> }
) {
const { id } = await context.params;
const success = mockStore.resumeJob(id);
Comment on lines +4 to +9

if (!success) {
return NextResponse.json(
{ error: "invalid_state", message: "Only paused jobs can be resumed" },
{ status: 400 }
);
}

return NextResponse.json({ id, status: "running" });
}
19 changes: 19 additions & 0 deletions frontend/app/api/jobs/[id]/retry-failed/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { NextRequest, NextResponse } from "next/server";
import { mockStore } from "@/lib/mocks/store";

export async function POST(
request: NextRequest,
context: { params: Promise<{ id: string }> }
) {
const { id } = await context.params;
const itemsRequeued = mockStore.retryFailedJob(id);
Comment on lines +4 to +9

if (itemsRequeued === 0) {
return NextResponse.json(
{ error: "invalid_state", message: "Only completed with errors or failed jobs can be retried, and there must be failed items" },
{ status: 400 }
);
}

return NextResponse.json({ id, status: "running", itemsRequeued });
}
32 changes: 32 additions & 0 deletions frontend/app/api/jobs/[id]/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { NextRequest, NextResponse } from "next/server";
import { mockStore } from "@/lib/mocks/store";

export async function GET(
request: NextRequest,
context: { params: Promise<{ id: string }> }
) {
const { id } = await context.params;
const job = mockStore.getJob(id);
Comment on lines +4 to +9

if (!job) {
return NextResponse.json(
{ error: "job_not_found", message: "No transfer job found with the specified ID" },
{ status: 404 }
);
}

// Return full job details matching contract
return NextResponse.json({
id: job.id,
status: job.status,
transferMode: job.transferMode,
conflictPolicy: job.conflictPolicy,
totalFiles: job.totalFiles,
totalFolders: job.totalFolders,
filesCompleted: job.filesCompleted,
filesFailed: job.filesFailed,
foldersCreated: job.foldersCreated,
createdAt: job.createdAt,
updatedAt: job.updatedAt
});
}
62 changes: 62 additions & 0 deletions frontend/app/api/jobs/[id]/stream/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import { NextRequest } from "next/server";
import { mockStore } from "@/lib/mocks/store";

export async function GET(
request: NextRequest,
context: { params: Promise<{ id: string }> }
) {
const { id } = await context.params;
const job = mockStore.getJob(id);

Comment on lines +4 to +10
if (!job) {
return new Response(
JSON.stringify({ error: "job_not_found", message: "No job found to stream" }),
{ status: 404, headers: { "Content-Type": "application/json" } }
);
}

const encoder = new TextEncoder();

const customStream = new ReadableStream({
start(controller) {
// Define listener to capture events from our mock store
const listener = (event: { type: string; data: string }) => {
const payload = `event: ${event.type}\ndata: ${event.data}\n\n`;
try {
controller.enqueue(encoder.encode(payload));
} catch {
// If connection closed, unsubscribe listener
mockStore.unsubscribeFromJob(id, listener);
}
};

// Subscribe to updates from our global mock database
mockStore.subscribeToJob(id, listener);

// Send initial connection event
const initialPayload = `event: progress\ndata: ${JSON.stringify({
item: "Establishing SSE connection...",
status: job.status,
filesCompleted: job.filesCompleted,
totalFiles: job.totalFiles
})}\n\n`;
controller.enqueue(encoder.encode(initialPayload));

// Handle client disconnect (aborted request)
request.signal.addEventListener("abort", () => {
mockStore.unsubscribeFromJob(id, listener);
try {
controller.close();
} catch {}
});
}
});

return new Response(customStream, {
headers: {
"Content-Type": "text/event-stream",
"Cache-Control": "no-cache",
"Connection": "keep-alive"
}
});
}
54 changes: 54 additions & 0 deletions frontend/app/api/jobs/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { NextRequest, NextResponse } from "next/server";
import { mockStore } from "@/lib/mocks/store";

export async function POST(request: NextRequest) {
try {
const body = await request.json();
const { transferMode, conflictPolicy, sourceItemIds, targetParentId } = body;

// Validate parameters
if (!transferMode || !conflictPolicy || !sourceItemIds || !targetParentId) {
return NextResponse.json(
{ error: "bad_request", message: "Missing required parameters in request body" },
{ status: 400 }
);
}

if (transferMode !== "COPY" && transferMode !== "MOVE") {
return NextResponse.json(
{ error: "invalid_mode", message: "transferMode must be COPY or MOVE" },
{ status: 400 }
);
}
Comment on lines +9 to +22

// Simulate quota check (if source items size exceeds ~6.4GB, return error 402 as in contract)
// Here we'll just succeed normally unless custom testing inputs are sent
const isQuotaError = sourceItemIds.includes("trigger-quota-error");
if (isQuotaError) {
return NextResponse.json(
{
error: "insufficient_target_quota",
requiredBytes: 6400000000,
availableBytes: 5000000000
},
{ status: 402 }
);
}

const newJob = mockStore.createJob(transferMode, conflictPolicy, sourceItemIds, targetParentId);
return NextResponse.json({
id: newJob.id,
status: newJob.status,
transferMode: newJob.transferMode,
totalFiles: newJob.totalFiles,
totalFolders: newJob.totalFolders,
createdAt: newJob.createdAt
}, { status: 201 });

} catch {
return NextResponse.json(
{ error: "invalid_json", message: "Malformed JSON request body" },
{ status: 400 }
);
}
}
22 changes: 22 additions & 0 deletions frontend/app/auth/callback/drive/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { NextRequest, NextResponse } from "next/server";
import { mockStore } from "@/lib/mocks/store";

export async function GET(request: NextRequest) {
const searchParams = request.nextUrl.searchParams;
const state = searchParams.get("state");

if (state === "source") {
mockStore.isSourceConnected = true;
} else if (state === "target") {
mockStore.isTargetConnected = true;
} else {
return NextResponse.json(
{ error: "invalid_state", message: "OAuth state verification failed" },
{ status: 400 }
);
}

// Redirect back to dashboard
const dashboardUrl = new URL("/dashboard", request.url);
return NextResponse.redirect(dashboardUrl);
}
32 changes: 32 additions & 0 deletions frontend/app/auth/callback/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { NextRequest, NextResponse } from "next/server";
import { cookies } from "next/headers";
import { mockStore } from "@/lib/mocks/store";

export async function GET(request: NextRequest) {
// Simulate receiving Google callback, verify state
const searchParams = request.nextUrl.searchParams;
const state = searchParams.get("state");

if (state !== "mock_oauth_state") {
return NextResponse.json(
{ error: "invalid_state", message: "OAuth state verification failed" },
{ status: 400 }
);
}

// Set in-memory session login flag
mockStore.isLoggedIn = true;

// Set mock httpOnly cookie (Next.js 15+ cookies() is async)
const cookieStore = await cookies();
cookieStore.set("SESSION", "mock-session-uuid-xyz123", {
httpOnly: true,
secure: process.env.NODE_ENV === "production",
path: "/",
maxAge: 3600 // 1 hour
});

// Redirect to dashboard page
const dashboardUrl = new URL("/dashboard", request.url);
return NextResponse.redirect(dashboardUrl);
}
7 changes: 7 additions & 0 deletions frontend/app/auth/connect/source/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { NextRequest, NextResponse } from "next/server";

export async function GET(request: NextRequest) {
// Redirect to callback/drive simulating permission authorization for Source drive
const targetUrl = new URL("/auth/callback/drive?state=source", request.url);
return NextResponse.redirect(targetUrl);
}
Comment on lines +3 to +7
7 changes: 7 additions & 0 deletions frontend/app/auth/login/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { NextRequest, NextResponse } from "next/server";

export async function GET(request: NextRequest) {
// Simulate redirecting to Google's OAuth consent screen
const callbackUrl = new URL("/auth/callback?code=mock_auth_code&state=mock_oauth_state", request.url);
return NextResponse.redirect(callbackUrl);
}
14 changes: 14 additions & 0 deletions frontend/app/auth/logout/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { NextResponse } from "next/server";
import { cookies } from "next/headers";
import { mockStore } from "@/lib/mocks/store";

export async function POST() {
// Reset mock state store
mockStore.reset();

// Clear mock session cookie
const cookieStore = await cookies();
cookieStore.delete("SESSION");

return NextResponse.json({ success: true });
}
Loading
Loading