feat: add MCP creator screenshot metrics recognition
This commit is contained in:
@@ -6,6 +6,13 @@ import {
|
||||
uid,
|
||||
} from "../../../lib/mvp-db";
|
||||
import { adminForbidden, isAdminRequest } from "../../../lib/admin-auth";
|
||||
import { creatorScreenshotMcpUrl } from "../../../lib/creator-screenshot-access";
|
||||
import {
|
||||
extractCreatorMetricsFromMcp,
|
||||
resolveCollectionMcpConfig,
|
||||
type CollectionMcpBindings,
|
||||
} from "../../../lib/mcp-collection-client";
|
||||
import { getRuntimeEnv } from "../../../lib/runtime-env";
|
||||
|
||||
export async function POST(request: Request) {
|
||||
if (!(await isAdminRequest(request))) return adminForbidden();
|
||||
@@ -33,12 +40,37 @@ export async function POST(request: Request) {
|
||||
screenshot_key = ?,
|
||||
exposure = NULL,
|
||||
views = NULL,
|
||||
ocr_status = 'failed',
|
||||
ocr_status = 'processing',
|
||||
updated_at = CURRENT_TIMESTAMP
|
||||
WHERE id = ?`,
|
||||
)
|
||||
.bind(key, distributionId)
|
||||
.run();
|
||||
try {
|
||||
const metrics = await extractCreatorMetricsFromMcp(
|
||||
creatorScreenshotMcpUrl(request, distributionId, key),
|
||||
resolveCollectionMcpConfig(getRuntimeEnv() as unknown as CollectionMcpBindings),
|
||||
);
|
||||
await db
|
||||
.prepare(
|
||||
`UPDATE distributions SET exposure = ?, views = ?,
|
||||
ocr_status = 'success', updated_at = CURRENT_TIMESTAMP
|
||||
WHERE id = ?`,
|
||||
)
|
||||
.bind(metrics.exposure, metrics.views, distributionId)
|
||||
.run();
|
||||
} catch (error) {
|
||||
console.error("[KOC LOOP] creator screenshot OCR failed", {
|
||||
distributionId,
|
||||
detail: error instanceof Error ? error.message : String(error),
|
||||
});
|
||||
await db
|
||||
.prepare(
|
||||
`UPDATE distributions SET ocr_status = 'failed', updated_at = CURRENT_TIMESTAMP WHERE id = ?`,
|
||||
)
|
||||
.bind(distributionId)
|
||||
.run();
|
||||
}
|
||||
return Response.json(await getDashboardData());
|
||||
} catch (error) {
|
||||
return Response.json(
|
||||
|
||||
Reference in New Issue
Block a user