Send styleInfo

We will be adding the feature to add style based of the currentStyle, see paring commit 31813da300
This commit is contained in:
Gusted 2021-06-03 15:42:52 +02:00
parent cc928d6e5a
commit c593c54228
No known key found for this signature in database
GPG Key ID: FD821B732837125F
3 changed files with 14 additions and 7 deletions

View File

@ -361,7 +361,7 @@ const styleMan = (() => {
switch (reason) { switch (reason) {
case 'link': case 'link':
style._usw = { style._usw = {
token: await tokenMan.getToken('userstylesworld', true, style.id), token: await tokenMan.getToken('userstylesworld', true, style),
}; };
for (const [k, v] of Object.entries(await retrieveStyleInformation(style._usw.token))) { for (const [k, v] of Object.entries(await retrieveStyleInformation(style._usw.token))) {
style._usw[k] = v; style._usw[k] = v;

View File

@ -52,7 +52,6 @@ const tokenMan = (() => {
flow: 'code', flow: 'code',
clientId: 'zeDmKhJIfJqULtcrGMsWaxRtWHEimKgS', clientId: 'zeDmKhJIfJqULtcrGMsWaxRtWHEimKgS',
clientSecret: 'wqHsvTuThQmXmDiVvOpZxPwSIbyycNFImpAOTxjaIRqDbsXcTOqrymMJKsOMuibFaij' + clientSecret: 'wqHsvTuThQmXmDiVvOpZxPwSIbyycNFImpAOTxjaIRqDbsXcTOqrymMJKsOMuibFaij' +
'ZZAkVYTDbLkQuYFKqgpMsMlFlgwQOYHvHFbgxQHDTwwdOroYhOwFuekCwXUlk',
authURL: URLS.usw + 'api/oauth/authorize_style', authURL: URLS.usw + 'api/oauth/authorize_style',
tokenURL: URLS.usw + 'api/oauth/access_token', tokenURL: URLS.usw + 'api/oauth/access_token',
redirect_uri: 'https://gusted.xyz/callback_helper/', redirect_uri: 'https://gusted.xyz/callback_helper/',
@ -78,8 +77,8 @@ const tokenMan = (() => {
return AUTH[name].clientId; return AUTH[name].clientId;
}, },
async getToken(name, interactive, styleId) { async getToken(name, interactive, style) {
const k = tokenMan.buildKeys(name, styleId); const k = tokenMan.buildKeys(name, style.id);
const obj = await chromeLocal.get(k.LIST); const obj = await chromeLocal.get(k.LIST);
if (obj[k.TOKEN]) { if (obj[k.TOKEN]) {
if (!obj[k.EXPIRE] || Date.now() < obj[k.EXPIRE]) { if (!obj[k.EXPIRE] || Date.now() < obj[k.EXPIRE]) {
@ -92,7 +91,11 @@ const tokenMan = (() => {
if (!interactive) { if (!interactive) {
throw new Error(`Invalid token: ${name}`); throw new Error(`Invalid token: ${name}`);
} }
return authUser(name, k, interactive); const styleInformation = name === 'userstylesworld' ? JSON.stringify({
'code': style.sourceCode,
'name': style.name,
}) : null;
return authUser(name, k, interactive, styleInformation);
}, },
async revokeToken(name, styleId) { async revokeToken(name, styleId) {
@ -132,7 +135,7 @@ const tokenMan = (() => {
return handleTokenResult(result, k); return handleTokenResult(result, k);
} }
async function authUser(name, k, interactive = false) { async function authUser(name, k, interactive = false, styleInformation = null) {
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];
@ -143,6 +146,9 @@ const tokenMan = (() => {
redirect_uri: provider.redirect_uri || chrome.identity.getRedirectURL(), redirect_uri: provider.redirect_uri || chrome.identity.getRedirectURL(),
state, state,
}; };
if (styleInformation) {
query['styleInfo'] = styleInformation;
}
if (provider.scopes) { if (provider.scopes) {
query.scope = provider.scopes.join(' '); query.scope = provider.scopes.join(' ');
} }

View File

@ -18,7 +18,8 @@ function connectToPort() {
function linkToUSW() { function linkToUSW() {
connectToPort(); connectToPort();
uswPort.postMessage({reason: 'link', data: editor.style}); const data = Object.assign(editor.style, {sourceCode: editor.getEditors()[0].getValue()});
uswPort.postMessage({reason: 'link', data});
} }
/* exported revokeLinking */ /* exported revokeLinking */