diff options
author | Marius David Wieschollek <passwords.public@mdns.eu> | 2021-11-28 21:29:57 +0300 |
---|---|---|
committer | Marius David Wieschollek <passwords.public@mdns.eu> | 2021-11-28 21:29:57 +0300 |
commit | e1c6b6afe7bcefb0a8b17d70c72588d6c70f8db9 (patch) | |
tree | 45fbb814dea2b5f828036179dc992118a0766622 | |
parent | 858cf27a8476174edc006b9e457208c4a0b5f594 (diff) |
Update handling of theming
Signed-off-by: Marius David Wieschollek <passwords.public@mdns.eu>
-rw-r--r-- | package-lock.json | 11 | ||||
-rw-r--r-- | package.json | 1 | ||||
-rw-r--r-- | src/PassLink/Action/Connect.js | 84 |
3 files changed, 13 insertions, 83 deletions
diff --git a/package-lock.json b/package-lock.json index 13ea0cb..402a5dc 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,7 +11,6 @@ "dependencies": { "eventemitter3": "^4.0.7", "libsodium-wrappers": "^0.7.9", - "pako": "^2.0.4", "url-parse": "^1.5.3", "uuid": "^8.3.2" } @@ -34,11 +33,6 @@ "libsodium": "^0.7.0" } }, - "node_modules/pako": { - "version": "2.0.4", - "resolved": "https://registry.npmjs.org/pako/-/pako-2.0.4.tgz", - "integrity": "sha512-v8tweI900AUkZN6heMU/4Uy4cXRc2AYNRggVmTR+dEncawDJgCdLMximOVA2p4qO57WMynangsfGRb5WD6L1Bg==" - }, "node_modules/querystringify": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/querystringify/-/querystringify-2.2.0.tgz", @@ -86,11 +80,6 @@ "libsodium": "^0.7.0" } }, - "pako": { - "version": "2.0.4", - "resolved": "https://registry.npmjs.org/pako/-/pako-2.0.4.tgz", - "integrity": "sha512-v8tweI900AUkZN6heMU/4Uy4cXRc2AYNRggVmTR+dEncawDJgCdLMximOVA2p4qO57WMynangsfGRb5WD6L1Bg==" - }, "querystringify": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/querystringify/-/querystringify-2.2.0.tgz", diff --git a/package.json b/package.json index 89a6834..d65ba3f 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,6 @@ "dependencies": { "eventemitter3": "^4.0.7", "libsodium-wrappers": "^0.7.9", - "pako": "^2.0.4", "url-parse": "^1.5.3", "uuid": "^8.3.2" } diff --git a/src/PassLink/Action/Connect.js b/src/PassLink/Action/Connect.js index fbfda88..cc9a0f3 100644 --- a/src/PassLink/Action/Connect.js +++ b/src/PassLink/Action/Connect.js @@ -44,10 +44,10 @@ export default class Connect extends PassLinkAction { * * @return {Promise<null|object>|null} */ - getTheme() { + async getTheme() { if(this._theme !== null) return this._theme; - return this._decodeTheme(); + return await this._loadTheme(); } /** @@ -111,77 +111,19 @@ export default class Connect extends PassLinkAction { * * @private */ - async _decodeTheme() { - 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; - } - - /** - * @param {String} data - * @return {Object|null} - * @private - */ - _themeFromJson(data) { - let theme = JSON.parse(data); - - if(theme.hasOwnProperty('color')) { - theme['color.primary'] = theme.color; - delete theme.color; - } - if(theme.hasOwnProperty('txtColor')) { - theme['color.text'] = theme.txtColor; - delete theme.txtColor; - } - if(theme.hasOwnProperty('bgColor')) { - theme['color.background'] = theme.bgColor; - delete theme.bgColor; - } - if(theme.hasOwnProperty('background') && theme.background.substr(0, 8) !== 'https://') { - theme.background = this._parameters.baseUrl + theme.background; - } - if(theme.hasOwnProperty('logo')) { - theme.logo = this._parameters.baseUrl + theme.logo; - } - - this._theme = theme; - - return theme; - } - - /** - * @param {String} data - * @return {Object|null} - * @private - */ - _themeFromV1(data) { - let parts = data.split('|'); - if(parts.length !== 6) return null; - - let theme = {}; + async _loadTheme() { + let url = `${this._parameters.baseUrl}index.php/apps/passwords/link/connect/theme`, + request = new HttpRequest(url); - 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]; + let data = {id: this._parameters.id}; - this._theme = theme; + try { + let response = await request.setData(data).send(); + this._theme = response.getData(); - return theme; + return response.getData(); + } catch(e) { + return null; + } } }
\ No newline at end of file |