/** * OxiCloud - Shared View Component * In-app shared files view. All operations go through the backend API. */ import { switchToFilesSection } from '../../app/navigation.js'; import { ui } from '../../app/ui.js'; import { getCsrfHeaders } from '../../core/csrf.js'; import { formatDateShort } from '../../core/formatters.js'; import { i18n } from '../../core/i18n.js'; import { fileSharing } from '../../features/sharing/fileSharing.js'; const sharedView = { // State items: [], filteredItems: [], currentItem: null, /** Auth header helper — tokens are in HttpOnly cookies now */ _headers(json = false) { const h = { ...getCsrfHeaders() }; if (json) h['Content-Type'] = 'application/json'; return h; }, init() { console.log('Initializing shared view component (API-backed)'); this.loadItems(); }, show() { this.displayUI(); this.attachEventListeners(); this.loadItems().then(() => this.filterAndSortItems()); const c = document.getElementById('shared-container'); if (c) c.classList.remove('hidden'); }, hide() { const c = document.getElementById('shared-container'); if (c) c.classList.add('hidden'); }, // Load shared items from backend API async loadItems() { try { const res = await fetch('/api/shares?page=1&per_page=1000', { headers: this._headers() }); if (res.ok) { const data = await res.json(); this.items = data.items || []; } else { this.items = []; } } catch (err) { console.error('Error loading shared items:', err); this.items = []; } this.filteredItems = [...this.items]; }, // Create and display the shared view UI displayUI() { const contentArea = document.querySelector('.content-area'); let container = document.getElementById('shared-container'); if (!container) { container = document.createElement('div'); container.id = 'shared-container'; container.className = 'shared-view-container'; if (contentArea) contentArea.appendChild(container); } container.innerHTML = `