Feature: upload api now support url query picbed and configname

ISSUES CLOSED: #93
This commit is contained in:
萌萌哒赫萝
2023-09-06 08:40:50 -07:00
parent f9a3f24c2f
commit 2fcec70721
8 changed files with 88 additions and 18 deletions

View File

@@ -99,6 +99,7 @@ GALLERY_SEARCH_FILENAME: Search by Filename
GALLERY_SEARCH_URL: Search by URL
GALLERY_MATCHED: ' Matched: '
UPLOAD_PAGE_COPY_UPLOAD_API: Copy Upload API
UPLOAD_PAGE_IMAGE_PROCESS_NAME: Image Processing
UPLOAD_PAGE_IMAGE_PROCESS_DIALOG_TITLE: Image Processing Settings
UPLOAD_PAGE_IMAGE_PROCESS_ISADDWM: Add Watermark

View File

@@ -99,6 +99,7 @@ GALLERY_SEARCH_FILENAME: 搜索文件名
GALLERY_SEARCH_URL: 搜索URL
GALLERY_MATCHED: ' 匹配到: '
UPLOAD_PAGE_COPY_UPLOAD_API: 复制上传API
UPLOAD_PAGE_IMAGE_PROCESS_NAME: 图片处理
UPLOAD_PAGE_IMAGE_PROCESS_DIALOG_TITLE: 图片处理设置
UPLOAD_PAGE_IMAGE_PROCESS_ISADDWM: 是否添加水印

View File

@@ -99,6 +99,7 @@ GALLERY_SEARCH_FILENAME: 搜尋文件名
GALLERY_SEARCH_URL: 搜尋URL
GALLERY_MATCHED: ' 匹配到: '
UPLOAD_PAGE_COPY_UPLOAD_API: 複製上傳API
UPLOAD_PAGE_IMAGE_PROCESS_NAME: 圖片處理
UPLOAD_PAGE_IMAGE_PROCESS_DIALOG_TITLE: 圖片處理設置
UPLOAD_PAGE_IMAGE_PROCESS_ISADDWM: 是否添加水印

View File

@@ -44,8 +44,9 @@ class Server {
}
if (request.method === 'POST') {
if (!routers.getHandler(request.url!)) {
logger.warn(`[PicList Server] don't support [${request.url}] url`)
const [url, query] = request.url!.split('?')
if (!routers.getHandler(url!)) {
logger.warn(`[PicList Server] don't support [${url}] url`)
handleResponse({
response,
statusCode: 404,
@@ -73,10 +74,11 @@ class Server {
})
}
logger.info('[PicList Server] get the request', body)
const handler = routers.getHandler(request.url!)
const handler = routers.getHandler(url!)?.handler
handler!({
...postObj,
response
response,
urlparams: query ? new URLSearchParams(query) : undefined
})
})
}

View File

