mirror of
https://github.com/Kuingsmile/PicList.git
synced 2026-09-07 00:17:03 +08:00
✨ Feature: upload api now support url query picbed and configname
ISSUES CLOSED: #93
This commit is contained in:
@@ -99,6 +99,7 @@ GALLERY_SEARCH_FILENAME: Search by Filename
|
|||||||
GALLERY_SEARCH_URL: Search by URL
|
GALLERY_SEARCH_URL: Search by URL
|
||||||
GALLERY_MATCHED: ' Matched: '
|
GALLERY_MATCHED: ' Matched: '
|
||||||
|
|
||||||
|
UPLOAD_PAGE_COPY_UPLOAD_API: Copy Upload API
|
||||||
UPLOAD_PAGE_IMAGE_PROCESS_NAME: Image Processing
|
UPLOAD_PAGE_IMAGE_PROCESS_NAME: Image Processing
|
||||||
UPLOAD_PAGE_IMAGE_PROCESS_DIALOG_TITLE: Image Processing Settings
|
UPLOAD_PAGE_IMAGE_PROCESS_DIALOG_TITLE: Image Processing Settings
|
||||||
UPLOAD_PAGE_IMAGE_PROCESS_ISADDWM: Add Watermark
|
UPLOAD_PAGE_IMAGE_PROCESS_ISADDWM: Add Watermark
|
||||||
|
|||||||
@@ -99,6 +99,7 @@ GALLERY_SEARCH_FILENAME: 搜索文件名
|
|||||||
GALLERY_SEARCH_URL: 搜索URL
|
GALLERY_SEARCH_URL: 搜索URL
|
||||||
GALLERY_MATCHED: ' 匹配到: '
|
GALLERY_MATCHED: ' 匹配到: '
|
||||||
|
|
||||||
|
UPLOAD_PAGE_COPY_UPLOAD_API: 复制上传API
|
||||||
UPLOAD_PAGE_IMAGE_PROCESS_NAME: 图片处理
|
UPLOAD_PAGE_IMAGE_PROCESS_NAME: 图片处理
|
||||||
UPLOAD_PAGE_IMAGE_PROCESS_DIALOG_TITLE: 图片处理设置
|
UPLOAD_PAGE_IMAGE_PROCESS_DIALOG_TITLE: 图片处理设置
|
||||||
UPLOAD_PAGE_IMAGE_PROCESS_ISADDWM: 是否添加水印
|
UPLOAD_PAGE_IMAGE_PROCESS_ISADDWM: 是否添加水印
|
||||||
|
|||||||
@@ -99,6 +99,7 @@ GALLERY_SEARCH_FILENAME: 搜尋文件名
|
|||||||
GALLERY_SEARCH_URL: 搜尋URL
|
GALLERY_SEARCH_URL: 搜尋URL
|
||||||
GALLERY_MATCHED: ' 匹配到: '
|
GALLERY_MATCHED: ' 匹配到: '
|
||||||
|
|
||||||
|
UPLOAD_PAGE_COPY_UPLOAD_API: 複製上傳API
|
||||||
UPLOAD_PAGE_IMAGE_PROCESS_NAME: 圖片處理
|
UPLOAD_PAGE_IMAGE_PROCESS_NAME: 圖片處理
|
||||||
UPLOAD_PAGE_IMAGE_PROCESS_DIALOG_TITLE: 圖片處理設置
|
UPLOAD_PAGE_IMAGE_PROCESS_DIALOG_TITLE: 圖片處理設置
|
||||||
UPLOAD_PAGE_IMAGE_PROCESS_ISADDWM: 是否添加水印
|
UPLOAD_PAGE_IMAGE_PROCESS_ISADDWM: 是否添加水印
|
||||||
|
|||||||
@@ -44,8 +44,9 @@ class Server {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (request.method === 'POST') {
|
if (request.method === 'POST') {
|
||||||
if (!routers.getHandler(request.url!)) {
|
const [url, query] = request.url!.split('?')
|
||||||
logger.warn(`[PicList Server] don't support [${request.url}] url`)
|
if (!routers.getHandler(url!)) {
|
||||||
|
logger.warn(`[PicList Server] don't support [${url}] url`)
|
||||||
handleResponse({
|
handleResponse({
|
||||||
response,
|
response,
|
||||||
statusCode: 404,
|
statusCode: 404,
|
||||||
@@ -73,10 +74,11 @@ class Server {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
logger.info('[PicList Server] get the request', body)
|
logger.info('[PicList Server] get the request', body)
|
||||||
const handler = routers.getHandler(request.url!)
|
const handler = routers.getHandler(url!)?.handler
|
||||||
handler!({
|
handler!({
|
||||||
...postObj,
|
...postObj,
|
||||||
response
|
response,
|
||||||
|
urlparams: query ? new URLSearchParams(query) : undefined
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
class Router {
|
class Router {
|
||||||
private router = new Map<string, routeHandler>()
|
private router = new Map<string, {handler: routeHandler, urlparams?: URLSearchParams}>()
|
||||||
|
|
||||||
get (url: string, callback: routeHandler): void {
|
get (url: string, callback: routeHandler, urlparams?: URLSearchParams): void {
|
||||||
this.router.set(url, callback)
|
this.router.set(url, { handler: callback, urlparams })
|
||||||
}
|
}
|
||||||
|
|
||||||
post (url: string, callback: routeHandler): void {
|
post (url: string, callback: routeHandler, urlparams?: URLSearchParams): void {
|
||||||
this.router.set(url, callback)
|
this.router.set(url, { handler: callback, urlparams })
|
||||||
}
|
}
|
||||||
|
|
||||||
getHandler (url: string) {
|
getHandler (url: string) {
|
||||||
|
|||||||
@@ -7,6 +7,8 @@ import windowManager from 'apis/app/window/windowManager'
|
|||||||
import { uploadChoosedFiles, uploadClipboardFiles, deleteChoosedFiles } from 'apis/app/uploader/apis'
|
import { uploadChoosedFiles, uploadClipboardFiles, deleteChoosedFiles } from 'apis/app/uploader/apis'
|
||||||
import path from 'path'
|
import path from 'path'
|
||||||
import { dbPathDir } from 'apis/core/datastore/dbChecker'
|
import { dbPathDir } from 'apis/core/datastore/dbChecker'
|
||||||
|
import picgo from '@core/picgo'
|
||||||
|
import { changeCurrentUploader } from '../utils/handleUploaderConfig'
|
||||||
|
|
||||||
const STORE_PATH = dbPathDir()
|
const STORE_PATH = dbPathDir()
|
||||||
const LOG_PATH = path.join(STORE_PATH, 'piclist.log')
|
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 ({
|
router.post('/upload', async ({
|
||||||
response,
|
response,
|
||||||
list = []
|
list = [],
|
||||||
|
urlparams
|
||||||
} : {
|
} : {
|
||||||
response: IHttpResponse,
|
response: IHttpResponse,
|
||||||
list?: string[]
|
list?: string[],
|
||||||
|
urlparams?: URLSearchParams
|
||||||
}): Promise<void> => {
|
}): Promise<void> => {
|
||||||
try {
|
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) {
|
if (list.length === 0) {
|
||||||
// upload with clipboard
|
// upload with clipboard
|
||||||
logger.info('[PicList Server] upload clipboard file')
|
logger.info('[PicList Server] upload clipboard file')
|
||||||
@@ -83,6 +112,9 @@ router.post('/upload', async ({
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (needRestore) {
|
||||||
|
changeCurrentUploader(currentPicBedType, currentPicBedConfig, currentPicBedConfigId)
|
||||||
|
}
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
logger.error(err)
|
logger.error(err)
|
||||||
handleResponse({
|
handleResponse({
|
||||||
|
|||||||
@@ -10,14 +10,26 @@
|
|||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
class="view-title"
|
class="view-title"
|
||||||
@click="handleNameClick"
|
|
||||||
>
|
>
|
||||||
{{ picBedName }} {{ $T('SETTINGS') }}
|
<span
|
||||||
|
class="view-title-text"
|
||||||
|
@click="handleNameClick"
|
||||||
|
>
|
||||||
|
{{ picBedName }} {{ $T('SETTINGS') }}</span>
|
||||||
<el-icon
|
<el-icon
|
||||||
v-if="linkToLogInList.includes(picBedName)"
|
v-if="linkToLogInList.includes(picBedName)"
|
||||||
>
|
>
|
||||||
<Link />
|
<Link />
|
||||||
</el-icon>
|
</el-icon>
|
||||||
|
<el-button
|
||||||
|
type="primary"
|
||||||
|
round
|
||||||
|
size="small"
|
||||||
|
style="margin-left: 6px"
|
||||||
|
@click="handleCopyApi"
|
||||||
|
>
|
||||||
|
{{ $T('UPLOAD_PAGE_COPY_UPLOAD_API') }}
|
||||||
|
</el-button>
|
||||||
</div>
|
</div>
|
||||||
<config-form
|
<config-form
|
||||||
v-if="config.length > 0"
|
v-if="config.length > 0"
|
||||||
@@ -95,7 +107,7 @@ import { ref, onBeforeUnmount, onBeforeMount } from 'vue'
|
|||||||
import { T as $T } from '@/i18n/index'
|
import { T as $T } from '@/i18n/index'
|
||||||
|
|
||||||
// 数据发送工具函数
|
// 数据发送工具函数
|
||||||
import { sendToMain, triggerRPC } from '@/utils/dataSender'
|
import { getConfig, sendToMain, triggerRPC } from '@/utils/dataSender'
|
||||||
|
|
||||||
// Vue Router 相关
|
// Vue Router 相关
|
||||||
import { useRoute, useRouter } from 'vue-router'
|
import { useRoute, useRouter } from 'vue-router'
|
||||||
@@ -105,6 +117,7 @@ import ConfigForm from '@/components/ConfigForm.vue'
|
|||||||
|
|
||||||
// Electron 相关
|
// Electron 相关
|
||||||
import {
|
import {
|
||||||
|
clipboard,
|
||||||
ipcRenderer,
|
ipcRenderer,
|
||||||
IpcRendererEvent
|
IpcRendererEvent
|
||||||
} from 'electron'
|
} from 'electron'
|
||||||
@@ -119,7 +132,7 @@ import { Link } from '@element-plus/icons-vue'
|
|||||||
import dayjs from 'dayjs'
|
import dayjs from 'dayjs'
|
||||||
|
|
||||||
// Element Plus 下拉菜单组件
|
// Element Plus 下拉菜单组件
|
||||||
import { ElDropdown } from 'element-plus'
|
import { ElDropdown, ElMessage } from 'element-plus'
|
||||||
|
|
||||||
const type = ref('')
|
const type = ref('')
|
||||||
const config = ref<IPicGoPluginConfig[]>([])
|
const config = ref<IPicGoPluginConfig[]>([])
|
||||||
@@ -187,7 +200,7 @@ const handleReset = async () => {
|
|||||||
$router.back()
|
$router.back()
|
||||||
}
|
}
|
||||||
|
|
||||||
const linkToLogInList = ['github', 'tcyun', 'aliyun', 'smms', 'qiniu', 'imgur', 'upyun', 'githubPlus']
|
const linkToLogInList = ['GitHub', '腾讯云COS', '阿里云OSS', 'SM.MS', '七牛云', 'Imgur', '又拍云', 'githubPlus']
|
||||||
|
|
||||||
function handleNameClick () {
|
function handleNameClick () {
|
||||||
switch ($route.params.type) {
|
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
|
config.value = _config
|
||||||
picBedName.value = name
|
picBedName.value = name
|
||||||
}
|
}
|
||||||
@@ -245,7 +277,7 @@ export default {
|
|||||||
height 100%
|
height 100%
|
||||||
overflow-y auto
|
overflow-y auto
|
||||||
overflow-x hidden
|
overflow-x hidden
|
||||||
.view-title
|
.view-title-text
|
||||||
&:hover
|
&:hover
|
||||||
cursor pointer
|
cursor pointer
|
||||||
color #409EFF
|
color #409EFF
|
||||||
|
|||||||
Vendored
+1
@@ -96,6 +96,7 @@ interface ILocales {
|
|||||||
GALLERY_SEARCH_FILENAME: string
|
GALLERY_SEARCH_FILENAME: string
|
||||||
GALLERY_SEARCH_URL: string
|
GALLERY_SEARCH_URL: string
|
||||||
GALLERY_MATCHED: string
|
GALLERY_MATCHED: string
|
||||||
|
UPLOAD_PAGE_COPY_UPLOAD_API: string
|
||||||
UPLOAD_PAGE_IMAGE_PROCESS_NAME: string
|
UPLOAD_PAGE_IMAGE_PROCESS_NAME: string
|
||||||
UPLOAD_PAGE_IMAGE_PROCESS_DIALOG_TITLE: string
|
UPLOAD_PAGE_IMAGE_PROCESS_DIALOG_TITLE: string
|
||||||
UPLOAD_PAGE_IMAGE_PROCESS_ISADDWM: string
|
UPLOAD_PAGE_IMAGE_PROCESS_ISADDWM: string
|
||||||
|
|||||||
Reference in New Issue
Block a user