Fix guest upload queue endpoint
This commit is contained in:
12
resources/js/guest/queue/__tests__/queueUrl.test.ts
Normal file
12
resources/js/guest/queue/__tests__/queueUrl.test.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { buildQueueUploadUrl } from '../queue';
|
||||
|
||||
describe('buildQueueUploadUrl', () => {
|
||||
it('builds the guest upload endpoint', () => {
|
||||
expect(buildQueueUploadUrl('demo-token')).toBe('/api/v1/events/demo-token/upload');
|
||||
});
|
||||
|
||||
it('encodes event tokens safely', () => {
|
||||
expect(buildQueueUploadUrl('token/with space')).toBe('/api/v1/events/token%2Fwith%20space/upload');
|
||||
});
|
||||
});
|
||||
@@ -5,6 +5,9 @@ import { createUpload } from './xhr';
|
||||
import { notify } from './notify';
|
||||
type SyncManager = { register(tag: string): Promise<void>; };
|
||||
|
||||
export const buildQueueUploadUrl = (eventToken: string) =>
|
||||
`/api/v1/events/${encodeURIComponent(eventToken)}/upload`;
|
||||
|
||||
export type QueueItem = {
|
||||
id?: number;
|
||||
eventToken: string;
|
||||
@@ -81,7 +84,7 @@ async function attemptUpload(it: QueueItem): Promise<boolean> {
|
||||
if (!navigator.onLine) return false;
|
||||
try {
|
||||
const json = await createUpload(
|
||||
`/api/v1/events/${encodeURIComponent(it.eventToken)}/photos`,
|
||||
buildQueueUploadUrl(it.eventToken),
|
||||
it,
|
||||
getDeviceId(),
|
||||
(pct) => {
|
||||
|
||||
Reference in New Issue
Block a user