pushing broken code

This commit is contained in:
Gusted 2021-04-07 09:18:48 +02:00
parent e2711a3704
commit 63db0d7650
No known key found for this signature in database
GPG Key ID: FD821B732837125F
5 changed files with 43 additions and 43 deletions

View File

@ -223,13 +223,11 @@ const styleMan = (() => {
style = mergeWithMapped(style); style = mergeWithMapped(style);
const url = !style.url && style.updateUrl && ( const url = !style.url && style.updateUrl && (
URLS.extractUsoArchiveInstallUrl(style.updateUrl) || URLS.extractUsoArchiveInstallUrl(style.updateUrl) ||
URLS.extractGreasyForkInstallUrl(style.updateUrl) URLS.extractGreasyForkInstallUrl(style.updateUrl) ||
URLS.extractUSwInstallUrl(style.updateUrl)
// Vednoc, time to proxy updateUrl's as this code is now broken.
); );
if (url) style.url = style.installationUrl = url; if (url) style.url = style.installationUrl = url;
if (style.initialUrl) {
style.installationUrl = URLS.extractUSwInstallUrl(style.initialUrl);
delete style.initialUrl;
}
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 handleSave(await saveStyle(style), reason); return handleSave(await saveStyle(style), reason);

View File

@ -36,9 +36,9 @@ bgReady.all.then(() => {
chrome.webRequest.onBeforeSendHeaders.addListener(maybeInstallFromDistro, { chrome.webRequest.onBeforeSendHeaders.addListener(maybeInstallFromDistro, {
urls: [ urls: [
URLS.usoArchiveRaw + 'usercss/*.user.css', URLS.usoArchiveRaw + 'usercss/*.user.css',
URLS.usw + 'api/style/*.user.css',
'*://greasyfork.org/scripts/*/code/*.user.css', '*://greasyfork.org/scripts/*/code/*.user.css',
'*://sleazyfork.org/scripts/*/code/*.user.css', '*://sleazyfork.org/scripts/*/code/*.user.css',
URLS.usw + 'api/style/*.user.css',
...[].concat( ...[].concat(
...Object.entries(maybeDistro) ...Object.entries(maybeDistro)
.map(([host, {glob}]) => makeUsercssGlobs(host, glob))), .map(([host, {glob}]) => makeUsercssGlobs(host, glob))),

View File

@ -81,7 +81,6 @@ const preinit = (() => {
value: API.usercss.buildCode(data.style).then(style => style.sections), value: API.usercss.buildCode(data.style).then(style => style.sections),
configurable: true, configurable: true,
}); });
data.style.initialUrl = initialUrl;
return data; return data;
} catch (error) { } catch (error) {
return {error, sourceCode}; return {error, sourceCode};

View File

@ -80,7 +80,6 @@ const URLS = {
usoArchiveRaw: 'https://raw.githubusercontent.com/33kk/uso-archive/flomaster/data/', usoArchiveRaw: 'https://raw.githubusercontent.com/33kk/uso-archive/flomaster/data/',
usw: 'https://userstyles.world/', usw: 'https://userstyles.world/',
uswIndex: 'https://userstyles.world/api/index/',
extractUsoArchiveId: url => extractUsoArchiveId: url =>
url && url &&
@ -425,14 +424,13 @@ function download(url, {
}; };
xhr.onload = () => { xhr.onload = () => {
if (xhr.status === requiredStatusCode || !requiredStatusCode || u.protocol === 'file:') { if (xhr.status === requiredStatusCode || !requiredStatusCode || u.protocol === 'file:') {
const isUSWIndex = url.startsWith(URLS.uswIndex);
const response = expandUsoVars(xhr.response); const response = expandUsoVars(xhr.response);
if (responseHeaders) { if (responseHeaders) {
const headers = {}; const headers = {};
for (const h of responseHeaders) headers[h] = xhr.getResponseHeader(h); for (const h of responseHeaders) headers[h] = xhr.getResponseHeader(h);
resolve({headers, response}); resolve({headers, response});
} else { } else {
resolve(isUSWIndex ? response.data : response); resolve(response);
} }
} else { } else {
reject(xhr.status); reject(xhr.status);

View File

@ -12,6 +12,7 @@
const RESULT_ID_PREFIX = 'search-result-'; const RESULT_ID_PREFIX = 'search-result-';
const INDEX_URL = URLS.usoArchiveRaw + 'search-index.json'; const INDEX_URL = URLS.usoArchiveRaw + 'search-index.json';
const USW_INDEX_URL = URLS.usw + 'api/index/uso-format';
const STYLUS_CATEGORY = 'chrome-extension'; const STYLUS_CATEGORY = 'chrome-extension';
const PAGE_LENGTH = 10; const PAGE_LENGTH = 10;
// update USO style install counter if the style isn't uninstalled immediately // update USO style install counter if the style isn't uninstalled immediately
@ -33,8 +34,7 @@
* @prop {Number} ai - authorId * @prop {Number} ai - authorId
* @prop {string} an - authorName * @prop {string} an - authorName
* @prop {string} sn - screenshotName * @prop {string} sn - screenshotName
* @prop {boolean} sa - screenshotArchived * @prop {boolean} sa - screenshotArchivedis
* @prop {bolean} uw - is USw style
*/ */
/** @type IndexEntry[] */ /** @type IndexEntry[] */
let results; let results;
@ -141,17 +141,15 @@
} }
}); });
function calcId(style) {
return calcUsoId(style) || calcUswId(style);
}
window.on('styleAdded', async ({detail: {style}}) => { window.on('styleAdded', async ({detail: {style}}) => {
restoreScrollPosition(); restoreScrollPosition();
let usoOrUSwId = calcUsoId(style) || const supportedId = calcId(style) || calcId(await API.styles.get(style.id));
calcUSwId(style); if (supportedId && results.find(r => r.id === supportedId)) {
if (usoOrUSwId) { renderActionButtons(supportedId, style.id);
const styleAPI = await API.styles.get(style.id);
usoOrUSwId = calcUsoId(styleAPI) ||
calcUSwId(styleAPI);
}
if (usoOrUSwId && results.find(r => r.id === usoOrUSwId)) {
renderActionButtons(usoOrUSwId, style.id);
} }
}); });
} }
@ -193,10 +191,10 @@
for (let retry = 0; !results.length && retry <= 2; retry++) { for (let retry = 0; !results.length && retry <= 2; retry++) {
results = await search({retry}); results = await search({retry});
} }
if (results.length) { if (!results.length && !$('#search-query').value) {
const installedStyles = await API.styles.getAll(); const installedStyles = await API.styles.getAll();
const allUsoOrUSwIds = new Set(installedStyles.map(calcUsoId || calcUSwId)); const allSupportedIds = new Set(installedStyles.map(calcUsoId || calcUswId));
results = results.filter(r => !allUsoOrUSwIds.has(r.i)); results = results.filter(r => !allSupportedIds.has(r.i));
} }
render(); render();
(results.length ? show : hide)(dom.list); (results.length ? show : hide)(dom.list);
@ -237,7 +235,7 @@
} }
// remove extraneous elements // remove extraneous elements
const pageLen = end > results.length && const pageLen = end > results.length &&
results.length % PAGE_LENGTH || results.length % PAGE_LENGTH ||
Math.min(results.length, PAGE_LENGTH); Math.min(results.length, PAGE_LENGTH);
while (dom.list.children.length > pageLen) { while (dom.list.children.length > pageLen) {
dom.list.lastElementChild.remove(); dom.list.lastElementChild.remove();
@ -281,7 +279,6 @@
an: author, an: author,
sa: shotArchived, sa: shotArchived,
sn: shotName, sn: shotName,
uw: isUSwStyle,
} = entry._result = result; } = entry._result = result;
entry.id = RESULT_ID_PREFIX + id; entry.id = RESULT_ID_PREFIX + id;
// title // title
@ -291,10 +288,13 @@
}); });
$('.search-result-title span', entry).textContent = $('.search-result-title span', entry).textContent =
t.breakWord(name.length < 300 ? name : name.slice(0, 300) + '...'); t.breakWord(name.length < 300 ? name : name.slice(0, 300) + '...');
// screenshot
const auto = !isUSwStyle ? URLS.uso + `auto_style_screenshots/${id}${USO_AUTO_PIC_SUFFIX}` : ''; // Note to Tophf, we send a direct image link over shotName, as we are currently not
// hosting any images. Which soon will be different.
const isDirectImageLink = /(.jpg|.webp|.avif|.jpeg|.png)$/g.match(shotName);
const auto = URLS.uso + `auto_style_screenshots/${id}${USO_AUTO_PIC_SUFFIX}`;
Object.assign($('.search-result-screenshot', entry), { Object.assign($('.search-result-screenshot', entry), {
src: isUSwStyle ? shotName src: isDirectImageLink ? shotName
: shotName && !shotName.endsWith(USO_AUTO_PIC_SUFFIX) : shotName && !shotName.endsWith(USO_AUTO_PIC_SUFFIX)
? `${shotArchived ? URLS.usoArchiveRaw : URLS.uso + 'style_'}screenshots/${shotName}` ? `${shotArchived ? URLS.usoArchiveRaw : URLS.uso + 'style_'}screenshots/${shotName}`
: auto, : auto,
@ -407,7 +407,7 @@
async function install() { async function install() {
const entry = this.closest('.search-result'); const entry = this.closest('.search-result');
const result = /** @type IndexEntry */ entry._result; const result = /** @type IndexEntry */ entry._result;
const {i: id, uw: isUSwStyle} = result; const {i: id} = result;
const installButton = $('.search-result-install', entry); const installButton = $('.search-result-install', entry);
showSpinner(entry); showSpinner(entry);
@ -415,16 +415,17 @@
installButton.disabled = true; installButton.disabled = true;
entry.style.setProperty('pointer-events', 'none', 'important'); entry.style.setProperty('pointer-events', 'none', 'important');
// FIXME: move this to background page and create an API like installUSOStyle // FIXME: move this to background page and create an API like installUSOStyle
if (!isUSwStyle) { result.pingbackTimer = setTimeout(download, PINGBACK_DELAY,
result.pingbackTimer = setTimeout(download, PINGBACK_DELAY, `${URLS.uso}styles/install/${id}?source=stylish-ch`);
`${URLS.uso}styles/install/${id}?source=stylish-ch`);
}
const updateUrl = isUSwStyle ? URLS.makeUSwCodeUrl(id) : URLS.makeUsoArchiveCodeUrl(id); // Any recommendation how to detect USw here?
// the `uw` was purely for this situation to make sure if we need
// create a USw url or an Uso-Archive url.
const updateUrl = URLS.makeUsoArchiveCodeUrl(id);
try { try {
const sourceCode = await download(updateUrl); const sourceCode = await download(updateUrl);
const style = await API.usercss.install({sourceCode, updateUrl, initialUrl: isUSwStyle ? updateUrl : null}); const style = await API.usercss.install({sourceCode, updateUrl});
renderFullInfo(entry, style); renderFullInfo(entry, style);
} catch (reason) { } catch (reason) {
error(`Error while downloading usoID:${id}\nReason: ${reason}`); error(`Error while downloading usoID:${id}\nReason: ${reason}`);
@ -481,9 +482,15 @@
async function fetchIndex() { async function fetchIndex() {
const timer = setTimeout(showSpinner, BUSY_DELAY, dom.list); const timer = setTimeout(showSpinner, BUSY_DELAY, dom.list);
index = (await download(INDEX_URL, {responseType: 'json'})) index = [];
.filter(res => res.f === 'uso'); await Promise.all([
index = [...index, ...(await download(URLS.uswIndex + 'uso-format', {responseType: 'json'}))]; download(INDEX_URL, {responseType: 'json'}).then(res => {
index = index.concat(res.filter(res => res.f === 'uso'));
}).catch(() => {}),
download(USW_INDEX_URL, {responseType: 'json'}).then(res => {
index = index.concat(res.data);
}).catch(() => {}),
]);
clearTimeout(timer); clearTimeout(timer);
$remove(':scope > .lds-spinner', dom.list); $remove(':scope > .lds-spinner', dom.list);
return index; return index;
@ -534,10 +541,8 @@
URLS.extractUsoArchiveId(updateUrl); URLS.extractUsoArchiveId(updateUrl);
} }
function calcUSwId({installationUrl}) { function calcUswId({installationUrl}) {
return installationUrl ? Number(installationUrl.startsWith(URLS.usw) return URLS.extractUSwId(installationUrl) || 0;
&& installationUrl.match(/\d+|$/)[0])
: 0;
} }
function calcHaystack(res) { function calcHaystack(res) {