Add fole check endpoint & Update dependencies

This commit is contained in:
2026-08-05 22:01:32 +02:00
parent 0702d445b2
commit b8f7bc48e1
10 changed files with 2378 additions and 1506 deletions
+40 -8
View File
@@ -9,7 +9,6 @@ use Illuminate\Support\Facades\Storage;
class ApiController extends Controller
{
/**
* Get Filesize of File
*/
@@ -19,7 +18,7 @@ class ApiController extends Controller
// Decrypt Hash
$file = Crypt::decryptString($folderhash);
$time = Crypt::decryptString($timehash);
} catch (DecryptException $e) {
} catch (DecryptException $e) {
return response()->json([
'error' => 'Invalid Token!',
], 500);
@@ -32,7 +31,7 @@ class ApiController extends Controller
], 404);
}
if (!Storage::exists($file)) {
if (! Storage::exists($file)) {
return response()->json([
'error' => 'File not found!',
], 404);
@@ -44,7 +43,39 @@ class ApiController extends Controller
}
/**
* Download File
* Check if a storage path exists
*/
public function checkPath(string $folderhash, string $timehash): \Illuminate\Http\JsonResponse
{
try {
$path = Crypt::decryptString($folderhash);
$time = Crypt::decryptString($timehash);
} catch (DecryptException $e) {
return response()->json(['valid' => false, 'error' => 'Invalid Token!'], 422);
}
if (Carbon::now() > Carbon::parse($time)) {
return response()->json(['valid' => false, 'error' => 'Link has expired!'], 410);
}
// Defensive: reject traversal; only allow the known prefixes / year dirs.
if (str_contains($path, '..')) {
return response()->json(['valid' => false, 'error' => 'Invalid path!'], 422);
}
if (! Storage::exists($path)) {
return response()->json(['valid' => false, 'error' => 'File not found!'], 404);
}
return response()->json([
'valid' => true,
'type' => Storage::directoryExists($path) ? 'directory' : 'file',
'size' => Storage::directoryExists($path) ? null : Storage::size($path),
]);
}
/**
* Download File
*/
public function download(string $folderhash, string $timehash)
{
@@ -63,26 +94,27 @@ class ApiController extends Controller
}
$filename = explode('/', $file);
$filePath = storage_path('app/' . $file);
$filePath = storage_path('app/'.$file);
$headers = [
'Content-Type' => Storage::mimeType($file),
'Content-Length' => Storage::size($file),
'Content-Disposition' => 'attachment; filename="' . end($filename) . '"',
'Content-Disposition' => 'attachment; filename="'.end($filename).'"',
];
// Stream the file in chunks to prevent memory issues
return response()->stream(
function () use ($filePath) {
$fd = fopen($filePath, 'rb');
while (!feof($fd)) {
while (! feof($fd)) {
echo fread($fd, 2048);
}
},
200,
$headers
);
} catch (DecryptException $e) { }
} catch (DecryptException $e) {
}
return view('error', ['error' => 'Invalid Token!']);
}