| |
| |
|
|
| const QUEUE_KEY = 'bayan_sync_queue'; |
|
|
| const SyncQueue = { |
| |
| |
| |
| |
| getAll() { |
| try { |
| const data = localStorage.getItem(QUEUE_KEY); |
| return data ? JSON.parse(data) : []; |
| } catch (e) { |
| console.warn('Failed to read sync queue', e); |
| return []; |
| } |
| }, |
|
|
| |
| |
| |
| |
| _save(queue) { |
| try { |
| localStorage.setItem(QUEUE_KEY, JSON.stringify(queue)); |
| } catch (e) { |
| console.warn('Failed to save sync queue', e); |
| } |
| }, |
|
|
| |
| |
| |
| |
| |
| enqueue(docId, content) { |
| if (!docId) return; |
| const queue = this.getAll(); |
| |
| |
| const filteredQueue = queue.filter(item => item.docId !== docId); |
| |
| filteredQueue.push({ |
| id: Date.now().toString() + '_' + Math.random().toString(36).substr(2, 5), |
| docId, |
| content, |
| timestamp: Date.now(), |
| retries: 0 |
| }); |
|
|
| this._save(filteredQueue); |
| }, |
|
|
| |
| |
| |
| |
| remove(id) { |
| const queue = this.getAll().filter(item => item.id !== id); |
| this._save(queue); |
| }, |
|
|
| |
| |
| |
| |
| incrementRetry(id) { |
| const queue = this.getAll(); |
| const item = queue.find(i => i.id === id); |
| if (item) { |
| item.retries += 1; |
| this._save(queue); |
| } |
| }, |
|
|
| |
| |
| |
| clear() { |
| try { |
| localStorage.removeItem(QUEUE_KEY); |
| } catch (e) {} |
| } |
| }; |
|
|
| if (typeof module !== 'undefined' && module.exports) { |
| module.exports = { SyncQueue }; |
| } |
|
|