Add Zotero.FullText.canIndex()

Currently identical to canReindex(), but in theory attachments aren't
supposed to be reindexable if they're already fully indexed
This commit is contained in:
Dan Stillman 2024-01-13 07:38:34 -05:00
parent 3338b4b285
commit 3b9afcc500
2 changed files with 25 additions and 20 deletions

View file

@ -1427,19 +1427,26 @@ Zotero.Fulltext = Zotero.FullText = new function(){
} }
this.canIndex = function (item) {
if (!item.isAttachment()
|| item.attachmentLinkMode == Zotero.Attachments.LINK_MODE_LINKED_URL) {
return false;
}
var contentType = item.attachmentContentType;
return contentType
&& (contentType == 'application/pdf'
|| contentType == 'application/epub+zip'
|| Zotero.MIME.isTextType(contentType));
};
/* /*
* Returns true if an item can be reindexed * Returns true if an item can be reindexed
* *
* Item must be a non-web-link attachment that isn't already fully indexed * Item must be a non-web-link attachment that isn't already fully indexed
*/ */
this.canReindex = Zotero.Promise.coroutine(function* (item) { this.canReindex = Zotero.Promise.coroutine(function* (item) {
if (item.isAttachment() if (!item.canIndex(item)) {
&& item.attachmentLinkMode != Zotero.Attachments.LINK_MODE_LINKED_URL) {
let contentType = item.attachmentContentType;
if (!contentType
|| contentType != 'application/pdf'
&& contentType != 'application/epub+zip'
&& !Zotero.MIME.isTextType(contentType)) {
return false; return false;
} }
switch (yield this.getIndexedState(item)) { switch (yield this.getIndexedState(item)) {
@ -1447,12 +1454,10 @@ Zotero.Fulltext = Zotero.FullText = new function(){
case this.INDEX_STATE_UNINDEXED: case this.INDEX_STATE_UNINDEXED:
case this.INDEX_STATE_PARTIAL: case this.INDEX_STATE_PARTIAL:
case this.INDEX_STATE_QUEUED: case this.INDEX_STATE_QUEUED:
// TODO: automatically reindex already-indexed attachments? // TODO: automatically reindex already-indexed attachments?
case this.INDEX_STATE_INDEXED: case this.INDEX_STATE_INDEXED:
return true; return true;
} }
}
return false; return false;
}); });

View file

@ -120,7 +120,7 @@ Zotero.MIME = new function(){
function isTextType(mimeType) { function isTextType(mimeType) {
return mimeType.substr(0, 5) == 'text/' || _textTypes[mimeType]; return mimeType.substr(0, 5) == 'text/' || mimeType in _textTypes;
} }
this.isWebPageType = function(mimeType) { this.isWebPageType = function(mimeType) {