From 32471030d432eb8d3cef4af8bb00790f3b9f089c Mon Sep 17 00:00:00 2001 From: ilotterytea Date: Tue, 17 Jun 2025 22:30:05 +0500 Subject: feat: we are using SQL databases now --- lib/file.php | 9 ++++++--- lib/partials.php | 14 ++++++++------ 2 files changed, 14 insertions(+), 9 deletions(-) (limited to 'lib') diff --git a/lib/file.php b/lib/file.php index fe7dae1..fc3e38a 100644 --- a/lib/file.php +++ b/lib/file.php @@ -19,12 +19,11 @@ function verify_mimetype(string $file_path, string $mimetype): bool throw new RuntimeException("Illegal type for MIME verifications: $mimetype"); } -function delete_file(string $file_id, string $file_extension): bool +function delete_file(string $file_id, string $file_extension, PDO|null $db = null): bool { $paths = [ FILE_UPLOAD_DIRECTORY . "/{$file_id}.{$file_extension}", - FILE_THUMBNAIL_DIRECTORY . "/{$file_id}.webp", - FILE_METADATA_DIRECTORY . "/{$file_id}.metadata.json" + FILE_THUMBNAIL_DIRECTORY . "/{$file_id}.webp" ]; foreach ($paths as $path) { @@ -33,6 +32,10 @@ function delete_file(string $file_id, string $file_extension): bool } } + if ($db) { + $db->prepare('DELETE FROM files WHERE id = ? AND extension = ?')->execute([$file_id, $file_extension]); + } + return true; } diff --git a/lib/partials.php b/lib/partials.php index 5b94ce2..6c69c62 100644 --- a/lib/partials.php +++ b/lib/partials.php @@ -66,12 +66,14 @@ function html_mini_navbar() function html_footer() { - $files = glob(FILE_UPLOAD_DIRECTORY . "/*.*"); - $file_size = 0; + $db = new PDO(DB_URL, DB_USER, DB_PASS); + $stmt = $db->query('SELECT COUNT(*) AS file_count, SUM(size) AS file_overall_size FROM files'); + $stmt->execute(); - foreach ($files as $file) { - $file_size += filesize($file); - } + $row = $stmt->fetch(PDO::FETCH_ASSOC); + + $file_count = $row['file_count']; + $file_size = $row['file_overall_size']; $suffix = 'MB'; $file_size /= 1024 * 1024; // MB @@ -119,7 +121,7 @@ function html_footer()

[Tor]

-

Serving files and of active content

+

Serving files and of active content