From f6f46390ab2d9a94f7904a68ba81f5f974a70e37 Mon Sep 17 00:00:00 2001 From: rainu Date: Fri, 27 Mar 2020 14:25:11 +0100 Subject: [PATCH] [#38] use hashed-urls and therefore reimplements recall mechanism --- README.md | 3 ++ layouts/error.vue | 43 +++++++++++++++++++++------- locales/de.json | 3 ++ locales/en.json | 3 ++ middleware/dropbox.js | 42 ++------------------------- middleware/recall.js | 14 +++++++++ nuxt.config.js | 3 +- package-lock.json | 57 +++++++++--------------------------- package.json | 2 +- pages/backup/index.vue | 3 ++ pages/recall.vue | 65 ++++++++++++++++++++++++++++++++++++++++++ store/secrets.js | 15 ++++++++++ 12 files changed, 159 insertions(+), 94 deletions(-) create mode 100644 middleware/recall.js create mode 100644 pages/recall.vue diff --git a/README.md b/README.md index 460f5b4..5cd48b8 100644 --- a/README.md +++ b/README.md @@ -64,6 +64,9 @@ For detailed explanation on how things work, check out [Nuxt.js docs](https://nu ## Changelog +### 0.9.21 +* use hashed-urls - now you can share links to subpages without error [#38](https://github.com/rainu/dev-notes/issues/38) + ### 0.9.19 * implements new note type: record [#5](https://github.com/rainu/dev-notes/issues/5) * use a dedicated icon for draggable elements diff --git a/layouts/error.vue b/layouts/error.vue index ea3e7f4..df6ac95 100644 --- a/layouts/error.vue +++ b/layouts/error.vue @@ -1,14 +1,32 @@ @@ -33,6 +51,11 @@ export default { pageNotFound: '404 Not Found', otherError: 'An error occurred' } + }, + computed: { + isRecallInProgress(){ + return window.location.search && window.location.search.includes("recall") + } } } diff --git a/locales/de.json b/locales/de.json index 000920a..91786c7 100644 --- a/locales/de.json +++ b/locales/de.json @@ -494,5 +494,8 @@ "others":{ "title": "Andere" } + }, + "recall": { + "progress": "Einstellungen werden vorgenommen ..." } } diff --git a/locales/en.json b/locales/en.json index 0ad2948..43a3638 100644 --- a/locales/en.json +++ b/locales/en.json @@ -494,5 +494,8 @@ "others": { "title": "Others" } + }, + "recall": { + "progress": "Settings will be applied ..." } } diff --git a/middleware/dropbox.js b/middleware/dropbox.js index 2e5f932..1ef5d21 100644 --- a/middleware/dropbox.js +++ b/middleware/dropbox.js @@ -1,41 +1,5 @@ -import { Dropbox } from "dropbox"; +export default function ({ store }) { + //this middleware is only responsible for trigger refreshing the dropbox token -const refreshToken = (store) => { - let dpxAuth = store.getters['secrets/getDropboxAuth'] - if(dpxAuth && dpxAuth.access_token) { - let dbx = new Dropbox({ - fetch: fetch, - accessToken: dpxAuth.access_token, - clientId: process.env.dropbox.clientId, - }) - - dbx.usersGetCurrentAccount() - .then(user => store.commit('secrets/setDropboxUser', user)) - .catch(() => store.dispatch('secrets/removeDropboxAuth')) - } -} - -export default function ({ isHMR, app, store, route, params, error, redirect }) { - //dropbox use a oath2 auth workflow. that means the user will be redirected - //to the dropbox' login masked and after the login was successfully dropbox - //redirects the user back to our web-app - - //this middleware is responsible for reading the dropbox auth token and store - //them into our store - - let recall = route.query.recall && route.query.recall === 'dropbox' && route.hash - if(!recall) { - refreshToken(store) - return - } - - let hashParams = new URLSearchParams(route.hash.substring(1)) - let authParams = {} - for(let [key, value] of hashParams.entries()) { - authParams[key] = value - } - - store.dispatch('secrets/setDropboxAuth', authParams) - .then(() => redirect(`/backup`)) - .then(() => refreshToken(store)) + store.dispatch('secrets/refreshDropboxToken') } diff --git a/middleware/recall.js b/middleware/recall.js new file mode 100644 index 0000000..25e6db6 --- /dev/null +++ b/middleware/recall.js @@ -0,0 +1,14 @@ +export default function (ctx) { + //we need to handle requests which cannot handle fragments (url with #) + //so this middleware will look the real url and check if there is a recall query + //if so, redirect to own recall-page with all the origin data + + if(window.location.search) { + let queryParams = new URLSearchParams(window.location.search.substr(1)) + + let recall = queryParams.has('recall') + if(recall) { + window.location = `${window.location.origin}${window.location.pathname}#/recall/${window.location.search}${window.location.hash}` + } + } +} diff --git a/nuxt.config.js b/nuxt.config.js index 2e8a50f..19e7650 100644 --- a/nuxt.config.js +++ b/nuxt.config.js @@ -10,7 +10,8 @@ const routerBase = process.env.DEPLOY_ENV === 'GH_PAGES' ? { base: '/' } } -routerBase.router.middleware = ['encryption', 'dropbox'] +routerBase.router.middleware = ['recall', 'encryption', 'dropbox'] +routerBase.router.mode = 'hash' export default { ...routerBase, diff --git a/package-lock.json b/package-lock.json index 1ca8ff0..976c09b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "DevNotes", - "version": "0.9.19", + "version": "0.9.21", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -1946,15 +1946,6 @@ "resolved": "https://registry.npmjs.org/binary-extensions/-/binary-extensions-2.0.0.tgz", "integrity": "sha512-Phlt0plgpIIBOGTT/ehfFnbNlfsDEiqmzE2KRXoX1bLIlir4X/MR+zSyBEkL05ffWgnRSf/DXv+WrUAVr93/ow==" }, - "bindings": { - "version": "1.5.0", - "resolved": "https://registry.npmjs.org/bindings/-/bindings-1.5.0.tgz", - "integrity": "sha512-p2q/t/mhvuOj/UeLlV6566GD/guowlr0hHxClI0W9m7MWYkL1F0hLo+0Aexs9HSPCtR1SXQ0TD3MMKrXZajbiQ==", - "optional": true, - "requires": { - "file-uri-to-path": "1.0.0" - } - }, "bluebird": { "version": "3.7.2", "resolved": "https://registry.npmjs.org/bluebird/-/bluebird-3.7.2.tgz", @@ -3820,12 +3811,6 @@ "schema-utils": "^2.5.0" } }, - "file-uri-to-path": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/file-uri-to-path/-/file-uri-to-path-1.0.0.tgz", - "integrity": "sha512-0Zt+s3L7Vf1biwWZ29aARiVYLx7iMGnEUl9x33fbB/j3jR81u/O2LbqK+Bm1CDSNDKVtJ/YjwY7TUd5SkeLQLw==", - "optional": true - }, "filesize": { "version": "3.6.1", "resolved": "https://registry.npmjs.org/filesize/-/filesize-3.6.1.tgz", @@ -5521,12 +5506,6 @@ "resolved": "https://registry.npmjs.org/mustache/-/mustache-2.3.2.tgz", "integrity": "sha512-KpMNwdQsYz3O/SBS1qJ/o3sqUJ5wSb8gb0pul8CO0S56b9Y2ALm8zCfsjPXsqGFfoNBkDwZuZIAjhsZI03gYVQ==" }, - "nan": { - "version": "2.14.0", - "resolved": "https://registry.npmjs.org/nan/-/nan-2.14.0.tgz", - "integrity": "sha512-INOFj37C7k3AfaNTtX8RhsTw7qRy7eLET14cROi9+5HAVbbHuIWUHEauBv5qT4Av2tWasiTY1Jw6puUNqRJXQg==", - "optional": true - }, "nanomatch": { "version": "1.2.13", "resolved": "https://registry.npmjs.org/nanomatch/-/nanomatch-1.2.13.tgz", @@ -9135,13 +9114,11 @@ } }, "fsevents": { - "version": "1.2.11", - "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-1.2.11.tgz", - "integrity": "sha512-+ux3lx6peh0BpvY0JebGyZoiR4D+oYzdPZMKJwkZ+sFkNJzpL7tXc/wehS49gUAxg3tmMHPHZkA8JU2rhhgDHw==", + "version": "1.2.12", + "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-1.2.12.tgz", + "integrity": "sha512-Ggd/Ktt7E7I8pxZRbGIs7vwqAPscSESMrCSkx2FtWeqmheJgCo2R74fTsZFCifr0VTPwqRpPv17+6b8Zp7th0Q==", "optional": true, "requires": { - "bindings": "^1.5.0", - "nan": "^2.12.1", "node-pre-gyp": "*" }, "dependencies": { @@ -9184,7 +9161,7 @@ } }, "chownr": { - "version": "1.1.3", + "version": "1.1.4", "bundled": true, "optional": true }, @@ -9334,7 +9311,7 @@ } }, "minimist": { - "version": "0.0.8", + "version": "1.2.5", "bundled": true, "optional": true }, @@ -9356,11 +9333,11 @@ } }, "mkdirp": { - "version": "0.5.1", + "version": "0.5.3", "bundled": true, "optional": true, "requires": { - "minimist": "0.0.8" + "minimist": "^1.2.5" } }, "ms": { @@ -9369,7 +9346,7 @@ "optional": true }, "needle": { - "version": "2.4.0", + "version": "2.3.3", "bundled": true, "optional": true, "requires": { @@ -9396,7 +9373,7 @@ } }, "nopt": { - "version": "4.0.1", + "version": "4.0.3", "bundled": true, "optional": true, "requires": { @@ -9418,12 +9395,13 @@ "optional": true }, "npm-packlist": { - "version": "1.4.7", + "version": "1.4.8", "bundled": true, "optional": true, "requires": { "ignore-walk": "^3.0.1", - "npm-bundled": "^1.0.1" + "npm-bundled": "^1.0.1", + "npm-normalize-package-bin": "^1.0.1" } }, "npmlog": { @@ -9493,17 +9471,10 @@ "ini": "~1.3.0", "minimist": "^1.2.0", "strip-json-comments": "~2.0.1" - }, - "dependencies": { - "minimist": { - "version": "1.2.0", - "bundled": true, - "optional": true - } } }, "readable-stream": { - "version": "2.3.6", + "version": "2.3.7", "bundled": true, "optional": true, "requires": { diff --git a/package.json b/package.json index bd93cae..ab2b8d0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "DevNotes", - "version": "0.9.20", + "version": "0.9.21", "description": "A progressive web application (PWA) for notes.", "author": "rainu", "private": true, diff --git a/pages/backup/index.vue b/pages/backup/index.vue index 7127ed5..2d8fc83 100644 --- a/pages/backup/index.vue +++ b/pages/backup/index.vue @@ -113,6 +113,9 @@ if (this.persistedPassword) { this.password = this.persistedPassword } + if(this.$route.query.selected) { + this.panel = parseInt(this.$route.query.selected) + } } } diff --git a/pages/recall.vue b/pages/recall.vue new file mode 100644 index 0000000..8f59657 --- /dev/null +++ b/pages/recall.vue @@ -0,0 +1,65 @@ + + + + + diff --git a/store/secrets.js b/store/secrets.js index 5328907..cc6a957 100644 --- a/store/secrets.js +++ b/store/secrets.js @@ -1,4 +1,5 @@ import Vue from 'vue' +import {Dropbox} from "dropbox"; export const state = () => ({ secrets: { @@ -100,6 +101,20 @@ export const actions = { store.dispatch('setDropboxAuth', {}), store.commit('setDropboxUser', {}) ]) + }, + refreshDropboxToken(store){ + let dpxAuth = store.getters.getDropboxAuth + if(dpxAuth && dpxAuth.access_token) { + let dbx = new Dropbox({ + fetch: fetch, + accessToken: dpxAuth.access_token, + clientId: process.env.dropbox.clientId, + }) + + return dbx.usersGetCurrentAccount() + .then(user => store.commit('setDropboxUser', user)) + .catch(() => store.dispatch('removeDropboxAuth')) + } } }