()
| 203 | } |
| 204 | |
| 205 | async function resolveAuthFileLinkIfPresent() { |
| 206 | let token = ''; |
| 207 | try { |
| 208 | const url = new URL(window.location.href); |
| 209 | token = String(url.searchParams.get(AUTH_FILE_LINK_PARAM) || '').trim(); |
| 210 | } catch (e) { |
| 211 | token = ''; |
| 212 | } |
| 213 | if (!token) return; |
| 214 | if (!AUTH_FILE_LINK_TOKEN_RE.test(token)) { |
| 215 | window.showToast(t('file_link_invalid_or_expired'), 'error'); |
| 216 | clearAuthFileLinkFromUrl(); |
| 217 | return; |
| 218 | } |
| 219 | |
| 220 | try { |
| 221 | const sourceInitPromise = window.__frSourceInitPromise; |
| 222 | if (sourceInitPromise && typeof sourceInitPromise.then === 'function') { |
| 223 | await sourceInitPromise.catch(() => {}); |
| 224 | } |
| 225 | } catch (e) { |
| 226 | // ignore |
| 227 | } |
| 228 | |
| 229 | try { |
| 230 | const res = await fetch(withBase('/api/file/resolveAuthFileLink.php?token=' + encodeURIComponent(token)), { |
| 231 | method: 'GET', |
| 232 | credentials: 'include', |
| 233 | headers: { 'Accept': 'application/json' } |
| 234 | }); |
| 235 | const data = await res.json().catch(() => ({})); |
| 236 | if (!res.ok || !data || data.ok !== true) { |
| 237 | if (res.status === 403) { |
| 238 | window.showToast(t('no_access_to_resource'), 'error'); |
| 239 | } else if (res.status === 404 || res.status === 410) { |
| 240 | window.showToast(t('file_link_invalid_or_expired'), 'error'); |
| 241 | } else { |
| 242 | const msg = (data && (data.error || data.message)) || t('file_link_resolve_failed'); |
| 243 | window.showToast(msg, 'error'); |
| 244 | } |
| 245 | return; |
| 246 | } |
| 247 | |
| 248 | const folder = String(data.folder || 'root'); |
| 249 | const file = String(data.file || '').trim(); |
| 250 | const sourceId = String(data.sourceId || '').trim(); |
| 251 | if (!file) { |
| 252 | window.showToast(t('file_link_invalid_or_expired'), 'error'); |
| 253 | return; |
| 254 | } |
| 255 | |
| 256 | const list = await import(withBase('/js/fileListView.js?v={{APP_QVER}}')).catch(async () => { |
| 257 | return import(withBase('/js/fileListView.js')); |
| 258 | }); |
| 259 | if (list && typeof list.navigateToLinkedFile === 'function') { |
| 260 | await list.navigateToLinkedFile(folder, file, sourceId); |
| 261 | } else if (typeof window.loadFileList === 'function') { |
| 262 | window.currentFolder = folder || 'root'; |
no test coverage detected