From f9c7d14a3fbbbd595558ee0fab918f44663c1390 Mon Sep 17 00:00:00 2001 From: hlw Date: Sun, 30 Aug 2020 20:21:15 +0800 Subject: [PATCH 1/3] feat: allow custom img host --- src/api/file.js | 24 ++- src/components/CodemirrorEditor/header.vue | 25 +-- .../CodemirrorEditor/rightClickMenu.vue | 29 +-- .../CodemirrorEditor/uploadImgDialog.vue | 177 ++++++++++++++++++ src/view/CodemirrorEditor.vue | 12 +- 5 files changed, 213 insertions(+), 54 deletions(-) create mode 100644 src/components/CodemirrorEditor/uploadImgDialog.vue diff --git a/src/api/file.js b/src/api/file.js index 250ecd1..c68d946 100644 --- a/src/api/file.js +++ b/src/api/file.js @@ -19,10 +19,28 @@ const fileUploadConfig = { function fileUpload(content, filename) { const date = new Date(); const dir = date.getFullYear() + '/' + (date.getMonth() + 1).toString().padStart(2, '0') + '/' + date.getDate().toString().padStart(2, '0'); - const uuid = uuidv4(); - const token = fileUploadConfig.accessToken[Math.floor(Math.random() * fileUploadConfig.accessToken.length)].replace('doocsmd', ''); + const uuid = uuidv4(); const dateFilename = new Date().getTime() + '-' + uuid + '.' + filename.split('.')[1]; - const url = `https://api.github.com/repos/${fileUploadConfig.username}/${fileUploadConfig.repo}/contents/${dir}/${dateFilename}`; + const imgHost = localStorage.getItem("ImgHost") || 'default' + + let token = '' + let username = '' + let repo = '' + + if (imgHost === 'default') { + token = fileUploadConfig.accessToken[Math.floor(Math.random() * fileUploadConfig.accessToken.length)].replace('doocsmd', ''); + username = fileUploadConfig.username + repo = fileUploadConfig.repo + } + + if (imgHost === 'github' && localStorage.getItem("GitHubConfig")) { + const githubConfg = JSON.parse(localStorage.getItem("GitHubConfig")); + token = githubConfg.accessToken + username = githubConfg.username + repo = githubConfg.repo + } + + const url = `https://api.github.com/repos/${username}/${repo}/contents/${dir}/${dateFilename}`; return fetch({ url, diff --git a/src/components/CodemirrorEditor/header.vue b/src/components/CodemirrorEditor/header.vue index bccd457..24082c8 100644 --- a/src/components/CodemirrorEditor/header.vue +++ b/src/components/CodemirrorEditor/header.vue @@ -1,14 +1,9 @@ diff --git a/src/components/CodemirrorEditor/header.vue b/src/components/CodemirrorEditor/header.vue index 24082c8..ec3513e 100644 --- a/src/components/CodemirrorEditor/header.vue +++ b/src/components/CodemirrorEditor/header.vue @@ -100,7 +100,7 @@ export default { return this.nightMode ? 'dark' : 'light' }, btnType() { - return !this.nightMode ? 'success' : 'default'; + return this.nightMode ? 'default' : 'primary'; }, ...mapState({ output: state => state.output, diff --git a/src/components/CodemirrorEditor/insertForm.vue b/src/components/CodemirrorEditor/insertForm.vue index afd4504..334ebe3 100644 --- a/src/components/CodemirrorEditor/insertForm.vue +++ b/src/components/CodemirrorEditor/insertForm.vue @@ -73,7 +73,7 @@ }, computed: { btnType() { - return !this.nightMode ? "success" : "default"; + return this.nightMode ? "default" : "primary"; }, ...mapState({ nightMode: state => state.nightMode, diff --git a/src/components/CodemirrorEditor/resetDialog.vue b/src/components/CodemirrorEditor/resetDialog.vue index 30aaeca..7c7eae7 100644 --- a/src/components/CodemirrorEditor/resetDialog.vue +++ b/src/components/CodemirrorEditor/resetDialog.vue @@ -21,7 +21,7 @@ export default { }, computed: { btnType() { - return this.nightMode ? 'default' : 'success'; + return this.nightMode ? 'default' : 'primary'; }, ...mapState({ nightMode: state => state.nightMode From ed119cb4f9060991dc331bbc56ff433d8baa3a98 Mon Sep 17 00:00:00 2001 From: yanglbme Date: Mon, 31 Aug 2020 10:59:53 +0800 Subject: [PATCH 3/3] fix: update upLoadImgDialog --- src/components/CodemirrorEditor/uploadImgDialog.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/CodemirrorEditor/uploadImgDialog.vue b/src/components/CodemirrorEditor/uploadImgDialog.vue index 3a44a06..f9b670d 100644 --- a/src/components/CodemirrorEditor/uploadImgDialog.vue +++ b/src/components/CodemirrorEditor/uploadImgDialog.vue @@ -29,7 +29,7 @@ - +