ui fix file preload, fix create metadata method

This commit is contained in:
nick-delirium 2024-10-23 18:03:45 +02:00
parent 6240a8636b
commit c53604e216
No known key found for this signature in database
GPG key ID: 93ABD695DF5FDBA0
6 changed files with 18 additions and 15 deletions

View file

@ -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}`;
}

View file

@ -13,7 +13,6 @@ interface CustomFieldFormProps {
}
const CustomFieldForm: React.FC<CustomFieldFormProps> = ({ siteId }) => {
console.log('siteId', siteId);
const focusElementRef = useRef<HTMLInputElement>(null);
const { customFieldStore: store } = useStore();
const field = store.instance;

View file

@ -33,7 +33,6 @@ const CustomFields = () => {
}, [sites]);
const handleInit = (field?: any) => {
console.log('field', field);
store.init(field);
showModal(<CustomFieldForm siteId={currentSite.id} />, {
title: field ? 'Edit Metadata' : 'Add Metadata', right: true

View file

@ -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);

View file

@ -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);

View file

@ -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;
}