diff --git a/frontend/app/api_client.ts b/frontend/app/api_client.ts index 12b3e06ca..515f393b3 100644 --- a/frontend/app/api_client.ts +++ b/frontend/app/api_client.ts @@ -166,8 +166,8 @@ export default class APIClient { let fetch = window.fetch; let edp = window.env.API_EDP || window.location.origin + '/api'; - const spotService = path.includes('/spot') && !path.includes('/login') - if (spotService && !edp.includes('api.openreplay.com')) { + const noChalice = path.includes('/spot') && !path.includes('/login') + if (noChalice && !edp.includes('api.openreplay.com')) { edp = edp.replace('/api', '') } if ( @@ -176,7 +176,7 @@ export default class APIClient { !path.includes('/assist/credentials') && siteIdRequiredPaths.some(sidPath => path.startsWith(sidPath)) ) { - if (!this.siteId) console.trace('no id', path) + if (!this.siteId) console.trace('no site id', path, this.siteId) edp = `${edp}/${this.siteId}`; } diff --git a/frontend/app/components/Client/CustomFields/CustomFieldForm.tsx b/frontend/app/components/Client/CustomFields/CustomFieldForm.tsx index 577153da2..dd76542c9 100644 --- a/frontend/app/components/Client/CustomFields/CustomFieldForm.tsx +++ b/frontend/app/components/Client/CustomFields/CustomFieldForm.tsx @@ -13,7 +13,6 @@ interface CustomFieldFormProps { } const CustomFieldForm: React.FC = ({ siteId }) => { - console.log('siteId', siteId); const focusElementRef = useRef(null); const { customFieldStore: store } = useStore(); const field = store.instance; diff --git a/frontend/app/components/Client/CustomFields/CustomFields.tsx b/frontend/app/components/Client/CustomFields/CustomFields.tsx index e4152911e..408c78961 100644 --- a/frontend/app/components/Client/CustomFields/CustomFields.tsx +++ b/frontend/app/components/Client/CustomFields/CustomFields.tsx @@ -33,7 +33,6 @@ const CustomFields = () => { }, [sites]); const handleInit = (field?: any) => { - console.log('field', field); store.init(field); showModal(, { title: field ? 'Edit Metadata' : 'Add Metadata', right: true diff --git a/frontend/app/mstore/customFieldStore.ts b/frontend/app/mstore/customFieldStore.ts index 2b4b9a2e2..f5502615d 100644 --- a/frontend/app/mstore/customFieldStore.ts +++ b/frontend/app/mstore/customFieldStore.ts @@ -79,7 +79,7 @@ class CustomFieldStore { this.isSaving = true; try { const wasCreating = !instance.exists(); - const response = instance.exists() ? await customFieldService.create(siteId, instance.toData()) : + const response = wasCreating ? await customFieldService.create(siteId, instance.toData()) : await customFieldService.update(siteId, instance.toData()); const updatedInstance = new CustomField(response); diff --git a/frontend/app/mstore/index.tsx b/frontend/app/mstore/index.tsx index f95b51dc7..0d57b344a 100644 --- a/frontend/app/mstore/index.tsx +++ b/frontend/app/mstore/index.tsx @@ -75,6 +75,7 @@ window.getJWT = () => { window.setJWT = (jwt) => { userStore.updateJwt({jwt}); }; +export const client = new APIClient(); export class RootStore { dashboardStore: DashboardStore; @@ -142,7 +143,6 @@ export class RootStore { } initClient() { - const client = new APIClient(); client.setSiteIdCheck(projectStore.getSiteId); client.setJwt(userStore.getJwt()); client.setJwtChecker(userStore.getJwt); diff --git a/frontend/app/player/web/network/loadFiles.ts b/frontend/app/player/web/network/loadFiles.ts index fc9669008..8c5b1ff2c 100644 --- a/frontend/app/player/web/network/loadFiles.ts +++ b/frontend/app/player/web/network/loadFiles.ts @@ -1,4 +1,4 @@ -import APIClient from 'App/api_client'; +import { client } from 'App/mstore' const ALLOWED_404 = 'No-file-and-this-is-ok'; const NO_BACKUP_FILE = 'No-efs-file'; @@ -58,16 +58,21 @@ export async function requestTarball(url: string) { } } +const urlPattern = /https?:\/\/[a-zA-Z0-9.-]+(:\d+)?\/(\d+)\/session\/\d+/; + +function getSiteId(url) { + const match = url.match(urlPattern); + return match ? match[2] : null; // match[2] contains the siteId +} + async function requestEFSMobFile(filename: string) { - const api = new APIClient(); - const siteId = document.location.href.match( - /https:\/\/[a-z.-]+\/([a-z0-9]+)\/[a-z-]+\/[0-9]+/ - )?.[1]; + const siteId = getSiteId(document.location.href) if (siteId) { - api.forceSiteId(siteId); - api.setSiteIdCheck(() => siteId); + client.forceSiteId(siteId); + client.setSiteIdCheck(() => ({ siteId })); } - const res = await api.fetch('/unprocessed/' + filename); + + const res = await client.fetch('/unprocessed/' + filename); if (res.status >= 400) { throw NO_BACKUP_FILE; }