Esempio n. 1
0
 public function checkConverted($key, $format, $fileType = "", $contentType = "")
 {
     global $awsS3Bucket;
     if ($fileType == "" or $contentType == "") {
         // update status in the DB
         $db = getDBObject();
         $formatInfo = $db->getFormat($format);
         $fileType = $formatInfo["file_type"];
         $contentType = $formatInfo["content_type"];
     }
     // check existance
     $s3 = getS3Object();
     $pdfName = getStorageName($key, $format, ".pdf");
     if ($contentType == "application/zip") {
         $convName = getStorageName($key, $format, ".zip");
     } else {
         $convName = getStorageName($key, $format, ".{$fileType}");
     }
     $logName = getStorageName($key, $format, ".txt");
     // PDFs can be found only for books that where added through early versions of fb2pdf,
     // when there was no support for formats. There is no need to query them
     // if format is set to semething other then 1.
     $pdfExists = $format == 1 && $s3->objectExists($awsS3Bucket, $pdfName);
     $convExists = $s3->objectExists($awsS3Bucket, $convName);
     $logExists = $s3->objectExists($awsS3Bucket, $logName);
     // check status and generate links
     $status = self::STATUS_PROGRESS;
     if (($pdfExists or $convExists) and $logExists) {
         $status = self::STATUS_SUCCESS;
         $this->convFile = $pdfExists ? "getfile.php?key={$pdfName}" : "getfile.php?key={$convName}";
         $this->logFile = "getfile.php?key={$logName}";
     } else {
         if ($logExists) {
             $status = self::STATUS_ERROR;
             $this->logFile = "getfile.php?key={$logName}";
         }
     }
     return $status;
 }
Esempio n. 2
0
 private function updateFormat($format)
 {
     global $awsS3Bucket;
     // update book status in the DB
     $db = getDBObject();
     if (!$db->updateBookStatus($this->bookKey, "p", 0, $format)) {
         error_log("FB2PDF ERROR. Callback: Unable to update book status. Key=\${$this->bookKey}");
         // do not stop if DB is failed!
     }
     $s3 = getS3Object();
     $zipFile = getStorageName($this->bookKey, $format, ".zip");
     if (!$s3->deleteObject($awsS3Bucket, $zipFile)) {
         error_log("FB2PDF ERROR. Unable to delete converted file {$zipFile} from the Amazon S3 storage.");
         // do not stop if failed!
     }
     $txtFile = getStorageName($this->bookKey, $format, ".txt");
     if (!$s3->deleteObject($awsS3Bucket, $txtFile)) {
         error_log("FB2PDF ERROR. Unable to delete log file {$txtFile} from the Amazon S3 storage.");
         // do not stop if failed!
     }
 }
Esempio n. 3
0
require_once '../utils.php';
if (!isset($_GET['key'])) {
    httpResponseCode("400 Bad Request", "Missing parameter \"key\"");
    die;
}
$key = $_GET['key'];
$pos = strrpos($key, ".");
if ($pos !== false) {
    $key = substr($key, 0, $pos);
}
$msg = "";
$db = getDBObject();
if (!$db->deleteBook($key . ".zip")) {
    $msg .= "<br>Unable to delete {$key}.zip from DB";
}
global $awsS3Bucket;
$s3 = getS3Object();
if (!$s3->deleteObject($awsS3Bucket, $key . ".fb2")) {
    $msg .= "<br>Unable to delete file {$key}.fb2 from Amazon S3";
}
if (!$s3->deleteObject($awsS3Bucket, $key . ".zip")) {
    $msg .= "<br>Unable to delete file {$key}.zip from Amazon S3";
}
if (!$s3->deleteObject($awsS3Bucket, $key . ".log")) {
    $msg .= "<br>Unable to delete file {$key}.log from Amazon S3";
}
if ($msg) {
    echo $msg;
} else {
    echo "Delete book {$key} - done.";
}