Fix lint issues in feedReader.js
This commit is contained in:
parent
bc4aafa8e4
commit
088483b776
1 changed files with 77 additions and 75 deletions
|
@ -56,7 +56,6 @@
|
|||
Zotero.FeedReader = function (url) {
|
||||
if (!url) throw new Error("Feed URL must be supplied");
|
||||
|
||||
|
||||
this._url = url;
|
||||
this._feedItems = [Zotero.Promise.defer()];
|
||||
this._feedProcessed = Zotero.Promise.defer();
|
||||
|
@ -93,7 +92,7 @@ Zotero.FeedReader = function(url) {
|
|||
if (issn) info.ISSN = issn;
|
||||
|
||||
let isbn = Zotero.FeedReader._getFeedField(feed, 'isbn', 'prism')
|
||||
|| Zotero.FeedReader._getFeedField(feed, 'isbn')
|
||||
|| Zotero.FeedReader._getFeedField(feed, 'isbn');
|
||||
if (isbn) info.ISBN = isbn;
|
||||
|
||||
let language = Zotero.FeedReader._getFeedField(feed, 'language', 'dc')
|
||||
|
@ -124,6 +123,7 @@ Zotero.FeedReader = function(url) {
|
|||
}.bind(this)).catch(function (e) {
|
||||
Zotero.debug("Feed processing failed " + e.message);
|
||||
this._feedProcessed.reject(e);
|
||||
// eslint-disable-next-line newline-per-chained-call
|
||||
}.bind(this)).finally(function () {
|
||||
// Make sure the last promise gets resolved to null
|
||||
let lastItem = this._feedItems[this._feedItems.length - 1];
|
||||
|
@ -137,12 +137,12 @@ Zotero.FeedReader = function(url) {
|
|||
let feedUrl = Services.io.newURI(url, null, null);
|
||||
feedProcessor.parseAsync(null, feedUrl);
|
||||
|
||||
feedProcessor.listener = {
|
||||
/*
|
||||
* MDN suggests that we could use nsIFeedProgressListener to handle the feed
|
||||
* as it gets loaded, but this is actually not implemented (as of 32.0.3),
|
||||
* so we have to load the whole feed and handle it in handleResult.
|
||||
*/
|
||||
feedProcessor.listener = {
|
||||
handleResult: (result) => {
|
||||
if (!result.doc) {
|
||||
this.terminate("No Feed");
|
||||
|
@ -161,7 +161,7 @@ Zotero.FeedReader = function(url) {
|
|||
Ci.nsILoadInfo.SEC_NORMAL, Ci.nsIContentPolicy.TYPE_OTHER);
|
||||
this._channel.loadFlags |= Components.interfaces.nsIRequest.LOAD_BYPASS_CACHE;
|
||||
this._channel.asyncOpen(feedProcessor, null); // Sends an HTTP request
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
* The constructor initiates async feed processing, but _feedProcessed
|
||||
|
@ -205,9 +205,9 @@ Zotero.FeedReader.prototype.terminate = function(status) {
|
|||
Zotero.defineProperty(Zotero.FeedReader.prototype, 'feedProperties', {
|
||||
get: function () {
|
||||
if (!this._feedProperties) {
|
||||
throw new Error("Feed has not been resolved yet. Try calling FeedReader#process first")
|
||||
throw new Error("Feed has not been resolved yet. Try calling FeedReader#process first");
|
||||
}
|
||||
return this._feedProperties
|
||||
return this._feedProperties;
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -222,11 +222,12 @@ Zotero.defineProperty(Zotero.FeedReader.prototype, 'feedProperties', {
|
|||
Zotero.defineProperty(Zotero.FeedReader.prototype, 'ItemIterator', {
|
||||
get: function () {
|
||||
let items = this._feedItems;
|
||||
// eslint-disable-next-line consistent-this
|
||||
let feedReader = this;
|
||||
|
||||
let iterator = function () {
|
||||
if (!feedReader._feedProperties) {
|
||||
throw new Error("Feed has not been resolved yet. Try calling FeedReader#process first")
|
||||
throw new Error("Feed has not been resolved yet. Try calling FeedReader#process first");
|
||||
}
|
||||
this.index = 0;
|
||||
};
|
||||
|
@ -241,7 +242,7 @@ Zotero.defineProperty(Zotero.FeedReader.prototype, 'ItemIterator', {
|
|||
|
||||
iterator.prototype.last = function () {
|
||||
return items[items.length - 1];
|
||||
}
|
||||
};
|
||||
|
||||
return iterator;
|
||||
}
|
||||
|
@ -301,11 +302,10 @@ Zotero.FeedReader._processCreators = function(feedEntry, field, role) {
|
|||
if (!name) continue;
|
||||
|
||||
let commas = name.split(',').length - 1,
|
||||
other = name.split(/\s(?:and|&)\s|;/).length - 1,
|
||||
separators = commas + other;
|
||||
if (personArr.length == 1 &&
|
||||
other = name.split(/\s(?:and|&)\s|;/).length - 1;
|
||||
if (personArr.length == 1
|
||||
// Has typical name separators
|
||||
(other || commas > 1
|
||||
&& (other || commas > 1
|
||||
// If only one comma and first part has more than one space,
|
||||
// it's probably not lastName, firstName
|
||||
|| (commas == 1 && name.split(/\s*,/)[0].indexOf(' ') != -1)
|
||||
|
@ -314,7 +314,8 @@ Zotero.FeedReader._processCreators = function(feedEntry, field, role) {
|
|||
// Probably multiple authors listed in a single field
|
||||
nameStr = name;
|
||||
break; // For clarity. personArr.length == 1 anyway
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
names.push(name);
|
||||
}
|
||||
}
|
||||
|
@ -352,7 +353,7 @@ Zotero.FeedReader._processCreators = function(feedEntry, field, role) {
|
|||
creators.push(creator);
|
||||
}
|
||||
return creators;
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
* Parse feed entry into a Zotero item
|
||||
|
@ -363,7 +364,7 @@ Zotero.FeedReader._getFeedItem = function(feedEntry, feedInfo) {
|
|||
// Can probably fall back to links on missing id - unlikely to change
|
||||
if (!feedEntry.id && !feedEntry.link) {
|
||||
Zotero.debug("FeedReader: Feed item missing an ID or link - discarding");
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
|
||||
let item = {
|
||||
|
@ -435,18 +436,17 @@ Zotero.FeedReader._getFeedItem = function(feedEntry, feedInfo) {
|
|||
if (issn) item.ISSN = issn;
|
||||
|
||||
let isbn = Zotero.FeedReader._getFeedField(feedEntry, 'isbn', 'prism')
|
||||
|| Zotero.FeedReader._getFeedField(feedEntry, 'isbn')
|
||||
|| Zotero.FeedReader._getFeedField(feedEntry, 'isbn');
|
||||
if (isbn) item.ISBN = isbn;
|
||||
|
||||
let identifier = Zotero.FeedReader._getFeedField(feedEntry, 'identifier', 'dc');
|
||||
if (identifier) {
|
||||
let cleanId = Zotero.Utilities.cleanDOI(identifier);
|
||||
for (let type of ['DOI', 'ISBN', 'ISSN']) {
|
||||
let cleanId = Zotero.Utilities[`clean${type}`](identifier);
|
||||
if (cleanId) {
|
||||
if (!item.DOI) item.DOI = cleanId;
|
||||
} else if (cleanId = Zotero.Utilities.cleanISBN(identifier)) {
|
||||
if (!item.ISBN) item.ISBN = cleanId;
|
||||
} else if (cleanId = Zotero.Utilities.cleanISSN(identifier)) {
|
||||
if (!item.ISSN) item.ISSN = cleanId;
|
||||
if (!item[type]) item[type] = cleanId;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -477,7 +477,7 @@ Zotero.FeedReader._getFeedItem = function(feedEntry, feedInfo) {
|
|||
item.enclosedItems = Zotero.FeedReader._getEnclosedItems(feedEntry);
|
||||
|
||||
return item;
|
||||
}
|
||||
};
|
||||
|
||||
/*********************
|
||||
* Utility functions *
|
||||
|
@ -497,24 +497,26 @@ Zotero.FeedReader._getRichText = function(feedText, field) {
|
|||
// Properties are stored internally as ns+name, but only some namespaces are
|
||||
// supported. Others are just "null"
|
||||
let ns = {
|
||||
'prism': 'null',
|
||||
'dc': 'dc:'
|
||||
}
|
||||
prism: 'null',
|
||||
dc: 'dc:'
|
||||
};
|
||||
Zotero.FeedReader._getFeedField = function (feedEntry, field, namespace) {
|
||||
let prefix = namespace ? ns[namespace] || 'null' : '';
|
||||
try {
|
||||
return feedEntry.fields.getPropertyAsAUTF8String(prefix + field);
|
||||
} catch(e) {}
|
||||
}
|
||||
catch (e) {}
|
||||
|
||||
try {
|
||||
if (namespace && !ns[namespace]) {
|
||||
prefix = namespace + ':';
|
||||
return feedEntry.fields.getPropertyAsAUTF8String(prefix + field);
|
||||
}
|
||||
} catch(e) {}
|
||||
|
||||
return;
|
||||
}
|
||||
catch (e) { }
|
||||
|
||||
return null;
|
||||
};
|
||||
|
||||
Zotero.FeedReader._getEnclosedItems = function (feedEntry) {
|
||||
var enclosedItems = [];
|
||||
|
@ -530,4 +532,4 @@ Zotero.FeedReader._getEnclosedItems = function(feedEntry) {
|
|||
}
|
||||
|
||||
return enclosedItems;
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue