diff --git a/assets/pass/add-to-apple-wallet.svg b/assets/pass/add-to-apple-wallet.svg new file mode 100644 index 0000000..1b9e9ef --- /dev/null +++ b/assets/pass/add-to-apple-wallet.svg @@ -0,0 +1,87 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/composables/sstaars.ts b/composables/sstaars.ts index 4361a5d..dd03eeb 100644 --- a/composables/sstaars.ts +++ b/composables/sstaars.ts @@ -3,6 +3,7 @@ import { useStorage } from '@vueuse/core' const queryKeyFactory = { admission: (key: string) => ['sstaars', 'admission', key], + admissionPkPass: (key: string) => ['sstaars', 'admission', key, 'pkPass'], } export const useSstaarsStore = createGlobalState(() => { @@ -16,3 +17,15 @@ export function useAdmission(key: string) { retry: false, }) } + +export function useAdmissionPkPass(key: string) { + const { data: admission } = useAdmission(key) + return useQuery({ + queryKey: queryKeyFactory.admissionPkPass(key), + queryFn: () => $fetch(`/cdn/apple-wallet/${admission.value?.eventId}/${key}.pkpass`, { method: 'GET' }), + // queryFn: () => $fetch(`https://sstaa-cdn.qinguan.me/apple-wallet/${admission.value?.eventId}/${key}.pkpass`, { method: 'GET' }), + // @ts-expect-error Apple Pay Session browser global https://developer.apple.com/documentation/apple_pay_on_the_web/apple_pay_js_api/checking_for_apple_pay_availability + enabled: computed(() => !!admission.value?.admissionKey && !!window.ApplePaySession), + retry: false, + }) +} diff --git a/pages/pass/[admissionKey].vue b/pages/pass/[admissionKey].vue index a32d264..8165a0e 100644 --- a/pages/pass/[admissionKey].vue +++ b/pages/pass/[admissionKey].vue @@ -17,6 +17,8 @@ Framework7.use(Framework7Vue) const route = useRoute() const { data: admission, isLoading: admissionIsLoading, error } = useAdmission(route.params.admissionKey as string) +const { data: admissionPkPass } = useAdmissionPkPass(route.params.admissionKey as string) + const qrcode = useQRCode(() => admission.value?.admissionKey ?? '', { width: 500, color: { @@ -100,6 +102,15 @@ useSeoMeta({
QR Code {{ admission?.admissionKey }} + +
+ + + Add to Apple Wallet +
@@ -143,7 +154,10 @@ useSeoMeta({

- Built by the SSTAA App Team and open sourced on + Built by the SSTAA App Team and open sourced on GitHub .

diff --git a/server/routes/cdn/[...path].ts b/server/routes/cdn/[...path].ts index e707242..def6fc7 100644 --- a/server/routes/cdn/[...path].ts +++ b/server/routes/cdn/[...path].ts @@ -1,8 +1,13 @@ import type { R2Bucket } from '@cloudflare/workers-types' export default defineEventHandler(async (event) => { - if (!event.context.cloudflare) - return 'Cloudflare R2 is not available in this environment.' + if (!event.context.cloudflare) { + throw createError({ + statusCode: 404, + statusMessage: 'Not found', + message: 'Cloudflare R2 is not available in this environment.', + }) + } const bucket: R2Bucket = event.context.cloudflare.env.R2_SSTAA const file = await bucket.get(event.context.params!.path)