more stuff in fixKnownProblems

fixes #1342
This commit is contained in:
tophf 2021-10-12 20:12:26 +03:00
parent 37a174b092
commit 992b89f0eb

View File

@ -234,12 +234,6 @@ const styleMan = (() => {
if (ready.then) await ready; if (ready.then) await ready;
reason = reason || dataMap.has(style.id) ? 'update' : 'install'; reason = reason || dataMap.has(style.id) ? 'update' : 'install';
style = mergeWithMapped(style); style = mergeWithMapped(style);
const url = !style.url && style.updateUrl && (
URLS.extractUsoArchiveInstallUrl(style.updateUrl) ||
URLS.extractGreasyForkInstallUrl(style.updateUrl) ||
URLS.extractUSwInstallUrl(style.updateUrl)
);
if (url) style.url = style.installationUrl = url;
style.originalDigest = await calcStyleDigest(style); style.originalDigest = await calcStyleDigest(style);
// FIXME: update updateDate? what about usercss config? // FIXME: update updateDate? what about usercss config?
return saveStyle(style, {reason}); return saveStyle(style, {reason});
@ -427,7 +421,7 @@ const styleMan = (() => {
style._id = uuidv4(); style._id = uuidv4();
} }
style._rev = Date.now(); style._rev = Date.now();
fixUsoMd5Issue(style); fixKnownProblems(style);
} }
function afterSave(style, newId) { function afterSave(style, newId) {
@ -478,7 +472,6 @@ const styleMan = (() => {
await db.exec('putMany', updated); await db.exec('putMany', updated);
} }
for (const style of styles) { for (const style of styles) {
fixUsoMd5Issue(style);
storeInMap(style); storeInMap(style);
uuidIndex.set(style._id, style.id); uuidIndex.set(style._id, style.id);
} }
@ -513,7 +506,21 @@ const styleMan = (() => {
style[key] = fixedUrl; style[key] = fixedUrl;
} }
} }
return res; let url;
/* USO bug, duplicate "update" subdomain, see #523 */
if ((url = style.md5Url) && url.includes('update.update.userstyles')) {
res = style.md5Url = url.replace('update.update.userstyles', 'update.userstyles');
}
/* Default homepage URL for external styles installed from a known distro */
if ((url = style.updateUrl) && (url =
URLS.extractGreasyForkInstallUrl(url) ||
URLS.extractUsoArchiveInstallUrl(url) ||
URLS.extractUSwInstallUrl(url)
)) {
if (!style.url) res = style.url = url;
if (style.installationUrl !== url) res = style.installationUrl = url;
}
return Boolean(res);
} }
function urlMatchStyle(query, style) { function urlMatchStyle(query, style) {
@ -602,14 +609,6 @@ const styleMan = (() => {
'$'; '$';
} }
// 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 createMatchQuery(url) { function createMatchQuery(url) {
let urlWithoutHash; let urlWithoutHash;
let urlWithoutParams; let urlWithoutParams;