oberconcejo/VS-CODE / .agents/skills/app-store-screenshots
app-store-screenshots
FlaggedUse when building App Store or Google Play screenshot pages, generating exportable marketing screenshots for iOS, macOS, and/or Android apps, or scaffolding a screenshot editor with Next.js. Triggers on app store, mac app store, play store, screenshots, marketing assets, html-to-image, phone mockup, mac mockup, android screenshots, feature graphic.
template/src/app/api/upload/route.ts
View on GitHubimport { createHash } from "node:crypto";
import { promises as fs } from "node:fs";
import path from "node:path";
import { NextResponse } from "next/server";
import { rejectCrossSiteWrite, sniffImageType } from "@/lib/request-guard";
import sharp from "sharp";
import { decodeBase64, readJsonBody } from "@/lib/request-body";
import { writeAsset } from "@/lib/write-asset";
export const dynamic = "force-dynamic";
const UPLOAD_DIR_REL = path.join("public", "screenshots", "uploaded");
const PUBLIC_PREFIX = "/screenshots/uploaded";
const MIME_EXT: Record<string, string> = {
"image/png": "png",
"image/jpeg": "jpg",
"image/jpg": "jpg",
};
function parseDataUrl(dataUrl: string): { mime: string; bytes: Buffer } | null {
const m = /^data:([^;]+);base64,(.+)$/.exec(dataUrl);
if (!m) return null;
const mime = m[1].toLowerCase();
const bytes = decodeBase64(m[2]);
return bytes ? { mime, bytes } : null;
}
export async function POST(req: Request) {
// This route WRITES A FILE to disk. See lib/request-guard.ts.
const blocked = rejectCrossSiteWrite(req);
if (blocked) {
return NextResponse.json({ ok: false, error: blocked.error }, { status: blocked.status });
}
const input = await readJsonBody(req, 12 * 1024 * 1024);
if (input.response) return input.response;
const body = input.value as { dataUrl?: string } | null;
if (!body?.dataUrl || typeof body.dataUrl !== "string") {
return NextResponse.json({ ok: false, error: "Missing dataUrl" }, { status: 400 });
}
const parsed = parseDataUrl(body.dataUrl);
if (!parsed) {
return NextResponse.json({ ok: false, error: "Unsupported data URL" }, { status: 400 });
}
const ext = MIME_EXT[parsed.mime];
if (!ext) {
return NextResponse.json(
{ ok: false, error: `Unsupported mime: ${parsed.mime}` },
{ status: 400 },
);
}
// The declared MIME comes from the caller-written data URL, so it decides
// the stored extension. Require the bytes to actually be that image type.
const sniffed = sniffImageType(parsed.bytes);
if (!sniffed || MIME_EXT[sniffed] !== ext) {
return NextResponse.json(
{ ok: false, error: "Content does not match declared image type" },
{ status: 400 },
);
}
if (parsed.bytes.byteLength > 8 * 1024 * 1024) {
return NextResponse.json({ ok: false, error: "Image too large (>8MB)" }, { status: 413 });
}
try {
// Decode pixels too: valid headers alone still accept truncated images.
await sharp(parsed.bytes, { limitInputPixels: 64 * 1024 * 1024, failOn: "warning" }).stats();
} catch {
return NextResponse.json({ ok: false, error: "Image is corrupt or exceeds 64 megapixels" }, { status: 400 });
}
const hash = createHash("sha1").update(parsed.bytes).digest("hex").slice(0, 16);
const filename = `${hash}.${ext}`;
const absDir = path.join(process.cwd(), UPLOAD_DIR_REL);
const absFile = path.join(absDir, filename);
try {
await fs.mkdir(absDir, { recursive: true });
await writeAsset(absFile, parsed.bytes);
return NextResponse.json({ ok: true, path: `${PUBLIC_PREFIX}/${filename}` });
} catch (e) {
return NextResponse.json(
{ ok: false, error: e instanceof Error ? e.message : String(e) },
{ status: 500 },
);
}
}
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| slack-gif-creatoranthropics/skillsKnowledge and utilities for creating animated GIFs optimized for Slack. Provides constraints, validation tools, and animation concepts. Use when users request animated GIFs for Slack like "make me a GIF of X doing Y for Slack." | Stars: 197k | Updated | Claude CodeCodex | Verified | Install |
| ponytailDietrichGebert/ponytailLazy senior dev mode for any coding task: the smallest change that fully solves it, and a reply a busy human understands in one read. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |
| ponytail-debtDietrichGebert/ponytailHarvest every shortcut: comment into one debt ledger, so deferrals get tracked instead of forgotten. One-shot report. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |
| ponytail-debtDietrichGebert/ponytailList every `shortcut:` comment (and older `ponytail:` ones) as a debt ledger. One-shot report, changes nothing. Use for "ponytail debt", "what did ponytail defer", "list the shortcuts", /ponytail-debt. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |