Don't rely on _isUswLinked (#1288)

This commit is contained in:
Gusted 2021-07-20 12:56:45 +00:00 committed by GitHub
parent 69ccdb0591
commit 61c7d4f08c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 6 additions and 9 deletions

View File

@ -374,10 +374,8 @@ const styleMan = (() => {
case 'publish': { case 'publish': {
if (!style._usw || !style._usw.token) { if (!style._usw || !style._usw.token) {
// Ensures just the style does have the _isUswLinked property as `true`.
for (const {style: someStyle} of dataMap.values()) { for (const {style: someStyle} of dataMap.values()) {
if (someStyle._id === style._id) { if (someStyle._id === style._id) {
someStyle._isUswLinked = true;
someStyle.tmpSourceCode = style.sourceCode; someStyle.tmpSourceCode = style.sourceCode;
let metadata = {}; let metadata = {};
try { try {
@ -388,7 +386,6 @@ const styleMan = (() => {
} }
someStyle.metadata = metadata; someStyle.metadata = metadata;
} else { } else {
delete someStyle._isUswLinked;
delete someStyle.tmpSourceCode; delete someStyle.tmpSourceCode;
delete someStyle.metadata; delete someStyle.metadata;
} }
@ -398,7 +395,6 @@ const styleMan = (() => {
token: await tokenMan.getToken('userstylesworld', true, style.id), token: await tokenMan.getToken('userstylesworld', true, style.id),
}; };
delete style._isUswLinked;
delete style.tmpSourceCode; delete style.tmpSourceCode;
delete style.metadata; delete style.metadata;
for (const [k, v] of Object.entries(await retrieveStyleInformation(style._usw.token))) { for (const [k, v] of Object.entries(await retrieveStyleInformation(style._usw.token))) {

View File

@ -92,7 +92,7 @@ const tokenMan = (() => {
if (!interactive) { if (!interactive) {
throw new Error(`Invalid token: ${name}`); throw new Error(`Invalid token: ${name}`);
} }
const accessToken = authUser(name, k, interactive); const accessToken = authUser(name, k, interactive, styleId ? {vendor_data: styleId} : {});
return accessToken; return accessToken;
}, },
@ -133,17 +133,17 @@ const tokenMan = (() => {
return handleTokenResult(result, k); return handleTokenResult(result, k);
} }
async function authUser(name, k, interactive = false) { async function authUser(name, k, interactive = false, extraQuery = {}) {
await require(['/vendor/webext-launch-web-auth-flow/webext-launch-web-auth-flow.min']); await require(['/vendor/webext-launch-web-auth-flow/webext-launch-web-auth-flow.min']);
/* global webextLaunchWebAuthFlow */ /* global webextLaunchWebAuthFlow */
const provider = AUTH[name]; const provider = AUTH[name];
const state = Math.random().toFixed(8).slice(2); const state = Math.random().toFixed(8).slice(2);
const query = { const query = Object.assign(extraQuery, {
response_type: provider.flow, response_type: provider.flow,
client_id: provider.clientId, client_id: provider.clientId,
redirect_uri: provider.redirect_uri || chrome.identity.getRedirectURL(), redirect_uri: provider.redirect_uri || chrome.identity.getRedirectURL(),
state, state,
}; });
if (provider.scopes) { if (provider.scopes) {
query.scope = provider.scopes.join(' '); query.scope = provider.scopes.join(' ');
} }

View File

@ -18,7 +18,8 @@
sendPostMessage({type: 'usw-remove-stylus-button'}); sendPostMessage({type: 'usw-remove-stylus-button'});
if (location.pathname === '/api/oauth/style/new') { if (location.pathname === '/api/oauth/style/new') {
API.styles.find({_isUswLinked: true}).then(style => { const styleId = Number(new URLSearchParams(location.search).get('vendor_data'));
API.styles.get(styleId).then(style => {
style.sourceCode = style.tmpSourceCode; style.sourceCode = style.tmpSourceCode;
sendPostMessage({type: 'usw-fill-new-style', data: style}); sendPostMessage({type: 'usw-fill-new-style', data: style});
}); });