Move magic type checking into functions.php

This commit is contained in:
Junior 2026-11-21 16:00:42 -05:00
parent 93235c92ab
commit ebb5325f99
2 changed files with 17 additions and 10 deletions

View File

@ -75,13 +75,8 @@ if ( !is_dir($comicoutputfull) ) {
}
if ( !$extracted ) {
$magic = file_get_contents($comicfull, false, null, 0, 4);
if ( substr($magic, 0, 2) === "PK" ) {
$comtype = "cbz";
} elseif ( $magic === "Rar!" ) {
$comtype = "cbr";
}
if ( $comtype == "cbz" ) {
$comtype = getComicType($comicfull);
if ( $comtype === COMICZIP ) {
$zip = new ZipArchive();
$opened = $zip->open($comicfull);
if ( !$opened ) {
@ -101,7 +96,7 @@ if ( !$extracted ) {
}
$zip->close();
}
} elseif ( $comtype == "cbr" ) {
} elseif ( $comtype === COMICRAR ) {
$rar = RarArchive::open($comicfull);
if ( $rar === false ) {
$data["error"] = true;

View File

@ -19,6 +19,17 @@ function safeFileName($file = "") {
return str_replace($to_remove, "", $file);
}
function getComicType(string $file = null): String|false {
$magic = file_get_contents($file, false, null, 0, 4);
$type = false;
if ( substr($magic, 0, 2) === "PK" ) {
$type = "cbz";
} elseif ( $magic === "Rar!" ) {
$type = "cbr";
}
return $type;
}
function makeThumb($item = "") {
if ( $item == "" ) { return false; }
$prefix = (substr(getcwd(), -4) == "ajax") ? "../" : "";
@ -51,7 +62,8 @@ function makeThumb($item = "") {
} else {
return false;
}
if ( substr($comic, -3) == "cbz" ) {
$comtype = getComicType($comic);
if ( $comtype === COMICZIP ) {
$zip = new ZipArchive();
$opened = $zip->open($comic);
if ( !$opened ) { return false; }
@ -72,7 +84,7 @@ function makeThumb($item = "") {
if ( is_null($imgdata) ) return false;
$didwrite = file_put_contents($outfile, $imgdata);
if ( !$didwrite ) return false;
} elseif ( substr($comic, -3) == "cbr" ) {
} elseif ( $comtype === COMICRAR ) {
$rar_file = RarArchive::open($comic);
if ( $rar_file === false ) { return false; }
$entries = $rar_file->getEntries();