Slight refactoring

This commit is contained in:
Sheldon Lee 2023-11-13 22:47:14 +08:00
parent 792b9c875f
commit 2bfa19fe24

View File

@ -24,8 +24,6 @@ define("VIDEO_EXTENSIONS", [
define("FILE_EXTENSIONS", array_merge(IMAGE_EXTENSIONS, VIDEO_EXTENSIONS)); define("FILE_EXTENSIONS", array_merge(IMAGE_EXTENSIONS, VIDEO_EXTENSIONS));
main();
function main(): void { function main(): void {
$data = json_decode(file_get_contents('php://input'), true); $data = json_decode(file_get_contents('php://input'), true);
$array = []; $array = [];
@ -42,15 +40,17 @@ function main(): void {
$is_dir = is_dir(ROOT_DIR.IMG_DIR.$path); $is_dir = is_dir(ROOT_DIR.IMG_DIR.$path);
if (!$is_dir && !is_valid_file_type($file)) continue; if (!$is_dir && !is_valid_file_type($file)) continue;
$url = ROOT_URL.IMG_DIR.$path;
$thumbnail_url = null;
if (!$is_dir) {
$thumbnail_url = create_thumbnail($category, $file);
}
$file_item = []; $file_item = [];
$file_item["is_dir"] = $is_dir; $file_item["is_dir"] = $is_dir;
if ($is_dir) { $file_item["url"] = $url;
$file_item["url"] = ROOT_URL.IMG_DIR.$path; $file_item["thumbnail_url"] = $thumbnail_url;
$file_item["thumbnail_url"] = null;
} else {
$file_item["url"] = ROOT_URL.IMG_DIR.$path;
$file_item["thumbnail_url"] = create_thumbnail($category, $file);
}
array_push($array, $file_item); array_push($array, $file_item);
} }
@ -67,7 +67,7 @@ function create_thumbnail(string $category, string $file): string | null {
$thumbnail_file = $thumbnail_directory.$file; $thumbnail_file = $thumbnail_directory.$file;
if (file_exists($thumbnail_file)) { if (file_exists($thumbnail_file)) {
log_print("$thumbnail_file exists, skipping gneeration"); log_print("$thumbnail_file exists, skipping generation");
goto return_thumbnail; goto return_thumbnail;
} }
@ -108,5 +108,6 @@ function is_image_file_type(string $filename): bool {
} }
return false; return false;
} }
?>
main();
?>