Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.mdns.eu/nextcloud/passwords-client.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarius David Wieschollek <passwords.public@mdns.eu>2021-01-24 01:02:10 +0300
committerMarius David Wieschollek <passwords.public@mdns.eu>2021-01-24 01:02:10 +0300
commit0b1bebcc0c0c864aa827c941f77614d346fd292a (patch)
treef31ffc03bd4f74ded3a77ecb037aca8aad85b95b
parent9304631ec5d6738d7899ce0493530969b21f9ffe (diff)
Change passlink connect processing
Signed-off-by: Marius David Wieschollek <passwords.public@mdns.eu>
-rw-r--r--src/PassLink/Action/Connect.js58
-rw-r--r--src/PassLink/PassLink.js10
2 files changed, 57 insertions, 11 deletions
diff --git a/src/PassLink/Action/Connect.js b/src/PassLink/Action/Connect.js
index 9b27e77..fbfda88 100644
--- a/src/PassLink/Action/Connect.js
+++ b/src/PassLink/Action/Connect.js
@@ -4,10 +4,13 @@ import HttpRequest from '../../Network/HttpRequest';
export default class Connect extends PassLinkAction {
/**
- *
* @param {Object} parameters
*/
constructor(parameters) {
+ if(!parameters.hasOwnProperty('id') && parameters.path.length > 8) {
+ parameters.id = parameters.path.substr(8, 36);
+ }
+
super(parameters);
this._codes = null;
this._clientLabel = null;
@@ -109,13 +112,31 @@ export default class Connect extends PassLinkAction {
* @private
*/
async _decodeTheme() {
- if(!this._parameters.hasOwnProperty('theme')) return null;
+ if(this._parameters.hasOwnProperty('t')) {
+ let pako = await import(/* webpackChunkName: "pako" */ 'pako'),
+ base64 = this._parameters.t,
+ zipped = atob(base64),
+ data = pako.inflate(zipped, {to: 'string'});
+
+ return this._themeFromV1(data);
+ } else if(this._parameters.hasOwnProperty('theme')) {
+ let pako = await import(/* webpackChunkName: "pako" */ 'pako'),
+ base64 = this._parameters.theme,
+ zipped = atob(base64),
+ data = pako.inflate(zipped, {to: 'string'});
+
+ return this._themeFromJson(data);
+ }
+ return null;
+ }
- let pako = await import(/* webpackChunkName: "pako" */ 'pako'),
- base64 = this._parameters.theme,
- zipped = atob(base64),
- json = pako.inflate(zipped, {to: 'string'}),
- theme = JSON.parse(json);
+ /**
+ * @param {String} data
+ * @return {Object|null}
+ * @private
+ */
+ _themeFromJson(data) {
+ let theme = JSON.parse(data);
if(theme.hasOwnProperty('color')) {
theme['color.primary'] = theme.color;
@@ -140,4 +161,27 @@ export default class Connect extends PassLinkAction {
return theme;
}
+
+ /**
+ * @param {String} data
+ * @return {Object|null}
+ * @private
+ */
+ _themeFromV1(data) {
+ let parts = data.split('|');
+ if(parts.length !== 6) return null;
+
+ let theme = {};
+
+ theme['label'] = parts[0];
+ theme['logo'] = `${this._parameters.baseUrl}/${parts[1]}`;
+ theme['background'] = parts[2].substr(0, 3) === '://' ? `https${parts[2]}`:`${this._parameters.baseUrl}/${parts[2]}`;
+ theme['color.primary'] = parts[3].length === 6 ? '#' + parts[3]:parts[3];
+ theme['color.text'] = parts[4].length === 6 ? '#' + parts[4]:parts[4];
+ theme['color.background'] = parts[5].length === 6 ? '#' + parts[5]:parts[5];
+
+ this._theme = theme;
+
+ return theme;
+ }
} \ No newline at end of file
diff --git a/src/PassLink/PassLink.js b/src/PassLink/PassLink.js
index db89796..c337aa8 100644
--- a/src/PassLink/PassLink.js
+++ b/src/PassLink/PassLink.js
@@ -15,15 +15,17 @@ class PassLink {
if(['ext+passlink:', 'web+passlink:', 'passlink:'].indexOf(url.protocol) === -1 || url.pathname.indexOf('/do/') === -1) {
throw new InvalidLink();
}
- let [server, action] = url.pathname.split('do/');
- let parameters = {};
+ let [server, action] = url.pathname.split('do/'),
+ parameters = {path: action};
+
for(let key of url.searchParams.keys()) {
parameters[key] = url.searchParams.get(key);
}
parameters.baseUrl = `https://${server}`;
+ if(action.indexOf('/') !== -1) action = action.substr(0, action.indexOf('/'));
- return {server, action, parameters}
+ return {server, action, parameters};
}
/**
@@ -33,7 +35,7 @@ class PassLink {
* @return {PassLinkAction}
*/
getAction(action, parameters) {
- if(action === 'connect') return new Connect(parameters);
+ if(action.substr(0, 7) === 'connect') return new Connect(parameters);
throw new UnknownAction(action);
}