koishi-plugin-minecraft-notifier 1.3.0 → 1.3.1
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 +3 -1
- package/lib/index.cjs +55 -8
- package/package.json +1 -1
package/lib/gitee-helper.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { AxiosResponse } from 'axios';
|
|
2
|
+
import { Context } from 'koishi';
|
|
2
3
|
/**
|
|
3
4
|
* 上传或更新 Gitee 仓库中的文本文件(如果不存在则创建,如果存在则更新)
|
|
5
|
+
* @param ctx
|
|
4
6
|
* @param owner - 仓库所有者用户名
|
|
5
7
|
* @param repo - 仓库名称
|
|
6
8
|
* @param path - 文件路径(例如 'docs/update.txt')
|
|
@@ -10,7 +12,7 @@ import { AxiosResponse } from 'axios';
|
|
|
10
12
|
* @param branch - 分支名(默认 'master')
|
|
11
13
|
* @returns Promise<{ success: boolean; data?: AxiosResponse; error?: string }>
|
|
12
14
|
*/
|
|
13
|
-
export declare function upsertFileToGitee(owner: string, repo: string, path: string, content: string, message: string, token: string, branch?: string): Promise<{
|
|
15
|
+
export declare function upsertFileToGitee(ctx: Context, owner: string, repo: string, path: string, content: string, message: string, token: string, branch?: string): Promise<{
|
|
14
16
|
success: boolean;
|
|
15
17
|
data?: AxiosResponse;
|
|
16
18
|
error?: string;
|
package/lib/index.cjs
CHANGED
|
@@ -123,23 +123,30 @@ 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 upsertFileToGitee(owner, repo, path3, content, message, token, branch = "master") {
|
|
126
|
+
async function upsertFileToGitee(ctx, owner, repo, path3, content, message, token, branch = "master") {
|
|
127
127
|
const base64Content = Buffer.from(content, "utf-8").toString("base64");
|
|
128
128
|
const checkUrl = `https://gitee.com/api/v5/repos/${owner}/${repo}/contents/${path3}?ref=${branch}&access_token=${token}`;
|
|
129
129
|
let fileSha = null;
|
|
130
130
|
try {
|
|
131
131
|
const checkResponse = await import_axios.default.get(checkUrl);
|
|
132
132
|
if (checkResponse.status === 200) {
|
|
133
|
-
|
|
133
|
+
if (Array.isArray(checkResponse.data) && checkResponse.data.length === 0) {
|
|
134
|
+
} else if (checkResponse.data.sha) {
|
|
135
|
+
fileSha = checkResponse.data.sha;
|
|
136
|
+
} else {
|
|
137
|
+
}
|
|
134
138
|
} else {
|
|
139
|
+
ctx.logger("minecraft-notifier").warn(
|
|
140
|
+
`Unexpected status code when checking file: ${checkResponse.status}`
|
|
141
|
+
);
|
|
135
142
|
throw new Error(`Unexpected status: ${checkResponse.status}`);
|
|
136
143
|
}
|
|
137
144
|
} catch (checkError) {
|
|
138
145
|
if (checkError.response?.status === 404) {
|
|
139
|
-
const
|
|
146
|
+
const createUrl2 = `https://gitee.com/api/v5/repos/${owner}/${repo}/contents/${path3}`;
|
|
140
147
|
try {
|
|
141
148
|
const createResponse = await import_axios.default.post(
|
|
142
|
-
|
|
149
|
+
createUrl2,
|
|
143
150
|
{
|
|
144
151
|
access_token: token,
|
|
145
152
|
content: base64Content,
|
|
@@ -154,7 +161,7 @@ async function upsertFileToGitee(owner, repo, path3, content, message, token, br
|
|
|
154
161
|
);
|
|
155
162
|
return { success: true, data: createResponse };
|
|
156
163
|
} catch (createError) {
|
|
157
|
-
|
|
164
|
+
ctx.logger("minecraft-notifier").warn(
|
|
158
165
|
"Gitee Create Error:",
|
|
159
166
|
createError.response?.data || createError.message
|
|
160
167
|
);
|
|
@@ -164,7 +171,7 @@ async function upsertFileToGitee(owner, repo, path3, content, message, token, br
|
|
|
164
171
|
};
|
|
165
172
|
}
|
|
166
173
|
} else {
|
|
167
|
-
|
|
174
|
+
ctx.logger("minecraft-notifier").warn(
|
|
168
175
|
"Gitee Check Error:",
|
|
169
176
|
checkError.response?.data || checkError.message
|
|
170
177
|
);
|
|
@@ -194,7 +201,7 @@ async function upsertFileToGitee(owner, repo, path3, content, message, token, br
|
|
|
194
201
|
);
|
|
195
202
|
return { success: true, data: updateResponse };
|
|
196
203
|
} catch (updateError) {
|
|
197
|
-
|
|
204
|
+
ctx.logger("minecraft-notifier").warn(
|
|
198
205
|
"Gitee Update Error:",
|
|
199
206
|
updateError.response?.data || updateError.message
|
|
200
207
|
);
|
|
@@ -204,7 +211,33 @@ async function upsertFileToGitee(owner, repo, path3, content, message, token, br
|
|
|
204
211
|
};
|
|
205
212
|
}
|
|
206
213
|
}
|
|
207
|
-
|
|
214
|
+
const createUrl = `https://gitee.com/api/v5/repos/${owner}/${repo}/contents/${path3}`;
|
|
215
|
+
try {
|
|
216
|
+
const createResponse = await import_axios.default.post(
|
|
217
|
+
createUrl,
|
|
218
|
+
{
|
|
219
|
+
access_token: token,
|
|
220
|
+
content: base64Content,
|
|
221
|
+
message,
|
|
222
|
+
branch
|
|
223
|
+
},
|
|
224
|
+
{
|
|
225
|
+
headers: {
|
|
226
|
+
"Content-Type": "application/json"
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
);
|
|
230
|
+
return { success: true, data: createResponse };
|
|
231
|
+
} catch (createError) {
|
|
232
|
+
ctx.logger("minecraft-notifier").warn(
|
|
233
|
+
"Gitee Create Error:",
|
|
234
|
+
createError.response?.data || createError.message
|
|
235
|
+
);
|
|
236
|
+
return {
|
|
237
|
+
success: false,
|
|
238
|
+
error: createError.response?.data?.message || createError.message
|
|
239
|
+
};
|
|
240
|
+
}
|
|
208
241
|
}
|
|
209
242
|
|
|
210
243
|
// src/xaml-generator.ts
|
|
@@ -346,6 +379,7 @@ async function exportXaml(ctx, cfg, summary, version) {
|
|
|
346
379
|
await import_node_fs.promises.copyFile(fullXamlPath, fullHomePagePath);
|
|
347
380
|
if (cfg.giteeApiToken && cfg.giteeOwner && cfg.giteeRepo) {
|
|
348
381
|
await upsertFileToGitee(
|
|
382
|
+
ctx,
|
|
349
383
|
cfg.giteeOwner,
|
|
350
384
|
cfg.giteeRepo,
|
|
351
385
|
"Custom.xaml",
|
|
@@ -367,6 +401,7 @@ async function exportXaml(ctx, cfg, summary, version) {
|
|
|
367
401
|
}
|
|
368
402
|
});
|
|
369
403
|
await upsertFileToGitee(
|
|
404
|
+
ctx,
|
|
370
405
|
cfg.giteeOwner,
|
|
371
406
|
cfg.giteeRepo,
|
|
372
407
|
"Custom.xaml.ini",
|
|
@@ -783,6 +818,18 @@ function apply(ctx, cfg) {
|
|
|
783
818
|
let fullHomePagePath = import_node_path2.default.join(xamlPath, "PCL.HomePage.xaml");
|
|
784
819
|
koaCtx.response.body = await import_node_fs2.promises.readFile(fullHomePagePath);
|
|
785
820
|
});
|
|
821
|
+
ctx.command("test").action(async ({ session }) => {
|
|
822
|
+
await upsertFileToGitee(
|
|
823
|
+
ctx,
|
|
824
|
+
"pynickle",
|
|
825
|
+
"PCL-AI-Summary-HomePage",
|
|
826
|
+
"Custom.xaml",
|
|
827
|
+
"111",
|
|
828
|
+
`feat: update PCL HomePage XAML for version 111`,
|
|
829
|
+
"c8629ca06822133e7d8b497c6e71cc7a",
|
|
830
|
+
"master"
|
|
831
|
+
);
|
|
832
|
+
});
|
|
786
833
|
ctx.setInterval(async () => {
|
|
787
834
|
try {
|
|
788
835
|
await loadData();
|
package/package.json
CHANGED