Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add pdf attachment items to sqs for text extraction #142

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions controllers/ItemsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -1128,6 +1128,8 @@ private function _handleFileRequest($item) {

Zotero_DB::commit();

$this->_addToPDFIndexingQueueIfNeeded($info, $item->key);

header("HTTP/1.1 204 No Content");
header("Last-Modified-Version: " . $item->version);
exit;
Expand Down Expand Up @@ -1181,6 +1183,8 @@ private function _handleFileRequest($item) {

Zotero_DB::commit();

$this->_addToPDFIndexingQueueIfNeeded($info, $item->key);

header("HTTP/1.1 204 No Content");
exit;
}
Expand All @@ -1189,4 +1193,25 @@ private function _handleFileRequest($item) {
}
exit;
}

// If it's a PDF and request is not from desktop app, add it to SQS
// to be processed by full-text-extractor
private function _addToPDFIndexingQueueIfNeeded($info, $itemKey) {
if ( ($info->contentType != "application/pdf" && !strpos($info->filename, ".pdf")) || !empty($_SERVER['HTTP_X_ZOTERO_VERSION'])) {
return;
}
if (Z_CONFIG::$SQS_URL == '') {
return;
}
$payload = [
"fileName" => $info->hash,
"itemKey" => $itemKey];
if (isset($this->objectGroupID)) {
$payload['groupID'] = $this->objectGroupID;
}
else {
$payload['userID'] = $this->userID;
}
Z_SQS::send(Z_CONFIG::$SQS_URL, json_encode($payload));
}
}
2 changes: 1 addition & 1 deletion include/SQS.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public static function deleteBatch($queueURL, $batchEntries) {

private static function load() {
if (!self::$sqs) {
self::$sqs = Z_Core::$AWS->get('sqs');
self::$sqs = Z_Core::$AWS->createSQS();
}
}
}
3 changes: 2 additions & 1 deletion include/config/config.inc.php-sample
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ class Z_CONFIG {
public static $S3_BUCKET_FULLTEXT = '';
public static $S3_BUCKET_ERRORS = '';
public static $SNS_ALERT_TOPIC = '';

public static $SQS_URL = '';

public static $REDIS_HOSTS = [
'default' => [
'host' => 'redis1.localdomain:6379'
Expand Down