| | |
| | | this.errors = window.jvbError; |
| | | |
| | | // Initialize DataStore for queue persistence |
| | | this.store = window.jvbStore.register('queue', { |
| | | const store = window.jvbStore.register('queue', { |
| | | storeName: 'queue', |
| | | keyPath: 'id', |
| | | endpoint: this.config.endpoint, |
| | | TTL: Infinity, |
| | |
| | | showLoading: false, |
| | | delayFetch: false, // Queue should fetch immediately |
| | | }); |
| | | this.store = store.queue; |
| | | |
| | | this.classes = [ |
| | | 'offline', |
| | |
| | | |
| | | async processOperation(operation) { |
| | | try { |
| | | //update to uploading |
| | | this.updateOperationStatus(operation.id, 'uploading'); |
| | | |
| | | // Get fresh copy from store to restore FormData |
| | | operation = this.getQueue(operation.id); |
| | | if (operation.data?._isFormData) { |
| | | operation.data = await this.store.objectToFormData(operation.data); |
| | | } |
| | | |
| | | //build request |
| | | const url = `${this.config.apiBase}${operation.endpoint}`; |
| | | let requestBody; |
| | | console.log(operation.data); |
| | | |
| | | if (operation.data instanceof FormData) { |
| | | operation.data.append('id', operation.id); |
| | | operation.data.append('user', this.user); |
| | | requestBody = operation.data; |
| | | // console.log('Sending formData: '); |
| | | // for (const pair of requestBody.entries()) { |
| | | // console.log(pair[0], pair[1]); |
| | | // } |
| | | |
| | | } else { |
| | | requestBody = JSON.stringify({ |
| | | ...operation.data, |
| | | id: operation.id, |
| | | user: this.user |
| | | }); |
| | | // console.log('Sending data: ', { |
| | | // ...operation.data, |
| | | // id: operation.id, |
| | | // user: this.user |
| | | // }); |
| | | operation.headers['Content-Type'] = 'application/json'; |
| | | } |
| | | |
| | | |
| | | |
| | | const response = await fetch(url, { |
| | | method: operation.method, |
| | | headers: operation.headers, |