Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion app/app.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
<script setup lang="ts">
import { prerenderRoutes } from 'nuxt/app'

prerenderRoutes(['/json/session.json'])
prerenderRoutes([
'/json/session.json',
'/json/pretalx.json',
])
</script>

<template>
Expand Down
7 changes: 5 additions & 2 deletions server/api/opass.get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ import pretalxData from '~~/server/utils/pretalx'

export default defineEventHandler(async () => {
const data = await pretalxData()
const opass = pretalxToOpass(data)

return opass
if (!data) {
return (await $fetch('https://coscup.org/2026/json/session.json'))
}
Comment on lines 5 to +9
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.

return pretalxToOpass(data)
})
11 changes: 11 additions & 0 deletions server/api/pretalx.json.get.ts
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
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.
}

return data
})
9 changes: 7 additions & 2 deletions server/api/session/[id]/index.get.ts
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')
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.

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

const submission = data.submissions?.map[id]
Comment thread
mirumodapon marked this conversation as resolved.

if (!submission) {
Expand Down
9 changes: 6 additions & 3 deletions server/api/session/index.get.ts
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')
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 (?


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

const submissions = data.submissions?.arr || []

Expand Down
4 changes: 4 additions & 0 deletions server/utils/pretalx/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ export default defineCachedFunction(
async () => {
const config = useRuntimeConfig()

if (!config.pretalxApiToken || !config.pretalxApiUrl) {
return null
}

const tables = ['submissions', 'submission-types', 'speakers', 'rooms', 'answers', 'slots'] as const
const results: Partial<PretalxResult> = {}

Expand Down