From 17a4fb171bb564642dfb9853a8aff32a0b77a528 Mon Sep 17 00:00:00 2001 From: HIsheR Date: Fri, 23 Oct 2026 15:26:47 +0800 Subject: [PATCH] =?UTF-8?q?iter:=20=E6=96=B0=E5=A2=9E=20Gitea=20REST=20API?= =?UTF-8?q?=20=E5=8C=85=E8=A3=85=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/gitea-api.mjs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 scripts/gitea-api.mjs diff --git a/scripts/gitea-api.mjs b/scripts/gitea-api.mjs new file mode 100644 index 0000000..6bfaedd --- /dev/null +++ b/scripts/gitea-api.mjs @@ -0,0 +1,19 @@ +/*** 作用:Gitea REST API 调用包装器,用法 node scripts/gitea-api.mjs [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 [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);