Skip to content

Commit

Permalink
✨ Feature: add tencent-cos options for url
Browse files Browse the repository at this point in the history
ISSUES CLOSED: #862, #863, #865, #524, #845, #732
  • Loading branch information
Molunerfinn committed Apr 4, 2022
1 parent f1c8507 commit af291e4
Show file tree
Hide file tree
Showing 13 changed files with 68 additions and 27 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"keycode": "^2.2.0",
"lodash-id": "^0.14.0",
"lowdb": "^1.0.0",
"picgo": "^1.5.0-alpha.0",
"picgo": "^1.5.0-alpha.3",
"qrcode.vue": "^1.7.0",
"shell-path": "2.1.0",
"uuidv4": "^6.2.11",
Expand Down
4 changes: 2 additions & 2 deletions src/main/apis/app/uploader/apis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export const uploadClipboardFiles = async (): Promise<string> => {
trayWindow?.webContents?.send('clipboardFiles', [])
trayWindow?.webContents?.send('uploadFiles', img)
if (windowManager.has(IWindowList.SETTING_WINDOW)) {
windowManager.get(IWindowList.SETTING_WINDOW)!.webContents.send('updateGallery')
windowManager.get(IWindowList.SETTING_WINDOW)!.webContents?.send('updateGallery')
}
return handleUrlEncode(img[0].imgUrl as string)
} else {
Expand Down Expand Up @@ -81,7 +81,7 @@ export const uploadChoosedFiles = async (webContents: WebContents, files: IFileW
// trayWindow just be created in mac/windows, not in linux
windowManager.get(IWindowList.TRAY_WINDOW)?.webContents?.send('uploadFiles', imgs)
if (windowManager.has(IWindowList.SETTING_WINDOW)) {
windowManager.get(IWindowList.SETTING_WINDOW)!.webContents.send('updateGallery')
windowManager.get(IWindowList.SETTING_WINDOW)!.webContents?.send('updateGallery')
}
return result
} else {
Expand Down
23 changes: 16 additions & 7 deletions src/main/lifeCycle/errorHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,23 @@ const LOG_PATH = path.join(STORE_PATH, '/picgo.log')
// since the error may occur in picgo-core
// so we can't use the log from picgo
export const loggerWriter = (error: Error) => {
let log = `${dayjs().format('YYYY-MM-DD HH:mm:ss')} [PicGo ERROR] startup error`
if (error?.stack) {
log += `\n------Error Stack Begin------\n${util.format(error.stack)}\n-------Error Stack End-------\n`
} else {
const msg = JSON.stringify(error)
log += `${msg}\n`
try {
const time = dayjs().format('YYYY-MM-DD HH:mm:ss')
let log = `${time} [PicGo ERROR] process error begin`
if (error?.stack) {
log += `\n------Error Stack Begin------\n${util.format(error.stack)}\n-------Error Stack End-------\n`
} else {
const msg = JSON.stringify(error)
log += `${msg}\n`
}
log += `${time} [PicGo ERROR] process error end`
if (!fse.existsSync(LOG_PATH)) {
fse.ensureFileSync(LOG_PATH)
}
fse.appendFileSync(LOG_PATH, log)
} catch (e) {
console.error(e)
}
fse.appendFileSync(LOG_PATH, log)
}

const handleProcessError = (error: Error) => {
Expand Down
8 changes: 7 additions & 1 deletion src/main/migrate/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ const updateShortKeyFromVersion212 = (db: typeof ConfigStore, shortKeyConfig: IS

const migrateGalleryFromVersion230 = async (configDB: typeof ConfigStore, galleryDB: DBStore, picgo: PicGoCore) => {
const originGallery: ImgInfo[] = configDB.get('uploaded')
// if hasMigrate, we don't need to migrate
const hasMigrate: boolean = configDB.get('__migrateUploaded')
if (hasMigrate) {
return
}
const configPath = configDB.getConfigPath()
const configBakPath = path.join(path.dirname(configPath), 'config.bak.json')
// migrate gallery from config to gallery db
Expand All @@ -44,7 +49,8 @@ const migrateGalleryFromVersion230 = async (configDB: typeof ConfigStore, galler
}
await galleryDB.insertMany(originGallery)
picgo.saveConfig({
uploaded: []
uploaded: [],
__migrateUploaded: true
})
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/main/server/routerManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ router.post('/upload', async ({
// upload with clipboard
logger.info('[PicGo Server] upload clipboard file')
const res = await uploadClipboardFiles()
logger.info('[PicGo Server] upload result:', res)
if (res) {
handleResponse({
response,
Expand Down Expand Up @@ -51,6 +52,7 @@ router.post('/upload', async ({
})
const win = windowManager.getAvailableWindow()
const res = await uploadChoosedFiles(win.webContents, pathList)
logger.info('[PicGo Server] upload result', res.join(' ; '))
if (res.length) {
handleResponse({
response,
Expand Down
5 changes: 5 additions & 0 deletions src/renderer/layouts/Main.vue
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,11 @@ export default class extends Vue {
</script>
<style lang='stylus'>
$darwinBg = transparentify(#172426, #000, 0.7)
.setting-list-scroll
height 425px
overflow-y auto
overflow-x hidden
margin-right 0!important
.picgo-fade
&-enter,
&-leave,
Expand Down
14 changes: 10 additions & 4 deletions src/renderer/pages/PicGoSetting.vue
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,13 @@
></el-switch>
</el-form-item>
<el-form-item
:label="$T('SETTINGS_USE_BUILTIN_CLIPBOARD_UPLOAD')"
>
<div class="el-form-item__custom-label" slot="label">
{{ $T('SETTINGS_USE_BUILTIN_CLIPBOARD_UPLOAD') }}
<el-tooltip class="item" effect="dark" :content="$T('BUILTIN_CLIPBOARD_TIPS')" placement="right">
<i class="el-icon-question"></i>
</el-tooltip>
</div>
<el-switch
v-model="form.useBuiltinClipboard"
:active-text="$T('SETTINGS_OPEN')"
Expand Down Expand Up @@ -811,6 +816,9 @@ export default class extends Vue {
color #eee
flex-basis: 50%
flex-shrink: 0
.el-form-item__custom-label
display flex
align-items center
.el-button-group
width 100%
.el-button
Expand All @@ -824,9 +832,7 @@ export default class extends Vue {
&.is-active
color #409EFF
.el-icon-question
font-size 20px
float right
margin-top 9px
margin-left 4px
color #eee
cursor pointer
transition .2s color ease-in-out
Expand Down
15 changes: 11 additions & 4 deletions src/renderer/pages/picbeds/TcYun.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<div id="tcyun-view">
<el-row :gutter="16">
<el-row :gutter="16" class="setting-list-scroll">
<el-col :span="16" :offset="4">
<div class="view-title">
腾讯云COS设置
Expand Down Expand Up @@ -74,6 +74,11 @@
>
<el-input v-model="form.customUrl" @keyup.native.enter="confirm" placeholder="例如https://xxxx.com"></el-input>
</el-form-item>
<el-form-item
label="设定网址后缀"
>
<el-input v-model="form.options" @keyup.native.enter="confirm" placeholder="例如?imageMogr2"></el-input>
</el-form-item>
<el-form-item>
<el-button-group>
<el-button type="primary" @click="confirm" round>确定</el-button>
Expand All @@ -90,24 +95,26 @@ import { ipcRenderer } from 'electron'
import { Component, Vue } from 'vue-property-decorator'
import mixin from '@/utils/ConfirmButtonMixin'
import { OPEN_URL } from '#/events/constants'
import { ITcyunConfig } from 'picgo/dist/types'
@Component({
name: 'tcyun',
mixins: [mixin]
})
export default class extends Vue {
form: ITcYunConfig = {
form: ITcyunConfig = {
secretId: '',
secretKey: '',
bucket: '',
appId: '',
area: '',
path: '',
customUrl: '',
version: 'v4'
version: 'v5',
options: ''
}
async created () {
const config = await this.getConfig<ITcYunConfig>('picBed.tcyun')
const config = await this.getConfig<ITcyunConfig>('picBed.tcyun')
if (config) {
this.form = Object.assign({}, config)
}
Expand Down
6 changes: 4 additions & 2 deletions src/renderer/pages/picbeds/UpYun.vue
Original file line number Diff line number Diff line change
Expand Up @@ -67,21 +67,23 @@
<script lang="ts">
import { Component, Vue } from 'vue-property-decorator'
import mixin from '@/utils/ConfirmButtonMixin'
import { IUpyunConfig } from 'picgo/dist/types'
@Component({
name: 'upyun',
mixins: [mixin]
})
export default class extends Vue {
form: IUpYunConfig = {
form: IUpyunConfig = {
bucket: '',
operator: '',
password: '',
options: '',
url: '',
path: ''
}
async created () {
const config = await this.getConfig<IUpYunConfig>('picBed.upyun')
const config = await this.getConfig<IUpyunConfig>('picBed.upyun')
if (config) {
this.form = Object.assign({}, config)
}
Expand Down
1 change: 1 addition & 0 deletions src/universal/i18n/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ export const EN: ILocales = {
SETTINGS_NOT_CONFIG_OPTIONS: 'Not Config Options',
SETTINGS_USE_BUILTIN_CLIPBOARD_UPLOAD: 'Use Builtin Clipboard to Upload',
SETTINGS_CHOOSE_LANGUAGE: 'Choose Language',
BUILTIN_CLIPBOARD_TIPS: 'Use builtin clipboard function to upload instead of using scripts',

// shortcut page
SHORTCUT_NAME: 'Shortcut Name',
Expand Down
1 change: 1 addition & 0 deletions src/universal/i18n/zh-CN.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ export const ZH_CN = {
SETTINGS_NOT_CONFIG_OPTIONS: '暂无配置项',
SETTINGS_USE_BUILTIN_CLIPBOARD_UPLOAD: '使用内置剪贴板上传',
SETTINGS_CHOOSE_LANGUAGE: '选择语言',
BUILTIN_CLIPBOARD_TIPS: '使用内置剪贴板函数而不是调用脚本获取剪贴板图片',

// shortcut page
SHORTCUT_NAME: '快捷键名称',
Expand Down
3 changes: 2 additions & 1 deletion src/universal/types/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,8 @@ interface ITcYunConfig {
area: string,
path: string,
customUrl: string,
version: 'v4' | 'v5'
version: 'v4' | 'v5',
options: string
}

interface IUpYunConfig {
Expand Down
11 changes: 6 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9782,11 +9782,12 @@ performance-now@^2.1.0:
resolved "https://registry.npmjs.org/performance-now/-/performance-now-2.1.0.tgz#6309f4e0e5fa913ec1c69307ae364b4b377c9e7b"
integrity sha1-Ywn04OX6kT7BxpMHrjZLSzd8nns=

picgo@^1.5.0-alpha.0:
version "1.5.0-alpha.0"
resolved "https://registry.npmmirror.com/picgo/download/picgo-1.5.0-alpha.0.tgz#c546a8e48035a0d0a97552dcb3b1e33d85e196d9"
integrity sha1-xUao5IA1oNCpdVLcs7HjPYXhltk=
picgo@^1.5.0-alpha.3:
version "1.5.0-alpha.3"
resolved "https://registry.npmmirror.com/picgo/-/picgo-1.5.0-alpha.3.tgz#1d30de78d0a963de131b6a3739706160a6a7598f"
integrity sha512-87jotY0snEjQrjmy0Ka46ZvKLjPlfGOghRs5ArvDDZ8g2l5PuikXAyu8AEFxc2WcJ8RiMwjG/tbS15l1dzM5JQ==
dependencies:
"@picgo/i18n" "^1.0.0"
chalk "^2.4.1"
commander "^8.1.0"
comment-json "^2.3.1"
Expand All @@ -9810,7 +9811,7 @@ picgo@^1.5.0-alpha.0:
request "^2.87.0"
request-promise-native "^1.0.5"
resolve "^1.8.1"
rimraf "^2.6.3"
rimraf "^3.0.2"

picocolors@^0.2.1:
version "0.2.1"
Expand Down

0 comments on commit af291e4

Please sign in to comment.