Fix incorrect USO md5Url (#523) (#527)

* Fix incorrect USO md5Url (#523)

* Fix md5Url in getAll

* Remove variable reassignment
This commit is contained in:
Rob Garrison 2018-10-26 08:48:58 -05:00 committed by GitHub
parent 100e1dc28d
commit 30cf5b2458
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 0 deletions

View File

@ -174,6 +174,7 @@ function getStyles(options) {
return dbExec('getAll').then(event => { return dbExec('getAll').then(event => {
cachedStyles.list = event.target.result || []; cachedStyles.list = event.target.result || [];
cachedStyles.list.forEach(fixUsoMd5Issue);
cachedStyles.byId.clear(); cachedStyles.byId.clear();
for (const style of cachedStyles.list) { for (const style of cachedStyles.list) {
cachedStyles.byId.set(style.id, style); cachedStyles.byId.set(style.id, style);
@ -264,6 +265,14 @@ function filterStyles({
} }
// The md5Url provided by USO includes a duplicate "update" subdomain (see #523),
// This fixes any already installed styles containing this error
function fixUsoMd5Issue(style) {
if (style && style.md5Url && style.md5Url.includes('update.update.userstyles')) {
style.md5Url = style.md5Url.replace('update.update.userstyles', 'update.userstyles');
}
}
function filterStylesInternal({ function filterStylesInternal({
// js engines don't like big functions (V8 often deoptimized the original filterStyles) // js engines don't like big functions (V8 often deoptimized the original filterStyles)
// it also makes sense to extract the less frequently executed code // it also makes sense to extract the less frequently executed code
@ -350,6 +359,8 @@ function saveStyle(style) {
let existed; let existed;
let codeIsUpdated; let codeIsUpdated;
fixUsoMd5Issue(style);
return maybeCalcDigest() return maybeCalcDigest()
.then(maybeImportFix) .then(maybeImportFix)
.then(decide); .then(decide);

View File

@ -238,6 +238,14 @@
}); });
} }
// USO providing md5Url as "https://update.update.userstyles.org/#####.md5"
// instead of "https://update.userstyles.org/#####.md5"
function tryFixMd5(style) {
if (style && style.md5Url && style.md5Url.includes('update.update')) {
style.md5Url = style.md5Url.replace('update.update', 'update');
}
return style;
}
function getStyleJson() { function getStyleJson() {
return getResource(getStyleURL(), {responseType: 'json'}) return getResource(getStyleURL(), {responseType: 'json'})
@ -256,6 +264,7 @@
}); });
})); }));
}) })
.then(tryFixMd5)
.catch(() => null); .catch(() => null);
} }