Compare commits
1 Commits
main
...
17a4fb171b
| Author | SHA1 | Date | |
|---|---|---|---|
| 17a4fb171b |
@@ -0,0 +1,19 @@
|
||||
/*** 作用:Gitea REST API 调用包装器,用法 node scripts/gitea-api.mjs <METHOD> <path不带前导斜杠> [jsonBody],令牌读自 .gitea-token ***/
|
||||
import { readFileSync } from 'node:fs';
|
||||
|
||||
// 仓库与令牌
|
||||
const base = 'https://gitea.yinyuanjingling.icu/api/v1';
|
||||
const token = readFileSync(new URL('../.gitea-token', import.meta.url), 'utf8').trim();
|
||||
const [method = 'GET', path = '', body = ''] = process.argv.slice(2);
|
||||
// 卫语句:缺参数退出
|
||||
if (!method || !path) { console.error('用法: node scripts/gitea-api.mjs <METHOD> <path> [jsonBody]'); process.exit(2); }
|
||||
|
||||
// 发起请求并输出结果(path 不带前导斜杠,规避 Git Bash MSYS 路径转换篡改)
|
||||
const res = await fetch(`${base}/${path.replace(/^\//, '')}`, {
|
||||
method: method.toUpperCase(),
|
||||
headers: { 'Authorization': `token ${token}`, 'Content-Type': 'application/json' },
|
||||
body: body || undefined,
|
||||
});
|
||||
const text = await res.text();
|
||||
console.log(`HTTP ${res.status}\n${text}`);
|
||||
process.exit(res.ok ? 0 : 1);
|
||||
Reference in New Issue
Block a user