From d5b737fb2c38bffa64261f21b519384f48d6aed9 Mon Sep 17 00:00:00 2001 From: Adrian Schubek Date: Wed, 29 May 2024 20:00:45 +0200 Subject: [PATCH] feat: add folder list json api --- src/index.php | 114 +++++++++++++++++++++++++++++--------------------- 1 file changed, 67 insertions(+), 47 deletions(-) diff --git a/src/index.php b/src/index.php index df83c50..1a55342 100644 --- a/src/index.php +++ b/src/index.php @@ -123,6 +123,23 @@ public function __toString(): string $sorted_files = array_reverse($sorted_files); $[end]$ $sorted = array_merge($sorted_folders, $sorted_files); + + // if list request return json + if(isset($_REQUEST["ls"])) { + $info = []; + foreach ($sorted as $file) { + $info[] = [ + "url" => $file->url, + "name" => $file->name, + "type" => $file->is_dir ? "dir" : "file", + "size" => $file->size, + "modified" => $file->modified_date, + "downloads" => $[if `!process.env.NO_DL_COUNT`]$ intval($redis->get($file->url))$[else]$0$[end]$ + ]; + } + header("Content-Type: application/json"); + die(json_encode($info)); + } } elseif (file_exists($local_path)) { // local path is file. serve it directly using nginx @@ -175,7 +192,7 @@ public function __toString(): string "mime" => mime_content_type($local_path) ?? "application/octet-stream", "size" => filesize($local_path), "modified" => filemtime($local_path), - "downloads" => $[if `!process.env.NO_DL_COUNT`]$$redis->get($relative_path)$[else]$0$[end]$, + "downloads" => $[if `!process.env.NO_DL_COUNT`]$ intval($redis->get($relative_path))$[else]$0$[end]$, "hash" => $[if `process.env.HASH`]$hash_file('sha256', $local_path)$[else]$null$[end]$ ]; header("Content-Type: application/json"); @@ -293,49 +310,15 @@ public function __toString(): string - - -
-
+

Protected file

Please enter the password to access this file.

- - + +
@@ -367,20 +350,19 @@ public function __toString(): string ?>
-
-
Name
- $[if `!process.env.NO_DL_COUNT`]$
Downloads
$[end]$ -
Size
-
Last Modified
- +
+ Name + $[if `!process.env.NO_DL_COUNT`]$Downloads$[end]$ + Size + Modified
is_dir) { ?>
$[if `!process.env.NO_DL_COUNT`]$ - "> + "> dl_count) ?> @@ -620,6 +602,44 @@ function toggletheme() { // TODO: sorting + +