Add support for arbitrary zip files
This commit is contained in:
@@ -47,6 +47,12 @@ function get_zip_meta($path): array {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$meta = fread($fp, unpack("V", substr($zipHdr2, 18, 4))[1]);
|
$meta = fread($fp, unpack("V", substr($zipHdr2, 18, 4))[1]);
|
||||||
|
fclose($fp);
|
||||||
|
return array($meta, $version);
|
||||||
|
}
|
||||||
|
|
||||||
|
function get_zip_files($path, $skip=0): string {
|
||||||
|
$fp = fopen($path, "rb");
|
||||||
$files = "{";
|
$files = "{";
|
||||||
$first = true;
|
$first = true;
|
||||||
while (!feof($fp)) {
|
while (!feof($fp)) {
|
||||||
@@ -59,6 +65,7 @@ function get_zip_meta($path): array {
|
|||||||
$crc = unpack("V", substr($zipHdr3, 14, 4))[1];
|
$crc = unpack("V", substr($zipHdr3, 14, 4))[1];
|
||||||
fseek($fp, $compSize, SEEK_CUR);
|
fseek($fp, $compSize, SEEK_CUR);
|
||||||
$hex = substr("00000000" . dechex($crc), -8);
|
$hex = substr("00000000" . dechex($crc), -8);
|
||||||
|
if ($skip-- > 0) continue;
|
||||||
if (!$first) $files .= ", ";
|
if (!$first) $files .= ", ";
|
||||||
$files .= "\"$name\": {\"compressed_size\": $compSize, \"uncompressed_size\": $uncompSize, \"crc32\": \"$hex\"}";
|
$files .= "\"$name\": {\"compressed_size\": $compSize, \"uncompressed_size\": $uncompSize, \"crc32\": \"$hex\"}";
|
||||||
$first = false;
|
$first = false;
|
||||||
@@ -66,7 +73,7 @@ function get_zip_meta($path): array {
|
|||||||
$files .= "}";
|
$files .= "}";
|
||||||
|
|
||||||
fclose($fp);
|
fclose($fp);
|
||||||
return array($meta, $version, $files);
|
return $files;
|
||||||
}
|
}
|
||||||
|
|
||||||
$path = $_SERVER['PATH_INFO'];
|
$path = $_SERVER['PATH_INFO'];
|
||||||
@@ -183,8 +190,12 @@ foreach ($clients as $c) {
|
|||||||
$datetime = '"' . $dt->format(DateTimeInterface::RFC3339) . '"';
|
$datetime = '"' . $dt->format(DateTimeInterface::RFC3339) . '"';
|
||||||
$zwstid = "\"$parts[2]\"";
|
$zwstid = "\"$parts[2]\"";
|
||||||
}
|
}
|
||||||
list($meta, $version, $files) = get_zip_meta($path);
|
list($meta, $version) = get_zip_meta($path);
|
||||||
$files ??= "null";
|
if (str_ends_with($file, ".zip")) {
|
||||||
|
$files = get_zip_files($path, $meta !== 'null' ? 2 : 0);
|
||||||
|
} else {
|
||||||
|
$files = "null";
|
||||||
|
}
|
||||||
$version ??= "null";
|
$version ??= "null";
|
||||||
echo " {\"name\": \"$file\", \"timestamp\": $datetime, \"zwstid\": $zwstid, \"meta\": $meta, \"files\": $files, " .
|
echo " {\"name\": \"$file\", \"timestamp\": $datetime, \"zwstid\": $zwstid, \"meta\": $meta, \"files\": $files, " .
|
||||||
"\"version\": $version, \"url\": \"$url\", \"size\": $size, \"created\": \"$cre\", \"modified\": \"$mod\"}";
|
"\"version\": $version, \"url\": \"$url\", \"size\": $size, \"created\": \"$cre\", \"modified\": \"$mod\"}";
|
||||||
|
Reference in New Issue
Block a user