Submit derive task after all uploads completed
This commit is contained in:
+13
@@ -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
|
||||
@@ -64,6 +64,29 @@ class ArchiveJob extends Job {
|
||||
$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();
|
||||
}
|
||||
|
||||
|
||||
+28
-3
@@ -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) {
|
||||
@@ -56,6 +56,8 @@ class Archive {
|
||||
}
|
||||
}
|
||||
|
||||
$headers[] = "content-type:application/pdf";
|
||||
|
||||
|
||||
$req = new HTTPRequest();
|
||||
if ($callback) {
|
||||
@@ -66,7 +68,7 @@ class Archive {
|
||||
if ($resp == 200) {
|
||||
return true;
|
||||
}
|
||||
throw new Exception($req->body);
|
||||
throw new Exception($resp . ": " . $req->body);
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -72,6 +72,10 @@ abstract class Job {
|
||||
|
||||
// Mark the job as failed miserably
|
||||
public function fail($message = "") {
|
||||
if (is_terminal()) {
|
||||
print(" !! " . $message . "\n");
|
||||
}
|
||||
|
||||
$db = DB::getInstance();
|
||||
if ($message != "") {
|
||||
$db->update("job", $this->_jobid, [
|
||||
|
||||
@@ -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]
|
||||
Reference in New Issue
Block a user