added download size

This commit is contained in:
averel10
2026-03-20 08:43:12 +01:00
parent c3bede86fe
commit ea7c75c523
2 changed files with 24 additions and 6 deletions

View File

@@ -1,12 +1,13 @@
'use server';
import { readdirSync, unlinkSync } from 'fs';
import { readdirSync, unlinkSync, statSync } from 'fs';
import { join } from 'path';
import { requireAdmin } from '@/lib/auth';
interface DownloadFile {
name: string;
url: string;
size: number;
}
export async function getAvailableDownloads(datasetId: number): Promise<DownloadFile[]> {
@@ -25,10 +26,15 @@ export async function getAvailableDownloads(datasetId: number): Promise<Download
// Sort by timestamp descending (most recent first)
matching.sort().reverse();
return matching.map(file => ({
name: file,
url: `/public/downloads/${file}`
}));
return matching.map(file => {
const filePath = join(downloadsDir, file);
const stats = statSync(filePath);
return {
name: file,
url: `/public/downloads/${file}`,
size: stats.size
};
});
} catch (error) {
console.error('Error fetching available downloads:', error);
throw new Error('Failed to fetch available downloads');