Support explicit current-output A/B fill, protected edited drafts, scoped cloud update offers and atomic native restore with stale-open CAS. Preserve original unknown requests, improve Pi conversation continuity and native DPI/navigation reads, and publish the authenticated template metadata contract. Validated: native backend 172 passed/5 environment tests ignored, UI 110, Pi 53, template/rule API 24 and native cloud contract 6; strict Clippy, layering and wasm. Real S01 selected B, edited/undo-redo, PCraft reopen and layered PSD roundtrip pass with exact pixels. Full nine-output generation and Photoshop acceptance remain open.
27 lines
1.6 KiB
TypeScript
27 lines
1.6 KiB
TypeScript
import { createHash } from 'node:crypto'
|
|
import { NextResponse } from 'next/server'
|
|
import { requireDesktop } from '@/lib/desktop-client/service'
|
|
import { DesktopClientError, desktopAssert } from '@/lib/desktop-client/contract.mjs'
|
|
import { desktopTemplatePacks } from '@/lib/desktop-client/template-packs'
|
|
|
|
export const runtime = 'nodejs'
|
|
export const dynamic = 'force-dynamic'
|
|
const headers = { 'Cache-Control': 'private, no-store', 'X-Content-Type-Options': 'nosniff' }
|
|
|
|
export async function GET(request: Request) {
|
|
try {
|
|
// Every request, including a conditional hit, checks current session and
|
|
// feature authority. Native account-scoped caching cannot replace this.
|
|
await requireDesktop(request)
|
|
const query = new URL(request.url).searchParams
|
|
desktopAssert(query.getAll('brandId').length === 1 && query.getAll('categoryId').length === 1, '请提供唯一的品牌和品类编号', 400, 'invalid_request')
|
|
const value = desktopTemplatePacks(query.get('brandId'), query.get('categoryId'))
|
|
const etag = `"${createHash('sha256').update(JSON.stringify(value)).digest('hex')}"`
|
|
if (request.headers.get('if-none-match') === etag) return new NextResponse(null, { status: 304, headers: { ...headers, ETag: etag } })
|
|
return NextResponse.json(value, { headers: { ...headers, ETag: etag } })
|
|
} catch (error) {
|
|
const known = error instanceof DesktopClientError
|
|
return NextResponse.json({ error: known ? error.message : '模板暂时无法读取', code: known ? error.code : 'internal_error' }, { status: known ? error.status : 500, headers })
|
|
}
|
|
}
|