Submit derive task after all uploads completed

This commit is contained in:
2026-06-05 12:56:11 +01:00
parent 34d8014bac
commit 44995c4e6a
5 changed files with 78 additions and 3 deletions
+13
View File
@@ -0,0 +1,13 @@
vendor
public/sys.css
public/app.js
pdf
uploads
cache
database
download
package-lock.json
composer.lock
attachments
node_modules
.env
+23
View File
@@ -64,6 +64,29 @@ class ArchiveJob extends Job {
$doc->save(); $doc->save();
} }
try {
$this->status("Waiting for bucket creation");
$done = 0;
while ($done == 0) {
sleep(1);
$md = Archive::metadata($id);
if (property_exists($md, "created")) {
$done = 1;
}
}
} catch (Exception $e) {
$this->fail($e->getMessage());
return;
}
try {
Archive::derive($id);
} catch (Exception $e) {
$this->fail($e->getMessage());
return;
}
$this->finish(); $this->finish();
} }
+28 -3
View File
@@ -26,7 +26,7 @@ class Archive {
} }
} }
throw new Exception("Error $resp processing tasks"); throw new Exception($req->body);
} }
static function upload(File $file, $identifier, $filename, $metadata = [], ?Callable $callback = null) { static function upload(File $file, $identifier, $filename, $metadata = [], ?Callable $callback = null) {
@@ -56,6 +56,8 @@ class Archive {
} }
} }
$headers[] = "content-type:application/pdf";
$req = new HTTPRequest(); $req = new HTTPRequest();
if ($callback) { if ($callback) {
@@ -66,7 +68,7 @@ class Archive {
if ($resp == 200) { if ($resp == 200) {
return true; return true;
} }
throw new Exception($req->body); throw new Exception($resp . ": " . $req->body);
} }
static function metadata($identifier) { static function metadata($identifier) {
@@ -84,7 +86,30 @@ class Archive {
} }
} }
throw new Exception("Error " . $resp . " during metadata get"); throw new Exception($resp . ": " . $req->body);
}
static function derive($identifier) {
$req = new HTTPRequest();
$data = [
"identifier" => $identifier,
"cmd" => "derive.php",
"args" => [],
"priority" => 0
];
$resp = $req->post("https://archive.org/services/tasks.php", json_encode($data), [
"Authorization: LOW " . Config::get("ARCHIVE_KEY") . ":" . Config::get("ARCHIVE_SECRET"),
"content-type:application/json",
]);
if ($resp == 200) {
return true;
}
throw new Exception($resp . ": " . $req->body);
} }
} }
+4
View File
@@ -72,6 +72,10 @@ abstract class Job {
// Mark the job as failed miserably // Mark the job as failed miserably
public function fail($message = "") { public function fail($message = "") {
if (is_terminal()) {
print(" !! " . $message . "\n");
}
$db = DB::getInstance(); $db = DB::getInstance();
if ($message != "") { if ($message != "") {
$db->update("job", $this->_jobid, [ $db->update("job", $this->_jobid, [
+10
View File
@@ -0,0 +1,10 @@
RewriteEngine On
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Send Requests To Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]