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

View File

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

View File

@ -18,7 +18,8 @@
sendPostMessage({type: 'usw-remove-stylus-button'});
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;
sendPostMessage({type: 'usw-fill-new-style', data: style});
});