mirror of
https://github.com/lrsjng/h5ai.git
synced 2025-06-02 16:19:48 -04:00
Adds workaround to use direct POST-request downloads.
This commit is contained in:
parent
adce6f19c4
commit
ab45b3072c
3 changed files with 12 additions and 116 deletions
|
@ -100,57 +100,6 @@ class Api {
|
|||
}
|
||||
|
||||
|
||||
else if ($action === "createArchive") {
|
||||
|
||||
json_fail(1, "downloads disabled", !$options["download"]["enabled"]);
|
||||
|
||||
list($format, $hrefs) = use_request_params(array("format", "hrefs"));
|
||||
|
||||
normalized_require_once("/server/php/inc/Archive.php");
|
||||
$archive = new Archive($this->app);
|
||||
|
||||
$hrefs = explode("|:|", trim($hrefs));
|
||||
$target = $archive->create($format, $hrefs);
|
||||
|
||||
if (!is_string($target)) {
|
||||
json_fail($target, "package creation failed");
|
||||
}
|
||||
|
||||
json_exit(array("id" => basename($target), "size" => filesize($target)));
|
||||
}
|
||||
|
||||
|
||||
else if ($action === "getArchive") {
|
||||
|
||||
json_fail(1, "downloads disabled", !$options["download"]["enabled"]);
|
||||
|
||||
list($id, $as) = use_request_params(array("id", "as"));
|
||||
json_fail(2, "file not found", !preg_match("/^package-/", $id));
|
||||
|
||||
$target = $this->app->get_cache_abs_path() . "/" . $id;
|
||||
json_fail(3, "file not found", !file_exists($target));
|
||||
|
||||
header("Content-Type: application/octet-stream");
|
||||
header("Content-Length: " . filesize($target));
|
||||
header("Content-Disposition: attachment; filename=\"$as\"");
|
||||
header("Connection: close");
|
||||
register_shutdown_function("delete_tempfile", $target);
|
||||
|
||||
// readfile($target);
|
||||
|
||||
// Send data in small segments of 16MB to not hit PHP's memory limit (default: 128M)
|
||||
if ($fd = fopen($target, 'rb')) {
|
||||
set_time_limit(0);
|
||||
while (!feof($fd)) {
|
||||
print fread($fd, 1024 * 1024 * 16);
|
||||
ob_flush();
|
||||
flush();
|
||||
}
|
||||
fclose($fd);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
else if ($action === "passArchive") {
|
||||
|
||||
json_fail(1, "downloads disabled", !$options["download"]["enabled"]);
|
||||
|
|
|
@ -41,35 +41,6 @@ class Archive {
|
|||
}
|
||||
|
||||
|
||||
// public function create($format, $hrefs) {
|
||||
|
||||
// $this->dirs = array();
|
||||
// $this->files = array();
|
||||
|
||||
// $this->add_hrefs($hrefs);
|
||||
|
||||
// if (count($this->dirs) === 0 && count($this->files) === 0) {
|
||||
// return 404;
|
||||
// }
|
||||
|
||||
// $target = $this->app->get_cache_abs_path() . "/package-" . sha1(microtime(true) . rand()) . "." . $format;
|
||||
|
||||
// try {
|
||||
// $archive = new PharData($target);
|
||||
// foreach ($this->dirs as $archived_dir) {
|
||||
// $archive->addEmptyDir($archived_dir);
|
||||
// }
|
||||
// foreach ($this->files as $real_file => $archived_file) {
|
||||
// $archive->addFile($real_file, $archived_file); // very, very slow :/
|
||||
// }
|
||||
// } catch (Exeption $err) {
|
||||
// return 500;
|
||||
// }
|
||||
|
||||
// return @filesize($target) ? $target : null;
|
||||
// }
|
||||
|
||||
|
||||
private function shell_cmd($cmd) {
|
||||
|
||||
$cmd = str_replace("[ROOTDIR]", "\"" . $this->app->get_abs_path() . "\"", $cmd);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue