mirror of
https://github.com/michalcz10/USB-RAID-Array.git
synced 2026-11-11 07:59:04 +00:00
revise backend
This commit is contained in:
+17
-25
@@ -1,26 +1,19 @@
|
||||
<?php
|
||||
// Include this at the top to see potential errors
|
||||
// Comment out in production
|
||||
ini_set('display_errors', 1);
|
||||
error_reporting(E_ALL);
|
||||
|
||||
require_once __DIR__ . '/../../config/config.php';
|
||||
require_once __DIR__ . '/../../includes/workspace.php';
|
||||
|
||||
// getDatabaseConnection relocated to central config
|
||||
|
||||
if (!isset($_GET['token'])) {
|
||||
die("Invalid request. No token provided.");
|
||||
}
|
||||
|
||||
$token = $_GET['token'];
|
||||
$conn = getDatabaseConnection();
|
||||
$database = getDatabaseConnection();
|
||||
|
||||
// Get share information
|
||||
$stmt = $conn->prepare("SELECT * FROM share WHERE token = ? AND expiration > NOW()");
|
||||
$stmt->bind_param("s", $token);
|
||||
$stmt->execute();
|
||||
$result = $stmt->get_result();
|
||||
$statement = $database->prepare("SELECT * FROM share WHERE token = ? AND expiration > NOW()");
|
||||
$statement->bind_param("s", $token);
|
||||
$statement->execute();
|
||||
$result = $statement->get_result();
|
||||
|
||||
if ($result->num_rows === 0) {
|
||||
die("Invalid or expired share link.");
|
||||
@@ -29,7 +22,9 @@ if ($result->num_rows === 0) {
|
||||
$share = $result->fetch_assoc();
|
||||
$filePath = $share['file_path'];
|
||||
$downloadAllowed = $share['download_allowed'] == 1;
|
||||
$stmt->close();
|
||||
$result->free();
|
||||
$statement->close();
|
||||
$database->close();
|
||||
|
||||
// Initialize SFTP
|
||||
$sftp = initializeSFTP();
|
||||
@@ -42,13 +37,13 @@ $fileName = basename($filePath);
|
||||
$fileExtension = strtolower(pathinfo($fileName, PATHINFO_EXTENSION));
|
||||
$fileSize = $sftp->stat($filePath)['size'];
|
||||
|
||||
$imageTypes = ['jpg', 'jpeg', 'png', 'gif', 'bmp', 'webp', 'svg'];
|
||||
$videoTypes = ['mp4', 'webm', 'ogg', 'mov', 'avi', 'mkv'];
|
||||
$audioTypes = ['mp3', 'wav', 'ogg', 'm4a', 'flac', 'aac'];
|
||||
$imageExtensions = ['jpg', 'jpeg', 'png', 'gif', 'bmp', 'webp', 'svg'];
|
||||
$videoExtensions = ['mp4', 'webm', 'ogg', 'mov', 'avi', 'mkv'];
|
||||
$audioExtensions = ['mp3', 'wav', 'ogg', 'm4a', 'flac', 'aac'];
|
||||
|
||||
$isImage = in_array($fileExtension, $imageTypes);
|
||||
$isVideo = in_array($fileExtension, $videoTypes);
|
||||
$isAudio = in_array($fileExtension, $audioTypes);
|
||||
$isImage = in_array($fileExtension, $imageExtensions);
|
||||
$isVideo = in_array($fileExtension, $videoExtensions);
|
||||
$isAudio = in_array($fileExtension, $audioExtensions);
|
||||
|
||||
if (!$isImage && !$isVideo && !$isAudio) {
|
||||
die("Unsupported file type");
|
||||
@@ -165,8 +160,8 @@ if (isset($_GET['stream'])) {
|
||||
|
||||
usleep(100000);
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
error_log("Shared streaming error: " . $e->getMessage());
|
||||
} catch (Exception $exception) {
|
||||
error_log("Shared streaming error: " . $exception->getMessage());
|
||||
}
|
||||
exit;
|
||||
}
|
||||
@@ -242,7 +237,6 @@ function formatBytes($bytes, $precision = 2) {
|
||||
'class' => 'media-page',
|
||||
]); ?>
|
||||
|
||||
|
||||
<div class="content-toolbar"><span class="badge">Shared link</span><p>Available until <?= htmlspecialchars(date('F j, Y, g:i a', strtotime($share['expiration']))) ?></p></div>
|
||||
<section class="content-panel media-panel">
|
||||
<article class="col-12">
|
||||
@@ -293,8 +287,6 @@ function formatBytes($bytes, $precision = 2) {
|
||||
|
||||
<?php renderWorkspaceEnd(); ?>
|
||||
|
||||
|
||||
|
||||
<script>
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
const mediaElement = document.querySelector('video, audio');
|
||||
@@ -312,4 +304,4 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user