@@ -1,12 +1,12 @@
class Router {
private router = new Map<string, routeHandler>()
private router = new Map<string, {handler: routeHandler, urlparams?: URLSearchParams}>()
get (url: string, callback: routeHandler): void {
this.router.set(url, callback)
get (url: string, callback: routeHandler, urlparams?: URLSearchParams): void {
this.router.set(url, { handler: callback, urlparams })
}
post (url: string, callback: routeHandler): void {
this.router.set(url, callback)
post (url: string, callback: routeHandler, urlparams?: URLSearchParams): void {
this.router.set(url, { handler: callback, urlparams })
}
getHandler (url: string) {

View File

@@ -7,6 +7,8 @@ import windowManager from 'apis/app/window/windowManager'
import { uploadChoosedFiles, uploadClipboardFiles, deleteChoosedFiles } from 'apis/app/uploader/apis'
import path from 'path'
import { dbPathDir } from 'apis/core/datastore/dbChecker'
import picgo from '@core/picgo'
import { changeCurrentUploader } from '../utils/handleUploaderConfig'
const STORE_PATH = dbPathDir()
const LOG_PATH = path.join(STORE_PATH, 'piclist.log')
@@ -16,12 +18,39 @@ const deleteErrorMessage = `delete error. see ${LOG_PATH} for more detail.`
router.post('/upload', async ({
response,
list = []
list = [],
urlparams
} : {
response: IHttpResponse,
list?: string[]
list?: string[],
urlparams?: URLSearchParams
}): Promise<void> => {
try {
const picbed = urlparams?.get('picbed')
let currentPicBedType = ''
let currentPicBedConfig = {} as IStringKeyMap
let currentPicBedConfigId = ''
let needRestore = false
if (picbed) {
const configName = urlparams?.get('configName') || 'Default'
const currentPicBed = picgo.getConfig<IStringKeyMap>('picBed') || {} as IStringKeyMap
currentPicBedType = currentPicBed?.current
currentPicBedConfig = currentPicBed?.[currentPicBedType]
currentPicBedConfigId = currentPicBedConfig?._id
if (picbed === currentPicBedType && configName === currentPicBedConfig._configName) {
// do nothing
} else {
needRestore = true
const picBeds = picgo.getConfig<IStringKeyMap>('uploader')
const currentPicBedList = picBeds?.[picbed]?.configList
if (currentPicBedList) {
const currentConfig = currentPicBedList?.find((item: any) => item._configName === configName)
if (currentConfig) {
changeCurrentUploader(picbed, currentConfig, currentConfig._id)
}
}
}
}
if (list.length === 0) {
// upload with clipboard
logger.info('[PicList Server] upload clipboard file')
@@ -83,6 +112,9 @@ router.post('/upload', async ({
})
}
}
if (needRestore) {
changeCurrentUploader(currentPicBedType, currentPicBedConfig, currentPicBedConfigId)
}
} catch (err: any) {
logger.error(err)
handleResponse({

View File

@@ -10,14 +10,26 @@
>
<div
class="view-title"
@click="handleNameClick"
>
{{ picBedName }} {{ $T('SETTINGS') }}
<span
class="view-title-text"
@click="handleNameClick"
>
{{ picBedName }} {{ $T('SETTINGS') }}</span>
<el-icon
v-if="linkToLogInList.includes(picBedName)"
>
<Link />
</el-icon>
<el-button
type="primary"
round
size="small"
style="margin-left: 6px"
@click="handleCopyApi"
>
{{ $T('UPLOAD_PAGE_COPY_UPLOAD_API') }}
</el-button>
</div>
<config-form
v-if="config.length > 0"
@@ -95,7 +107,7 @@ import { ref, onBeforeUnmount, onBeforeMount } from 'vue'
import { T as $T } from '@/i18n/index'
// 数据发送工具函数
import { sendToMain, triggerRPC } from '@/utils/dataSender'
import { getConfig, sendToMain, triggerRPC } from '@/utils/dataSender'
// Vue Router 相关
import { useRoute, useRouter } from 'vue-router'
@@ -105,6 +117,7 @@ import ConfigForm from '@/components/ConfigForm.vue'
// Electron 相关
import {
clipboard,
ipcRenderer,
IpcRendererEvent
} from 'electron'
@@ -119,7 +132,7 @@ import { Link } from '@element-plus/icons-vue'
import dayjs from 'dayjs'
// Element Plus 下拉菜单组件
import { ElDropdown } from 'element-plus'
import { ElDropdown, ElMessage } from 'element-plus'
const type = ref('')
const config = ref<IPicGoPluginConfig[]>([])
@@ -187,7 +200,7 @@ const handleReset = async () => {
$router.back()
}
const linkToLogInList = ['github', 'tcyun', 'aliyun', 'smms', 'qiniu', 'imgur', 'upyun', 'githubPlus']
const linkToLogInList = ['GitHub', '腾讯云COS', '阿里云OSS', 'SM.MS', '七牛云', 'Imgur', '又拍云', 'githubPlus']
function handleNameClick () {
switch ($route.params.type) {
@@ -218,7 +231,26 @@ function handleNameClick () {
}
}
function getPicBeds (event: IpcRendererEvent, _config: IPicGoPluginConfig[], name: string) {
async function handleCopyApi () {
try {
const serverConfig = await getConfig<IStringKeyMap>('settings.server') || {
port: 36677,
host: '127.0.0.1'
}
const { port, host } = serverConfig
const uploader = await getConfig('uploader') as IStringKeyMap || {}
const picBedConfigList = uploader[$route.params.type as string].configList || []
const picBedConfig = picBedConfigList.find((item: IUploaderConfigListItem) => item._id === $route.params.configId)
const apiUrl = `http://${host}:${port}/upload?picbed=${$route.params.type}&configName=${picBedConfig?._configName}`
clipboard.writeText(apiUrl)
ElMessage.success($T('MANAGE_BUCKET_COPY_SUCCESS') + ' ' + apiUrl)
} catch (error) {
console.log(error)
ElMessage.error('Copy failed')
}
}
function getPicBeds (_event: IpcRendererEvent, _config: IPicGoPluginConfig[], name: string) {
config.value = _config
picBedName.value = name
}
@@ -245,7 +277,7 @@ export default {
height 100%
overflow-y auto
overflow-x hidden
.view-title
.view-title-text
&:hover
cursor pointer
color #409EFF

View File

@@ -96,6 +96,7 @@ interface ILocales {
GALLERY_SEARCH_FILENAME: string
GALLERY_SEARCH_URL: string
GALLERY_MATCHED: string
UPLOAD_PAGE_COPY_UPLOAD_API: string
UPLOAD_PAGE_IMAGE_PROCESS_NAME: string
UPLOAD_PAGE_IMAGE_PROCESS_DIALOG_TITLE: string
UPLOAD_PAGE_IMAGE_PROCESS_ISADDWM: string