mirror of
https://github.com/immich-app/static-pages.git
synced 2026-09-30 13:23:05 +08:00
fix: restore deprecated /api/answers endpoint for old clients (#409)
Co-authored-by: Zack Pollard <zackpollard@Zacks-MacBook-Pro.local> Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Zack Pollard
Claude Opus 4.6
parent
6438b9c75e
commit
dcd7c15449
@@ -83,6 +83,49 @@ router.post('/api/answers/batch', async (request, env) => {
|
||||
return new Response(null, { status: 204 });
|
||||
});
|
||||
|
||||
// @deprecated — kept for old clients still calling the single-answer endpoint
|
||||
router.post('/api/answers', async (request, env) => {
|
||||
const db = env.DB;
|
||||
const { questionId, value, otherText } = (await request.json()) as {
|
||||
questionId: string;
|
||||
value: string;
|
||||
otherText?: string;
|
||||
};
|
||||
|
||||
const ip =
|
||||
request.headers.get('CF-Connecting-IP') ??
|
||||
request.headers.get('x-forwarded-for') ??
|
||||
'unknown';
|
||||
|
||||
let respondentId = getRespondentId(request);
|
||||
const headers = new Headers();
|
||||
|
||||
if (!respondentId) {
|
||||
respondentId = crypto.randomUUID();
|
||||
setRespondentCookie(headers, respondentId);
|
||||
}
|
||||
|
||||
await db
|
||||
.prepare(
|
||||
`INSERT INTO respondents (id, ip_address, created_at) VALUES (?, ?, ?)
|
||||
ON CONFLICT (id) DO UPDATE SET ip_address = excluded.ip_address`,
|
||||
)
|
||||
.bind(respondentId, ip, new Date().toISOString())
|
||||
.run();
|
||||
|
||||
await db
|
||||
.prepare(
|
||||
`INSERT INTO answers (respondent_id, question_id, answer, other_text, answered_at)
|
||||
VALUES (?, ?, ?, ?, ?)
|
||||
ON CONFLICT (respondent_id, question_id)
|
||||
DO UPDATE SET answer = excluded.answer, other_text = excluded.other_text, answered_at = excluded.answered_at`,
|
||||
)
|
||||
.bind(respondentId, questionId, value, otherText ?? null, new Date().toISOString())
|
||||
.run();
|
||||
|
||||
return new Response(null, { status: 204, headers });
|
||||
});
|
||||
|
||||
router.get('/api/resume', async (request, env) => {
|
||||
const db = env.DB;
|
||||
let respondentId = getRespondentId(request);
|
||||
|
||||
Reference in New Issue
Block a user