-
Notifications
You must be signed in to change notification settings - Fork 4
add pretalx data fallback when token is unavailable #49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
3342912
4987501
1d96ace
9b865c2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,11 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import pretalxData from '~~/server/utils/pretalx' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export default defineEventHandler(async () => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const data = await pretalxData() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (!data) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return (await $fetch('https://coscup.org/2026/json/pretalx.json')) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+2
to
+7
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export default defineEventHandler(async () => { | |
| const data = await pretalxData() | |
| if (!data) { | |
| return (await $fetch('https://coscup.org/2026/json/pretalx.json')) | |
| import { createError } from 'h3' | |
| let cachedPretalxFallback: any | null = null | |
| export default defineEventHandler(async () => { | |
| const data = await pretalxData() | |
| if (!data) { | |
| if (cachedPretalxFallback) { | |
| return cachedPretalxFallback | |
| } | |
| try { | |
| const fallback = await $fetch('https://coscup.org/2026/json/pretalx.json') | |
| cachedPretalxFallback = fallback | |
| return fallback | |
| } catch (error: any) { | |
| throw createError({ | |
| statusCode: 502, | |
| statusMessage: 'Bad Gateway', | |
| message: 'Failed to fetch pretalx fallback data from coscup.org', | |
| cause: error, | |
| }) | |
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,15 @@ | ||
| import pretalxData from '~~/server/utils/pretalx' | ||
| import type { PretalxResult } from '~~/server/utils/pretalx/type' | ||
| import { parseAnswer, parseSlot, parseSpeaker, parseType } from '~~/server/utils/pretalx/parser' | ||
|
|
||
| export default defineEventHandler(async (event) => { | ||
| const id = getRouterParam(event, 'id')! | ||
|
|
||
| const data = await pretalxData() | ||
| const data = await $fetch<PretalxResult>('/2026/json/pretalx.json') | ||
|
||
|
|
||
| if (!data) { | ||
| return (await $fetch('https://coscup.org/2026/json/pretalx.json')) | ||
| } | ||
|
|
||
| const submission = data.submissions?.map[id] | ||
|
mirumodapon marked this conversation as resolved.
|
||
|
|
||
| if (!submission) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,9 +1,12 @@ | ||||||
| import type { Submission } from '~~/server/utils/pretalx/type' | ||||||
| import pretalxData from '~~/server/utils/pretalx' | ||||||
| import type { PretalxResult, Submission } from '~~/server/utils/pretalx/type' | ||||||
| import { parseAnswer, parseSlot, parseSpeaker, parseType } from '~~/server/utils/pretalx/parser' | ||||||
|
|
||||||
| export default defineEventHandler(async () => { | ||||||
| const data = await pretalxData() | ||||||
| const data = await $fetch<PretalxResult>('/2026/json/pretalx.json') | ||||||
|
||||||
| const data = await $fetch<PretalxResult>('/2026/json/pretalx.json') | |
| const data = await $fetch<PretalxResult>('/json/pretalx.json') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
這應該要有 /2026 (?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The fallback uses an external
$fetch('https://coscup.org/2026/json/session.json')but doesn’t handle upstream failures;$fetchwill throw and the endpoint becomes a 500. Consider try/catch with a 502/503 (and optionally caching the fallback response) so behavior is predictable when the upstream is down.