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:
parent
3338b4b285
commit
3b9afcc500
2 changed files with 25 additions and 20 deletions
|
@ -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
|
||||
*
|
||||
* Item must be a non-web-link attachment that isn't already fully indexed
|
||||
*/
|
||||
this.canReindex = Zotero.Promise.coroutine(function* (item) {
|
||||
if (item.isAttachment()
|
||||
&& 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)) {
|
||||
if (!item.canIndex(item)) {
|
||||
return false;
|
||||
}
|
||||
switch (yield this.getIndexedState(item)) {
|
||||
|
@ -1447,12 +1454,10 @@ Zotero.Fulltext = Zotero.FullText = new function(){
|
|||
case this.INDEX_STATE_UNINDEXED:
|
||||
case this.INDEX_STATE_PARTIAL:
|
||||
case this.INDEX_STATE_QUEUED:
|
||||
|
||||
// TODO: automatically reindex already-indexed attachments?
|
||||
case this.INDEX_STATE_INDEXED:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
});
|
||||
|
||||
|
|
|
@ -120,7 +120,7 @@ Zotero.MIME = new function(){
|
|||
|
||||
|
||||
function isTextType(mimeType) {
|
||||
return mimeType.substr(0, 5) == 'text/' || _textTypes[mimeType];
|
||||
return mimeType.substr(0, 5) == 'text/' || mimeType in _textTypes;
|
||||
}
|
||||
|
||||
this.isWebPageType = function(mimeType) {
|
||||
|
|
Loading…
Reference in a new issue