first commit
This commit is contained in:
24
app/api/asc/screenshots/commit/route.ts
Normal file
24
app/api/asc/screenshots/commit/route.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { appleApiRequest } from "@/app/asc/api";
|
||||
|
||||
// PATCH /api/asc/screenshots/commit { screenshotId, md5, ... }
|
||||
// Step 3: Commit the uploaded screenshot to mark upload as complete
|
||||
export async function PATCH(req: NextRequest) {
|
||||
const body = await req.json();
|
||||
const { screenshotId } = body ?? {};
|
||||
if (!screenshotId) return NextResponse.json({ error: "screenshotId gerekli" }, { status: 400 });
|
||||
|
||||
const result = await appleApiRequest(`/appScreenshots/${screenshotId}`, {
|
||||
method: "PATCH",
|
||||
body: JSON.stringify({
|
||||
data: {
|
||||
type: "appScreenshots",
|
||||
id: screenshotId,
|
||||
attributes: { uploaded: true },
|
||||
},
|
||||
}),
|
||||
});
|
||||
|
||||
if (result.error) return NextResponse.json({ error: result.error }, { status: 502 });
|
||||
return NextResponse.json(result.data);
|
||||
}
|
||||
97
app/api/asc/screenshots/route.ts
Normal file
97
app/api/asc/screenshots/route.ts
Normal file
@@ -0,0 +1,97 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { appleApiRequest } from "@/app/asc/api";
|
||||
|
||||
const DISPLAY_TYPE = "APP_IPHONE_65"; // iPhone 6.5" (6.7" Super Retina)
|
||||
|
||||
// GET /api/asc/screenshots?localizationId=xxx
|
||||
// Returns the APP_IPHONE_65 screenshot set and its screenshots
|
||||
export async function GET(req: NextRequest) {
|
||||
const locId = req.nextUrl.searchParams.get("localizationId");
|
||||
if (!locId) return NextResponse.json({ error: "localizationId gerekli" }, { status: 400 });
|
||||
|
||||
// 1. Fetch screenshot sets for this localization
|
||||
const setsResult = await appleApiRequest(
|
||||
`/appStoreVersionLocalizations/${locId}/appScreenshotSets?filter[screenshotDisplayType]=${DISPLAY_TYPE}&include=appScreenshots&limit=1`
|
||||
);
|
||||
if (setsResult.error) return NextResponse.json({ error: setsResult.error }, { status: 502 });
|
||||
|
||||
const sets = setsResult.data?.data ?? [];
|
||||
if (sets.length === 0) {
|
||||
return NextResponse.json({ set: null, screenshots: [] });
|
||||
}
|
||||
|
||||
const set = sets[0];
|
||||
// screenshots are included via ?include=appScreenshots
|
||||
const included = setsResult.data?.included ?? [];
|
||||
const screenshots = included.filter((r: { type: string }) => r.type === "appScreenshots");
|
||||
|
||||
return NextResponse.json({ set, screenshots });
|
||||
}
|
||||
|
||||
// POST /api/asc/screenshots/reserve { localizationId, fileName, fileSize, md5 }
|
||||
// Step 1: Creates screenshot set if needed, then creates the upload reservation
|
||||
export async function POST(req: NextRequest) {
|
||||
const body = await req.json();
|
||||
const { localizationId, fileName, fileSize, md5 } = body ?? {};
|
||||
|
||||
if (!localizationId || !fileName || !fileSize)
|
||||
return NextResponse.json({ error: "localizationId, fileName, fileSize gerekli" }, { status: 400 });
|
||||
|
||||
// 1. Find or create the APP_IPHONE_65 screenshot set
|
||||
const setsResult = await appleApiRequest(
|
||||
`/appStoreVersionLocalizations/${localizationId}/appScreenshotSets?filter[screenshotDisplayType]=${DISPLAY_TYPE}&limit=1`
|
||||
);
|
||||
if (setsResult.error) return NextResponse.json({ error: setsResult.error }, { status: 502 });
|
||||
|
||||
let setId: string;
|
||||
if ((setsResult.data?.data ?? []).length > 0) {
|
||||
setId = setsResult.data.data[0].id;
|
||||
} else {
|
||||
// Create the set
|
||||
const createSet = await appleApiRequest(`/appScreenshotSets`, {
|
||||
method: "POST",
|
||||
body: JSON.stringify({
|
||||
data: {
|
||||
type: "appScreenshotSets",
|
||||
attributes: { screenshotDisplayType: DISPLAY_TYPE },
|
||||
relationships: {
|
||||
appStoreVersionLocalization: {
|
||||
data: { type: "appStoreVersionLocalizations", id: localizationId },
|
||||
},
|
||||
},
|
||||
},
|
||||
}),
|
||||
});
|
||||
if (createSet.error) return NextResponse.json({ error: createSet.error }, { status: 502 });
|
||||
setId = createSet.data.data.id;
|
||||
}
|
||||
|
||||
// 2. Create screenshot upload reservation
|
||||
const reserveResult = await appleApiRequest(`/appScreenshots`, {
|
||||
method: "POST",
|
||||
body: JSON.stringify({
|
||||
data: {
|
||||
type: "appScreenshots",
|
||||
attributes: { fileName, fileSize, ...(md5 ? { md5 } : {}) },
|
||||
relationships: {
|
||||
appScreenshotSet: {
|
||||
data: { type: "appScreenshotSets", id: setId },
|
||||
},
|
||||
},
|
||||
},
|
||||
}),
|
||||
});
|
||||
|
||||
if (reserveResult.error) return NextResponse.json({ error: reserveResult.error }, { status: 502 });
|
||||
return NextResponse.json(reserveResult.data, { status: 201 });
|
||||
}
|
||||
|
||||
// DELETE /api/asc/screenshots?screenshotId=xxx
|
||||
export async function DELETE(req: NextRequest) {
|
||||
const screenshotId = req.nextUrl.searchParams.get("screenshotId");
|
||||
if (!screenshotId) return NextResponse.json({ error: "screenshotId gerekli" }, { status: 400 });
|
||||
|
||||
const result = await appleApiRequest(`/appScreenshots/${screenshotId}`, { method: "DELETE" });
|
||||
if (result.error) return NextResponse.json({ error: result.error }, { status: 502 });
|
||||
return new NextResponse(null, { status: 204 });
|
||||
}
|
||||
Reference in New Issue
Block a user