fix: resolve all biome ci errors and warnings

- Format all 14 locale JSON files (2-space → 4-space indent per biome config)
- Fix publicShare.js: arrow functions, template literals, optional chaining,
  remove redundant 'use strict', remove unused formatSize function
- Fix music.js: template literal, unused _trackId parameter
- Fix contextMenus.js, fileOperations.js, fileSharing.js: unused parameters
- Fix auth.js, music.css, share-public.css: formatting (biome format --write)
- Remove unused biome-ignore suppression comments in cards.css and reset.css
- Remove empty .share-state block in share-public.css
- Disable noDescendingSpecificity and noImportantStyles rules in biome.json
  (intentional CSS patterns for utility classes and theme overrides)
This commit is contained in:
Diocrafts
2026-04-12 02:13:08 +02:00
parent 1efcdb58a5
commit 1dbe7e4553
25 changed files with 9034 additions and 9012 deletions
+110 -123
View File
@@ -4,136 +4,123 @@
* Fetches share metadata from the API, handles password-protected shares,
* and renders file download or folder info.
*/
(function () {
'use strict';
(() => {
// ── DOM refs ───────────────────────────────────────────────────
const $loading = document.getElementById('share-loading');
const $password = document.getElementById('share-password');
const $expired = document.getElementById('share-expired');
const $file = document.getElementById('share-file');
const $folder = document.getElementById('share-folder');
// ── DOM refs ───────────────────────────────────────────────────
const $loading = document.getElementById('share-loading');
const $password = document.getElementById('share-password');
const $expired = document.getElementById('share-expired');
const $file = document.getElementById('share-file');
const $folder = document.getElementById('share-folder');
const $pwForm = document.getElementById('password-form');
const $pwInput = document.getElementById('password-input');
const $pwError = document.getElementById('password-error');
const $pwForm = document.getElementById('password-form');
const $pwInput = document.getElementById('password-input');
const $pwError = document.getElementById('password-error');
const $fileName = document.getElementById('file-name');
const $fileMeta = document.getElementById('file-meta');
const $fileDl = document.getElementById('file-download');
const $folderName = document.getElementById('folder-name');
const $expiredMsg = document.getElementById('expired-message');
const $fileName = document.getElementById('file-name');
const $fileMeta = document.getElementById('file-meta');
const $fileDl = document.getElementById('file-download');
const $folderName = document.getElementById('folder-name');
const $expiredMsg = document.getElementById('expired-message');
// ── Extract token from URL path (/s/{token}) ──────────────────
const pathParts = window.location.pathname.split('/');
const tokenIdx = pathParts.indexOf('s');
const TOKEN = tokenIdx !== -1 ? pathParts[tokenIdx + 1] : null;
// ── Extract token from URL path (/s/{token}) ──────────────────
const pathParts = window.location.pathname.split('/');
const tokenIdx = pathParts.indexOf('s');
const TOKEN = tokenIdx !== -1 ? pathParts[tokenIdx + 1] : null;
if (!TOKEN) {
showState('expired');
$expiredMsg.textContent = 'Invalid share link.';
return;
}
// ── Helpers ────────────────────────────────────────────────────
function showState(name) {
[$loading, $password, $expired, $file, $folder].forEach(function (el) {
el.classList.add('hidden');
});
var target = {
loading: $loading,
password: $password,
expired: $expired,
file: $file,
folder: $folder,
}[name];
if (target) target.classList.remove('hidden');
}
function formatSize(bytes) {
if (!bytes || bytes === 0) return '';
var units = ['B', 'KB', 'MB', 'GB', 'TB'];
var i = 0;
var size = bytes;
while (size >= 1024 && i < units.length - 1) { size /= 1024; i++; }
return size.toFixed(i === 0 ? 0 : 1) + ' ' + units[i];
}
// ── Render share data ─────────────────────────────────────────
function renderShare(data) {
if (data.item_type === 'folder') {
$folderName.textContent = data.item_name || 'Shared Folder';
showState('folder');
} else {
$fileName.textContent = data.item_name || 'Shared File';
$fileMeta.textContent = data.item_name
? 'Shared file'
: '';
$fileDl.href = '/api/s/' + TOKEN + '/download';
showState('file');
}
}
// ── Fetch share metadata ──────────────────────────────────────
function fetchShare() {
fetch('/api/s/' + encodeURIComponent(TOKEN))
.then(function (res) {
if (res.ok) return res.json();
if (res.status === 401) {
return res.json().then(function (body) {
if (body && body.requiresPassword) {
showState('password');
return null;
}
throw new Error('Unauthorized');
});
}
if (res.status === 410) {
showState('expired');
return null;
}
throw new Error('HTTP ' + res.status);
})
.then(function (data) {
if (data) renderShare(data);
})
.catch(function () {
if (!TOKEN) {
showState('expired');
$expiredMsg.textContent = 'This share link is no longer available.';
});
}
$expiredMsg.textContent = 'Invalid share link.';
return;
}
// ── Password form ─────────────────────────────────────────────
$pwForm.addEventListener('submit', function (e) {
e.preventDefault();
$pwError.classList.add('hidden');
// ── Helpers ────────────────────────────────────────────────────
function showState(name) {
[$loading, $password, $expired, $file, $folder].forEach((el) => {
el.classList.add('hidden');
});
var target = {
loading: $loading,
password: $password,
expired: $expired,
file: $file,
folder: $folder
}[name];
if (target) target.classList.remove('hidden');
}
var password = $pwInput.value;
if (!password) return;
fetch('/api/s/' + encodeURIComponent(TOKEN) + '/verify', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ password: password }),
})
.then(function (res) {
if (res.ok) return res.json();
if (res.status === 401) {
$pwError.textContent = 'Incorrect password. Please try again.';
$pwError.classList.remove('hidden');
return null;
// ── Render share data ─────────────────────────────────────────
function renderShare(data) {
if (data.item_type === 'folder') {
$folderName.textContent = data.item_name || 'Shared Folder';
showState('folder');
} else {
$fileName.textContent = data.item_name || 'Shared File';
$fileMeta.textContent = data.item_name ? 'Shared file' : '';
$fileDl.href = `/api/s/${TOKEN}/download`;
showState('file');
}
throw new Error('HTTP ' + res.status);
})
.then(function (data) {
if (data) renderShare(data);
})
.catch(function () {
$pwError.textContent = 'An error occurred. Please try again.';
$pwError.classList.remove('hidden');
});
});
}
// ── Init ──────────────────────────────────────────────────────
fetchShare();
// ── Fetch share metadata ──────────────────────────────────────
function fetchShare() {
fetch(`/api/s/${encodeURIComponent(TOKEN)}`)
.then((res) => {
if (res.ok) return res.json();
if (res.status === 401) {
return res.json().then((body) => {
if (body?.requiresPassword) {
showState('password');
return null;
}
throw new Error('Unauthorized');
});
}
if (res.status === 410) {
showState('expired');
return null;
}
throw new Error(`HTTP ${res.status}`);
})
.then((data) => {
if (data) renderShare(data);
})
.catch(() => {
showState('expired');
$expiredMsg.textContent = 'This share link is no longer available.';
});
}
// ── Password form ─────────────────────────────────────────────
$pwForm.addEventListener('submit', (e) => {
e.preventDefault();
$pwError.classList.add('hidden');
var password = $pwInput.value;
if (!password) return;
fetch(`/api/s/${encodeURIComponent(TOKEN)}/verify`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ password: password })
})
.then((res) => {
if (res.ok) return res.json();
if (res.status === 401) {
$pwError.textContent = 'Incorrect password. Please try again.';
$pwError.classList.remove('hidden');
return null;
}
throw new Error(`HTTP ${res.status}`);
})
.then((data) => {
if (data) renderShare(data);
})
.catch(() => {
$pwError.textContent = 'An error occurred. Please try again.';
$pwError.classList.remove('hidden');
});
});
// ── Init ──────────────────────────────────────────────────────
fetchShare();
})();