Exemplo n.º 1
0
function sqsPutMessage($id, $sourceUrl, $name, $callbackUrl, $callbackPassword, $email, $format, $formatParams, $fileType, $contentType)
{
    global $awsApiKey, $awsApiSecretKey, $awsSQSQueue, $awsSQSTimeout;
    $sqs = new SQSClient($awsApiKey, $awsApiSecretKey, 'http://queue.amazonaws.com');
    try {
        // Create the queue.  TODO: If the queue has recently been deleted,
        // the application needs to wait for 60 seconds before
        $sqs->CreateQueue($awsSQSQueue);
        $logName = getStorageName($id, $format, ".txt");
        $extension = ".{$fileType}";
        if ($contentType == "application/zip") {
            $extension = ".zip";
        }
        $fileName = getStorageName($id, $format, $extension);
        // Send a message to the queue
        $message = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><fb2pdfjob version=\"4\">" . "<source url=\"{$sourceUrl}\" type=\"application/fb2+xml\" name=\"{$name}\"/>" . "<result key=\"{$id}\" encoding=\"{$contentType}\" name=\"{$fileName}\" filetype=\"{$fileType}\"/>" . "<log key=\"{$logName}\"/>" . "<callback url=\"{$callbackUrl}\" method=\"POST\" params=\"pass={$callbackPassword}&amp;email={$email}&amp;format={$format}\"/>";
        foreach (array_keys($formatParams) as $name) {
            $value = $formatParams[$name];
            $message .= "<parameter name=\"{$name}\" value=\"{$value}\"/>";
        }
        $message .= "</fb2pdfjob>";
        $sqs->SendMessage(base64_encode($message));
    } catch (Exception $e) {
        $err_str = $e->getMessage();
        error_log("FB2PDF ERROR. sqshelper: " . $err_str);
        return false;
    }
    return true;
}
Exemplo n.º 2
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;
 }
Exemplo n.º 3
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!
     }
 }