koishi-plugin-minecraft-notifier 1.2.2 → 1.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/gitee-helper.d.ts +2 -3
- package/lib/index.cjs +94 -30
- package/package.json +1 -1
package/lib/gitee-helper.d.ts
CHANGED
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
import { AxiosResponse } from 'axios';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* 上传或更新 Gitee 仓库中的文本文件(如果不存在则创建,如果存在则更新)
|
|
4
4
|
* @param owner - 仓库所有者用户名
|
|
5
5
|
* @param repo - 仓库名称
|
|
6
6
|
* @param path - 文件路径(例如 'docs/update.txt')
|
|
7
7
|
* @param content - 文件内容(纯文本字符串,会自动 Base64 编码)
|
|
8
|
-
* @param sha - 文件的当前 SHA 值(通过 GET contents API 获取,用于更新)
|
|
9
8
|
* @param message - Commit 消息
|
|
10
9
|
* @param token - Gitee Personal Access Token
|
|
11
10
|
* @param branch - 分支名(默认 'master')
|
|
12
11
|
* @returns Promise<{ success: boolean; data?: AxiosResponse; error?: string }>
|
|
13
12
|
*/
|
|
14
|
-
export declare function
|
|
13
|
+
export declare function upsertFileToGitee(owner: string, repo: string, path: string, content: string, message: string, token: string, branch?: string): Promise<{
|
|
15
14
|
success: boolean;
|
|
16
15
|
data?: AxiosResponse;
|
|
17
16
|
error?: string;
|
package/lib/index.cjs
CHANGED
|
@@ -123,36 +123,88 @@ var import_node_path = __toESM(require("node:path"), 1);
|
|
|
123
123
|
|
|
124
124
|
// src/gitee-helper.ts
|
|
125
125
|
var import_axios = __toESM(require("axios"), 1);
|
|
126
|
-
async function
|
|
126
|
+
async function upsertFileToGitee(owner, repo, path3, content, message, token, branch = "master") {
|
|
127
127
|
const base64Content = Buffer.from(content, "utf-8").toString("base64");
|
|
128
|
-
const
|
|
128
|
+
const checkUrl = `https://gitee.com/api/v5/repos/${owner}/${repo}/contents/${path3}?ref=${branch}&access_token=${token}`;
|
|
129
|
+
let fileSha = null;
|
|
129
130
|
try {
|
|
130
|
-
const
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
{
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
131
|
+
const checkResponse = await import_axios.default.get(checkUrl);
|
|
132
|
+
if (checkResponse.status === 200) {
|
|
133
|
+
fileSha = checkResponse.data.sha;
|
|
134
|
+
} else {
|
|
135
|
+
throw new Error(`Unexpected status: ${checkResponse.status}`);
|
|
136
|
+
}
|
|
137
|
+
} catch (checkError) {
|
|
138
|
+
if (checkError.response?.status === 404) {
|
|
139
|
+
const createUrl = `https://gitee.com/api/v5/repos/${owner}/${repo}/contents/${path3}`;
|
|
140
|
+
try {
|
|
141
|
+
const createResponse = await import_axios.default.post(
|
|
142
|
+
createUrl,
|
|
143
|
+
{
|
|
144
|
+
access_token: token,
|
|
145
|
+
content: base64Content,
|
|
146
|
+
message,
|
|
147
|
+
branch
|
|
148
|
+
},
|
|
149
|
+
{
|
|
150
|
+
headers: {
|
|
151
|
+
"Content-Type": "application/json"
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
);
|
|
155
|
+
return { success: true, data: createResponse };
|
|
156
|
+
} catch (createError) {
|
|
157
|
+
console.error(
|
|
158
|
+
"Gitee Create Error:",
|
|
159
|
+
createError.response?.data || createError.message
|
|
160
|
+
);
|
|
161
|
+
return {
|
|
162
|
+
success: false,
|
|
163
|
+
error: createError.response?.data?.message || createError.message
|
|
164
|
+
};
|
|
143
165
|
}
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
166
|
+
} else {
|
|
167
|
+
console.error(
|
|
168
|
+
"Gitee Check Error:",
|
|
169
|
+
checkError.response?.data || checkError.message
|
|
170
|
+
);
|
|
171
|
+
return {
|
|
172
|
+
success: false,
|
|
173
|
+
error: checkError.response?.data?.message || checkError.message
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
if (fileSha) {
|
|
178
|
+
const updateUrl = `https://gitee.com/api/v5/repos/${owner}/${repo}/contents/${path3}`;
|
|
179
|
+
try {
|
|
180
|
+
const updateResponse = await import_axios.default.put(
|
|
181
|
+
updateUrl,
|
|
182
|
+
{
|
|
183
|
+
access_token: token,
|
|
184
|
+
content: base64Content,
|
|
185
|
+
sha: fileSha,
|
|
186
|
+
message,
|
|
187
|
+
branch
|
|
188
|
+
},
|
|
189
|
+
{
|
|
190
|
+
headers: {
|
|
191
|
+
"Content-Type": "application/json"
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
);
|
|
195
|
+
return { success: true, data: updateResponse };
|
|
196
|
+
} catch (updateError) {
|
|
197
|
+
console.error(
|
|
198
|
+
"Gitee Update Error:",
|
|
199
|
+
updateError.response?.data || updateError.message
|
|
200
|
+
);
|
|
201
|
+
return {
|
|
202
|
+
success: false,
|
|
203
|
+
error: updateError.response?.data?.message || updateError.message
|
|
204
|
+
};
|
|
205
|
+
}
|
|
155
206
|
}
|
|
207
|
+
return { success: false, error: "Failed to determine file existence" };
|
|
156
208
|
}
|
|
157
209
|
|
|
158
210
|
// src/xaml-generator.ts
|
|
@@ -293,7 +345,7 @@ async function exportXaml(ctx, cfg, summary, version) {
|
|
|
293
345
|
await import_node_fs.promises.writeFile(fullXamlPath, xaml);
|
|
294
346
|
await import_node_fs.promises.copyFile(fullXamlPath, fullHomePagePath);
|
|
295
347
|
if (cfg.giteeApiToken && cfg.giteeOwner && cfg.giteeRepo) {
|
|
296
|
-
await
|
|
348
|
+
await upsertFileToGitee(
|
|
297
349
|
cfg.giteeOwner,
|
|
298
350
|
cfg.giteeRepo,
|
|
299
351
|
"Custom.xaml",
|
|
@@ -301,7 +353,19 @@ async function exportXaml(ctx, cfg, summary, version) {
|
|
|
301
353
|
`feat: update PCL HomePage XAML for version ${version}`,
|
|
302
354
|
cfg.giteeApiToken,
|
|
303
355
|
"master"
|
|
304
|
-
)
|
|
356
|
+
).then((result) => {
|
|
357
|
+
if (result.success) {
|
|
358
|
+
ctx.logger("minecraft-notifier").info(
|
|
359
|
+
"Upsert successful:",
|
|
360
|
+
result.data?.data
|
|
361
|
+
);
|
|
362
|
+
} else {
|
|
363
|
+
ctx.logger("minecraft-notifier").warn(
|
|
364
|
+
"Upsert failed:",
|
|
365
|
+
result.error
|
|
366
|
+
);
|
|
367
|
+
}
|
|
368
|
+
});
|
|
305
369
|
}
|
|
306
370
|
return fullXamlPath;
|
|
307
371
|
}
|
|
@@ -615,9 +679,9 @@ var Config = import_koishi.Schema.object({
|
|
|
615
679
|
checkInterval: import_koishi.Schema.number().default(3).description("\u5728\u7EBF\u72B6\u6001\u68C0\u67E5\u95F4\u9694\uFF08\u5206\u949F\uFF09"),
|
|
616
680
|
baseApiUrl: import_koishi.Schema.string().default("https://api.openai.com/v1").description("AI \u63A5\u53E3\u7684\u57FA\u7840 URL"),
|
|
617
681
|
model: import_koishi.Schema.string().default("gpt-5").description("\u4F7F\u7528\u7684 AI \u6A21\u578B"),
|
|
618
|
-
apiKey: import_koishi.Schema.string().default("").description("AI \u63A5\u53E3\u7684 API \u5BC6\u94A5").required(),
|
|
682
|
+
apiKey: import_koishi.Schema.string().role("secret").default("").description("AI \u63A5\u53E3\u7684 API \u5BC6\u94A5").required(),
|
|
619
683
|
notifyChannel: import_koishi.Schema.array(String).default([]).description("\u7528\u4E8E\u63A5\u6536\u66F4\u65B0\u901A\u77E5\u7684\u9891\u9053 ID \u5217\u8868"),
|
|
620
|
-
giteeApiToken: import_koishi.Schema.string().default("").description("Gitee API \u8BBF\u95EE\u4EE4\u724C\uFF0C\u7528\u4E8E\u4E0A\u4F20 XAML \u6587\u4EF6"),
|
|
684
|
+
giteeApiToken: import_koishi.Schema.string().role("secret").default("").description("Gitee API \u8BBF\u95EE\u4EE4\u724C\uFF0C\u7528\u4E8E\u4E0A\u4F20 XAML \u6587\u4EF6"),
|
|
621
685
|
giteeOwner: import_koishi.Schema.string().default("").description("Gitee \u4ED3\u5E93\u6240\u6709\u8005\u7528\u6237\u540D"),
|
|
622
686
|
giteeRepo: import_koishi.Schema.string().default("").description("Gitee \u4ED3\u5E93\u540D\u79F0")
|
|
623
687
|
});
|
package/package.json
CHANGED