mirror of
https://github.com/lrsjng/h5ai.git
synced 2025-08-20 03:51:23 +02:00
Changes temp dir to cache dir. Adds auto deletion of temp packages.
This commit is contained in:
@@ -31,6 +31,9 @@ function check_keys($keys) {
|
|||||||
return $values;
|
return $values;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function delete_tempfile($file) {
|
||||||
|
@unlink($file);
|
||||||
|
}
|
||||||
|
|
||||||
list($action) = check_keys(array("action"));
|
list($action) = check_keys(array("action"));
|
||||||
|
|
||||||
@@ -83,15 +86,16 @@ else if ($action === "getarchive") {
|
|||||||
json_fail(1, "downloads disabled", !$options["download"]["enabled"]);
|
json_fail(1, "downloads disabled", !$options["download"]["enabled"]);
|
||||||
|
|
||||||
list($id, $as) = check_keys(array("id", "as"));
|
list($id, $as) = check_keys(array("id", "as"));
|
||||||
json_fail(2, "file not found", !preg_match("/^h5ai-selection-/", $id));
|
json_fail(2, "file not found", !preg_match("/^package-/", $id));
|
||||||
|
|
||||||
$target = H5ai::normalize_path(sys_get_temp_dir(), true) . $id;
|
$target = $h5ai->getTempAbsPath() . "/" . $id;
|
||||||
json_fail(3, "file not found", !file_exists($target));
|
json_fail(3, "file not found", !file_exists($target));
|
||||||
|
|
||||||
header("Content-Type: application/octet-stream");
|
header("Content-Type: application/octet-stream");
|
||||||
header("Content-Length: " . filesize($target));
|
header("Content-Length: " . filesize($target));
|
||||||
header("Content-Disposition: attachment; filename=\"$as\"");
|
header("Content-Disposition: attachment; filename=\"$as\"");
|
||||||
header("Connection: close");
|
header("Connection: close");
|
||||||
|
register_shutdown_function("delete_tempfile", $target);
|
||||||
readfile($target);
|
readfile($target);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -105,8 +109,8 @@ else if ($action === "getchecks") {
|
|||||||
$gdinfo = gd_info();
|
$gdinfo = gd_info();
|
||||||
$gd = array_key_exists("JPG Support", $gdinfo) && $gdinfo["JPG Support"] || array_key_exists("JPEG Support", $gdinfo) && $gdinfo["JPEG Support"];
|
$gd = array_key_exists("JPG Support", $gdinfo) && $gdinfo["JPG Support"] || array_key_exists("JPEG Support", $gdinfo) && $gdinfo["JPEG Support"];
|
||||||
}
|
}
|
||||||
$cache = @is_writable($h5ai->getH5aiAbsPath() . "/cache");
|
$cache = @is_writable($h5ai->getCacheAbsPath());
|
||||||
$temp = @is_writable(sys_get_temp_dir());
|
$temp = @is_writable($h5ai->getTempAbsPath());
|
||||||
$tar = @preg_match("/tar$/", `which tar`) > 0;
|
$tar = @preg_match("/tar$/", `which tar`) > 0;
|
||||||
$zip = @preg_match("/zip$/", `which zip`) > 0;
|
$zip = @preg_match("/zip$/", `which zip`) > 0;
|
||||||
$convert = @preg_match("/convert$/", `which convert`) > 0;
|
$convert = @preg_match("/convert$/", `which convert`) > 0;
|
||||||
|
@@ -29,7 +29,7 @@ class Archive {
|
|||||||
return 404;
|
return 404;
|
||||||
}
|
}
|
||||||
|
|
||||||
$target = H5ai::normalize_path(sys_get_temp_dir(), true) . "h5ai-selection-" . microtime(true) . rand() . "." . $format;
|
$target = $this->h5ai->getTempAbsPath() . "/package-" . sha1(microtime(true) . rand()) . "." . $format;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if ($execution === "shell") {
|
if ($execution === "shell") {
|
||||||
|
@@ -86,6 +86,19 @@ class H5ai {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function getCacheAbsPath() {
|
||||||
|
|
||||||
|
return $this->h5aiAbsPath . '/cache';
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function getTempAbsPath() {
|
||||||
|
|
||||||
|
// return H5ai::normalize_path(sys_get_temp_dir());
|
||||||
|
return $this->h5aiAbsPath . '/cache';
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public function getRootAbsHref() {
|
public function getRootAbsHref() {
|
||||||
|
|
||||||
return $this->rootAbsHref;
|
return $this->rootAbsHref;
|
||||||
|
@@ -72,7 +72,7 @@ class Thumb {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
$captureAbsPath = $this->h5ai->getH5aiAbsPath() . "/cache/capture-" . sha1($sourceAbsPath) . ".jpg";
|
$captureAbsPath = $this->h5ai->getCacheAbsPath() . "/capture-" . sha1($sourceAbsPath) . ".jpg";
|
||||||
|
|
||||||
if (!file_exists($captureAbsPath) || filemtime($sourceAbsPath) >= filemtime($captureAbsPath)) {
|
if (!file_exists($captureAbsPath) || filemtime($sourceAbsPath) >= filemtime($captureAbsPath)) {
|
||||||
$cmd = str_replace("[SOURCE]", $sourceAbsPath, $cmd);
|
$cmd = str_replace("[SOURCE]", $sourceAbsPath, $cmd);
|
||||||
|
Reference in New Issue
Block a user