Skip to content

add pretalx data fallback when token is unavailable#49

Open
mirumodapon wants to merge 3 commits intomainfrom
feat/session-data-fallback
Open

add pretalx data fallback when token is unavailable#49
mirumodapon wants to merge 3 commits intomainfrom
feat/session-data-fallback

Conversation

@mirumodapon
Copy link
Copy Markdown
Collaborator

This PR introduces a fallback mechanism for pretalx data, allowing the application to function even when a token is not provided.

@rileychh-dokploy-coscup
Copy link
Copy Markdown

rileychh-dokploy-coscup bot commented Mar 21, 2026

Dokploy Preview Deployment

Name Status Preview Updated (UTC)
Nuxt ❌ Failed Preview URL 2026-03-21T11:47:02.884Z

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a fallback path for session data generation when pretalx credentials aren’t available, so the site can still produce session JSON by proxying COSCUP’s published endpoints.

Changes:

  • Make server/utils/pretalx return null when TOKEN/BASE_URL are missing (instead of attempting unauthenticated pretalx calls).
  • Add remote fallback fetches in session JSON/API routes when pretalx data is unavailable.
  • Ensure /api/session is included in Nuxt prerender routes.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
server/utils/pretalx/index.ts Return null early when pretalx runtime config is missing; otherwise fetch pretalx tables as before.
server/routes/json/session.json.get.ts Fallback to https://coscup.org/2026/json/session.json when pretalx data is null.
server/routes/api/session/index.get.ts Fallback to https://coscup.org/2026/api/session when pretalx data is null.
server/routes/api/session/[id]/index.get.ts Reworks data source for per-session endpoint, but currently introduces a runtime/type mismatch (see PR comment).
app/app.vue Adds /api/session to prerender list alongside /json/session.json.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 5 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +5 to +8
const data = await $fetch<PretalxResult>('/2026/json/pretalx.json')

if (!data) {
return (await $fetch('https://coscup.org/2026/api/session'))
Copy link

Copilot AI Mar 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$fetch will throw on non-2xx/network failures, so the if (!data) branch won’t run in the common failure case (and data is typed as non-null). To make the fallback actually work, wrap the $fetch('/2026/json/pretalx.json') in a try/catch (or use $fetch.raw) and fall back on error.

Suggested change
const data = await $fetch<PretalxResult>('/2026/json/pretalx.json')
if (!data) {
return (await $fetch('https://coscup.org/2026/api/session'))
let data: PretalxResult | null = null
try {
data = await $fetch<PretalxResult>('/2026/json/pretalx.json')
}
catch {
// Fallback to remote session API on fetch error (non-2xx or network failure)
return await $fetch('https://coscup.org/2026/api/session')
}
if (!data) {
return await $fetch('https://coscup.org/2026/api/session')

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rileychh 這個你覺得有需要嗎


export default defineEventHandler(async () => {
const data = await pretalxData()
const data = await $fetch<PretalxResult>('/2026/json/pretalx.json')
Copy link

Copilot AI Mar 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This internal fetch hardcodes the /2026/ base path. That makes the route brittle if app.baseURL changes (or for future years). Prefer calling the local handler without embedding the year (e.g. /json/pretalx.json via local fetch) or derive the prefix from runtime config to avoid duplicating the base path in multiple places.

Suggested change
const data = await $fetch<PretalxResult>('/2026/json/pretalx.json')
const data = await $fetch<PretalxResult>('/json/pretalx.json')

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

這應該要有 /2026 (?

const id = getRouterParam(event, 'id')!

const data = await pretalxData()
const data = await $fetch<PretalxResult>('/2026/json/pretalx.json')
Copy link

Copilot AI Mar 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This path hardcodes /2026/, which couples the server logic to the current app.baseURL. To reduce future churn and avoid mismatches, prefer fetching /json/pretalx.json via local fetch (or constructing the path from app.baseURL) rather than embedding the year here.

Copilot uses AI. Check for mistakes.
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'))
Copy link

Copilot AI Mar 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When pretalxData() returns null, this route always fetches from https://coscup.org/.... If that upstream request fails, the handler will throw and callers will get a generic 500. Consider handling $fetch errors explicitly (try/catch + createError with 502/503), and optionally caching the fallback result to avoid repeated upstream requests under load.

Suggested change
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,
})
}

Copilot uses AI. Check for mistakes.
Comment on lines 5 to +9
const data = await pretalxData()
const opass = pretalxToOpass(data)

return opass
if (!data) {
return (await $fetch('https://coscup.org/2026/json/session.json'))
}
Copy link

Copilot AI Mar 21, 2026

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; $fetch will 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.

Copilot uses AI. Check for mistakes.
@mirumodapon mirumodapon marked this pull request as ready for review March 21, 2026 11:46
@mirumodapon mirumodapon requested a review from rileychh March 21, 2026 11:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants