/
index.ts
125 lines (121 loc) · 3.42 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/*
* GNU GENERAL PUBLIC LICENSE
* Version 3, 29 June 2007
*
* Copyright (C) 2024 Terwer, Inc. <https://terwer.space/>
* Everyone is permitted to copy and distribute verbatim copies
* of this license document, but changing it is not allowed.
*/
import { IAliyunConfig, IPicGo, IPluginConfig } from "../../../types"
import { ILocalesKey } from "../../../i18n/zh-CN"
import { hasNodeEnv } from "universal-picgo-store"
import { handleNode } from "./node"
import { handleWeb } from "./web"
const handle = async (ctx: IPicGo): Promise<IPicGo> => {
if (hasNodeEnv) {
return handleNode(ctx)
}
return handleWeb(ctx)
}
const config = (ctx: IPicGo): IPluginConfig[] => {
const userConfig = ctx.getConfig<IAliyunConfig>("picBed.aliyun") || {}
const config: IPluginConfig[] = [
{
name: "accessKeyId",
type: "input",
get alias() {
return ctx.i18n.translate<ILocalesKey>("PICBED_ALICLOUD_ACCESSKEYID")
},
default: userConfig.accessKeyId || "",
required: true,
},
{
name: "accessKeySecret",
type: "password",
get alias() {
return ctx.i18n.translate<ILocalesKey>("PICBED_ALICLOUD_ACCESSKEYSECRET")
},
default: userConfig.accessKeySecret || "",
required: true,
},
{
name: "bucket",
type: "input",
get alias() {
return ctx.i18n.translate<ILocalesKey>("PICBED_ALICLOUD_BUCKET")
},
default: userConfig.bucket || "",
required: true,
},
{
name: "area",
type: "input",
get prefix() {
return ctx.i18n.translate<ILocalesKey>("PICBED_ALICLOUD_AREA")
},
get alias() {
return ctx.i18n.translate<ILocalesKey>("PICBED_ALICLOUD_AREA")
},
default: userConfig.area || "",
get message() {
return ctx.i18n.translate<ILocalesKey>("PICBED_ALICLOUD_MESSAGE_AREA")
},
required: true,
},
{
name: "path",
type: "input",
get prefix() {
return ctx.i18n.translate<ILocalesKey>("PICBED_ALICLOUD_PATH")
},
get alias() {
return ctx.i18n.translate<ILocalesKey>("PICBED_ALICLOUD_PATH")
},
get message() {
return ctx.i18n.translate<ILocalesKey>("PICBED_ALICLOUD_MESSAGE_PATH")
},
default: userConfig.path || "",
required: false,
},
{
name: "customUrl",
type: "input",
get prefix() {
return ctx.i18n.translate<ILocalesKey>("PICBED_ALICLOUD_CUSTOMURL")
},
get alias() {
return ctx.i18n.translate<ILocalesKey>("PICBED_ALICLOUD_CUSTOMURL")
},
get message() {
return ctx.i18n.translate<ILocalesKey>("PICBED_ALICLOUD_MESSAGE_CUSTOMURL")
},
default: userConfig.customUrl || "",
required: false,
},
{
name: "options",
type: "input",
get prefix() {
return ctx.i18n.translate<ILocalesKey>("PICBED_ALICLOUD_OPTIONS")
},
get alias() {
return ctx.i18n.translate<ILocalesKey>("PICBED_ALICLOUD_OPTIONS")
},
get message() {
return ctx.i18n.translate<ILocalesKey>("PICBED_ALICLOUD_MESSAGE_OPTIONS")
},
default: userConfig.options || "",
required: false,
},
]
return config
}
export default function register(ctx: IPicGo): void {
ctx.helper.uploader.register("aliyun", {
get name() {
return ctx.i18n.translate<ILocalesKey>("PICBED_ALICLOUD")
},
handle,
config,
})
}