Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

实现非管理员token,实现文件前缀 #22

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,25 @@ export const getConfig = (ctx: PicGo): IPluginConfig[] => {
name: 'token',
type: 'password',
default: userConfig.token ?? '',
message: '填写管理员token,获取请参考alist文档。',
message: '填写用户token,获取请参考alist文档。',
required: true,
alias: '管理员token',
alias: '用户token',
},
{
name: 'path_prefix',
type: 'input',
default: userConfig.path_prefix ?? '',
message: '如果使用的不是管理员token,填写下载直链中的路径前缀',
required: false,
alias: '路径前缀',
},
{
name: 'filename_prefix',
type: 'input',
default: userConfig.filename_prefix ?? '',
message: 'Alist自动为文件名添加的前缀(如果有),如web',
required: false,
alias: '文件名前缀',
},
]
return config
Expand Down
5 changes: 3 additions & 2 deletions src/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ export const handle = async (ctx: PicGo): Promise<PicGo> => {
const userConfig: UserConfig = ctx.getConfig(bedName)
if (!userConfig)
throw new Error("Can't find uploader config")
let { url, path, version } = userConfig
let { url, path, version, path_prefix } = userConfig
const { token } = userConfig
path = rmBothEndSlashes(path)
path_prefix = rmBothEndSlashes(path_prefix)
url = rmEndSlashes(url)
version = Number(version)
const imgList = ctx.output
Expand Down Expand Up @@ -46,7 +47,7 @@ export const handle = async (ctx: PicGo): Promise<PicGo> => {
ctx.log.info(`[请求结果]${JSON.stringify(res)}`)
if (res.code !== Number(200))
throw new Error(`[请求出错]${JSON.stringify(res)}`)
imgList[i].imgUrl = `${url}/d/${path}/${imgList[i].fileName}`
imgList[i].imgUrl = `${url}/d${path_prefix ? `/${path_prefix}` : ''}/${path}/${(userConfig.filename_prefix || '') + imgList[i].fileName}`
}
catch (err) {
throw new Error(`[上传操作]异常:${err.message}`)
Expand Down
2 changes: 2 additions & 0 deletions src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ export interface UserConfig {
url: string
token: string
path: string
path_prefix: string
filename_prefix: string
}

export interface PostOptions {
Expand Down