mirror of
https://github.com/gorhill/uBlock.git
synced 2024-09-15 15:32:28 +02:00
further fix re #426
This commit is contained in:
parent
53f6a5a9e5
commit
97bf6e279e
@ -76,7 +76,6 @@ var AssetEntry = function() {
|
|||||||
this.localChecksum = '';
|
this.localChecksum = '';
|
||||||
this.repoChecksum = '';
|
this.repoChecksum = '';
|
||||||
this.expireTimestamp = 0;
|
this.expireTimestamp = 0;
|
||||||
this.homeURL = '';
|
|
||||||
};
|
};
|
||||||
|
|
||||||
var RepoMetadata = function() {
|
var RepoMetadata = function() {
|
||||||
@ -86,6 +85,9 @@ var RepoMetadata = function() {
|
|||||||
|
|
||||||
var repoMetadata = null;
|
var repoMetadata = null;
|
||||||
|
|
||||||
|
// We need these to persist beyond repoMetaData
|
||||||
|
var homeURLs = {};
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
var stringIsNotEmpty = function(s) {
|
var stringIsNotEmpty = function(s) {
|
||||||
@ -412,14 +414,7 @@ var getRepoMetadata = function(callback) {
|
|||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
exports.setHomeURL = function(path, homeURL) {
|
exports.setHomeURL = function(path, homeURL) {
|
||||||
var onRepoMetadataReady = function(metadata) {
|
homeURLs[path] = homeURL;
|
||||||
var entry = metadata.entries[path];
|
|
||||||
if ( entry === undefined ) {
|
|
||||||
entry = metadata.entries[path] = new AssetEntry();
|
|
||||||
}
|
|
||||||
entry.homeURL = homeURL;
|
|
||||||
};
|
|
||||||
getRepoMetadata(onRepoMetadataReady);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
@ -533,6 +528,7 @@ var readRepoFile = function(path, callback) {
|
|||||||
|
|
||||||
var readRepoCopyAsset = function(path, callback) {
|
var readRepoCopyAsset = function(path, callback) {
|
||||||
var assetEntry;
|
var assetEntry;
|
||||||
|
var homeURL = homeURLs[path];
|
||||||
|
|
||||||
var reportBack = function(content, err) {
|
var reportBack = function(content, err) {
|
||||||
var details = {
|
var details = {
|
||||||
@ -598,7 +594,7 @@ var readRepoCopyAsset = function(path, callback) {
|
|||||||
var onHomeFileLoaded = function() {
|
var onHomeFileLoaded = function() {
|
||||||
this.onload = this.onerror = null;
|
this.onload = this.onerror = null;
|
||||||
if ( stringIsNotEmpty(this.responseText) === false ) {
|
if ( stringIsNotEmpty(this.responseText) === false ) {
|
||||||
console.error('µBlock> readRepoCopyAsset("%s") / onHomeFileLoaded("%s"): no response', path, assetEntry.homeURL);
|
console.error('µBlock> readRepoCopyAsset("%s") / onHomeFileLoaded("%s"): no response', path, homeURL);
|
||||||
// Fetch from repo only if obsolescence was due to repo checksum
|
// Fetch from repo only if obsolescence was due to repo checksum
|
||||||
if ( assetEntry.localChecksum !== assetEntry.repoChecksum ) {
|
if ( assetEntry.localChecksum !== assetEntry.repoChecksum ) {
|
||||||
getTextFileFromURL(repositoryURLSkipCache, onRepoFileLoaded, onRepoFileError);
|
getTextFileFromURL(repositoryURLSkipCache, onRepoFileLoaded, onRepoFileError);
|
||||||
@ -607,14 +603,14 @@ var readRepoCopyAsset = function(path, callback) {
|
|||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
//console.log('µBlock> readRepoCopyAsset("%s") / onHomeFileLoaded("%s")', path, assetEntry.homeURL);
|
//console.log('µBlock> readRepoCopyAsset("%s") / onHomeFileLoaded("%s")', path, homeURL);
|
||||||
updateChecksum();
|
updateChecksum();
|
||||||
cachedAssetsManager.save(path, this.responseText, callback);
|
cachedAssetsManager.save(path, this.responseText, callback);
|
||||||
};
|
};
|
||||||
|
|
||||||
var onHomeFileError = function() {
|
var onHomeFileError = function() {
|
||||||
this.onload = this.onerror = null;
|
this.onload = this.onerror = null;
|
||||||
console.error(errorCantConnectTo.replace('{{url}}', assetEntry.homeURL));
|
console.error(errorCantConnectTo.replace('{{url}}', homeURL));
|
||||||
// Fetch from repo only if obsolescence was due to repo checksum
|
// Fetch from repo only if obsolescence was due to repo checksum
|
||||||
if ( assetEntry.localChecksum !== assetEntry.repoChecksum ) {
|
if ( assetEntry.localChecksum !== assetEntry.repoChecksum ) {
|
||||||
getTextFileFromURL(repositoryURLSkipCache, onRepoFileLoaded, onRepoFileError);
|
getTextFileFromURL(repositoryURLSkipCache, onRepoFileLoaded, onRepoFileError);
|
||||||
@ -628,10 +624,10 @@ var readRepoCopyAsset = function(path, callback) {
|
|||||||
// - Auto-update enabled AND (not in cache OR in cache but obsolete)
|
// - Auto-update enabled AND (not in cache OR in cache but obsolete)
|
||||||
var timestamp = entries[path];
|
var timestamp = entries[path];
|
||||||
var inCache = typeof timestamp === 'number';
|
var inCache = typeof timestamp === 'number';
|
||||||
if ( exports.allowRemoteFetch && exports.autoUpdate && stringIsNotEmpty(assetEntry.homeURL) ) {
|
if ( exports.allowRemoteFetch && exports.autoUpdate && stringIsNotEmpty(homeURL) ) {
|
||||||
if ( inCache === false || cacheIsObsolete(timestamp) ) {
|
if ( inCache === false || cacheIsObsolete(timestamp) ) {
|
||||||
//console.log('µBlock> readRepoCopyAsset("%s") / onCacheMetaReady(): not cached or obsolete', path);
|
//console.log('µBlock> readRepoCopyAsset("%s") / onCacheMetaReady(): not cached or obsolete', path);
|
||||||
getTextFileFromURL(assetEntry.homeURL, onHomeFileLoaded, onHomeFileError);
|
getTextFileFromURL(homeURL, onHomeFileLoaded, onHomeFileError);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -658,7 +654,6 @@ var readRepoCopyAsset = function(path, callback) {
|
|||||||
// Repo copy changed: fetch from home URL
|
// Repo copy changed: fetch from home URL
|
||||||
if ( exports.allowRemoteFetch && exports.autoUpdate && assetEntry.localChecksum !== assetEntry.repoChecksum ) {
|
if ( exports.allowRemoteFetch && exports.autoUpdate && assetEntry.localChecksum !== assetEntry.repoChecksum ) {
|
||||||
//console.log('µBlock> readRepoCopyAsset("%s") / onRepoMetaReady(): repo has newer version', path);
|
//console.log('µBlock> readRepoCopyAsset("%s") / onRepoMetaReady(): repo has newer version', path);
|
||||||
var homeURL = assetEntry.homeURL;
|
|
||||||
if ( stringIsNotEmpty(homeURL) ) {
|
if ( stringIsNotEmpty(homeURL) ) {
|
||||||
getTextFileFromURL(homeURL, onHomeFileLoaded, onHomeFileError);
|
getTextFileFromURL(homeURL, onHomeFileLoaded, onHomeFileError);
|
||||||
} else {
|
} else {
|
||||||
@ -924,7 +919,7 @@ exports.get = function(path, callback) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Asset is repo copy of external content
|
// Asset is repo copy of external content
|
||||||
if ( assetEntry.homeURL !== '' ) {
|
if ( stringIsNotEmpty(homeURLs[path]) ) {
|
||||||
readRepoCopyAsset(path, callback);
|
readRepoCopyAsset(path, callback);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -963,7 +958,7 @@ exports.metadata = function(callback) {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
entry = out[path];
|
entry = out[path];
|
||||||
entry.cacheObsolete = stringIsNotEmpty(entry.homeURL) &&
|
entry.cacheObsolete = stringIsNotEmpty(homeURLs[path]) &&
|
||||||
cacheIsObsolete(entry.lastModified);
|
cacheIsObsolete(entry.lastModified);
|
||||||
}
|
}
|
||||||
callback(out);
|
callback(out);
|
||||||
@ -983,7 +978,7 @@ exports.metadata = function(callback) {
|
|||||||
}
|
}
|
||||||
entryOut.localChecksum = entryRepo.localChecksum;
|
entryOut.localChecksum = entryRepo.localChecksum;
|
||||||
entryOut.repoChecksum = entryRepo.repoChecksum;
|
entryOut.repoChecksum = entryRepo.repoChecksum;
|
||||||
entryOut.homeURL = entryRepo.homeURL;
|
entryOut.homeURL = homeURLs[path] || '';
|
||||||
entryOut.repoObsolete = entryOut.localChecksum !== entryOut.repoChecksum;
|
entryOut.repoObsolete = entryOut.localChecksum !== entryOut.repoChecksum;
|
||||||
}
|
}
|
||||||
checkCacheObsolescence();
|
checkCacheObsolescence();
|
||||||
|
Loading…
Reference in New Issue
Block a user