Don't rely on _isUswLinked
It will now simply pass the vendor_data query which will exposed on the `location.search` once you are on the `/api/oauth/style/new` path. And thus can be retrieved which styleID should be need to get.
Related USw commit: 59b2eb8f3a
This commit is contained in:
parent
69ccdb0591
commit
ede20ca30c
|
@ -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))) {
|
||||
|
|
|
@ -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(' ');
|
||||
}
|
||||
|
|
|
@ -18,7 +18,12 @@
|
|||
sendPostMessage({type: 'usw-remove-stylus-button'});
|
||||
|
||||
if (location.pathname === '/api/oauth/style/new') {
|
||||
API.styles.find({_isUswLinked: true}).then(style => {
|
||||
// Gets the search query string, and get the vendor_data from it.
|
||||
// Which is the id of the style that shall be linked with.
|
||||
const vendorData = window.location.search.split('&')
|
||||
.find(query => query.startsWith('vendor_data'))
|
||||
.split('=')[1];
|
||||
API.styles.get(Number(vendorData)).then(style => {
|
||||
style.sourceCode = style.tmpSourceCode;
|
||||
sendPostMessage({type: 'usw-fill-new-style', data: style});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue
Block a user