fix: resolve public share downloads and sort storage overview by size
All checks were successful
Automated Container Build / build-and-push (push) Successful in 35s
All checks were successful
Automated Container Build / build-and-push (push) Successful in 35s
This commit is contained in:
parent
fb3f3a3393
commit
5c2eaf49e4
2 changed files with 13 additions and 4 deletions
|
|
@ -19,6 +19,7 @@ export default function PublicSharePage({ params }: { params: Promise<{ id: stri
|
||||||
const [error, setError] = useState<string | null>(null);
|
const [error, setError] = useState<string | null>(null);
|
||||||
const [requirePassword, setRequirePassword] = useState(false);
|
const [requirePassword, setRequirePassword] = useState(false);
|
||||||
const [password, setPassword] = useState('');
|
const [password, setPassword] = useState('');
|
||||||
|
const [token, setToken] = useState('');
|
||||||
const [fileInfo, setFileInfo] = useState<FileInfo | null>(null);
|
const [fileInfo, setFileInfo] = useState<FileInfo | null>(null);
|
||||||
const [currentPath, setCurrentPath] = useState('');
|
const [currentPath, setCurrentPath] = useState('');
|
||||||
|
|
||||||
|
|
@ -36,6 +37,12 @@ export default function PublicSharePage({ params }: { params: Promise<{ id: stri
|
||||||
} else {
|
} else {
|
||||||
setRequirePassword(false);
|
setRequirePassword(false);
|
||||||
setFileInfo(data);
|
setFileInfo(data);
|
||||||
|
try {
|
||||||
|
const t = await api.createPublicShareToken(id, pwd);
|
||||||
|
setToken(t);
|
||||||
|
} catch (e) {
|
||||||
|
console.error("Failed to fetch token", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
if (err.require_password) {
|
if (err.require_password) {
|
||||||
|
|
@ -55,7 +62,7 @@ export default function PublicSharePage({ params }: { params: Promise<{ id: stri
|
||||||
|
|
||||||
function handleDownload(specificPath?: string) {
|
function handleDownload(specificPath?: string) {
|
||||||
const downloadPath = specificPath ? (currentPath ? `${currentPath}/${specificPath}` : specificPath) : currentPath;
|
const downloadPath = specificPath ? (currentPath ? `${currentPath}/${specificPath}` : specificPath) : currentPath;
|
||||||
const url = api.getPublicDownloadUrl(id, password, downloadPath);
|
const url = api.getPublicDownloadUrl(id, token, downloadPath);
|
||||||
window.location.href = url;
|
window.location.href = url;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -136,7 +143,7 @@ export default function PublicSharePage({ params }: { params: Promise<{ id: stri
|
||||||
const isVideo = !fileInfo?.is_dir && fileInfo?.mime_type?.startsWith('video/');
|
const isVideo = !fileInfo?.is_dir && fileInfo?.mime_type?.startsWith('video/');
|
||||||
const isAudio = !fileInfo?.is_dir && fileInfo?.mime_type?.startsWith('audio/');
|
const isAudio = !fileInfo?.is_dir && fileInfo?.mime_type?.startsWith('audio/');
|
||||||
const isPdf = !fileInfo?.is_dir && fileInfo?.mime_type === 'application/pdf';
|
const isPdf = !fileInfo?.is_dir && fileInfo?.mime_type === 'application/pdf';
|
||||||
const downloadUrl = fileInfo ? api.getPublicDownloadUrl(id, password, currentPath) : '';
|
const downloadUrl = fileInfo && token ? api.getPublicDownloadUrl(id, token, currentPath) : '';
|
||||||
|
|
||||||
// Breadcrumbs
|
// Breadcrumbs
|
||||||
const pathParts = currentPath.split('/').filter(Boolean);
|
const pathParts = currentPath.split('/').filter(Boolean);
|
||||||
|
|
|
||||||
|
|
@ -63,6 +63,8 @@ export default function StorageDashboard() {
|
||||||
|
|
||||||
const totalDriveSize = 100 * 1024 * 1024 * 1024; // Dummy 100GB capacity for visualization, could be dynamic
|
const totalDriveSize = 100 * 1024 * 1024 * 1024; // Dummy 100GB capacity for visualization, could be dynamic
|
||||||
|
|
||||||
|
const sortedCategories = [...data.categories].sort((a, b) => b.size - a.size);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex-1 overflow-y-auto p-8 max-w-5xl mx-auto w-full">
|
<div className="flex-1 overflow-y-auto p-8 max-w-5xl mx-auto w-full">
|
||||||
<div className="mb-8 flex items-center gap-4">
|
<div className="mb-8 flex items-center gap-4">
|
||||||
|
|
@ -85,7 +87,7 @@ export default function StorageDashboard() {
|
||||||
|
|
||||||
{/* Progress Bar */}
|
{/* Progress Bar */}
|
||||||
<div className="h-4 w-full rounded-full overflow-hidden flex gap-0.5" style={{ backgroundColor: 'var(--color-bg-secondary)' }}>
|
<div className="h-4 w-full rounded-full overflow-hidden flex gap-0.5" style={{ backgroundColor: 'var(--color-bg-secondary)' }}>
|
||||||
{data.categories.map(cat => {
|
{sortedCategories.map(cat => {
|
||||||
const pct = (cat.size / Math.max(data.total_size, 1)) * 100;
|
const pct = (cat.size / Math.max(data.total_size, 1)) * 100;
|
||||||
if (pct === 0) return null;
|
if (pct === 0) return null;
|
||||||
return (
|
return (
|
||||||
|
|
@ -104,7 +106,7 @@ export default function StorageDashboard() {
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
|
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
|
||||||
{data.categories.map((cat, idx) => {
|
{sortedCategories.map((cat, idx) => {
|
||||||
const config = categoryConfig[cat.category] || categoryConfig.other;
|
const config = categoryConfig[cat.category] || categoryConfig.other;
|
||||||
const Icon = config.icon;
|
const Icon = config.icon;
|
||||||
return (
|
return (
|
||||||
|
|
|
||||||
Reference in a new issue