chore: sync ops/gitea_push.js
This commit is contained in:
1 parent
1168b94e67
commit
47c27f4176
1 file changed
+27
@@ -0,0 +1,27 @@
|
||||
// 批量推送文件到 Gitea: node gitea_push.js <localPath>:<repoPath> ...
|
||||
const FS = require("fs");
|
||||
const B = "http://localhost:3001/api/v1/repos/admin/mini-erp-fabric-demo/contents/";
|
||||
const H = { Authorization: "token 77c6bd2fdab535b2720821d36b4cfb74aa3bf87c", "Content-Type": "application/json" };
|
||||
|
||||
async function push(lp, rp) {
|
||||
const content = FS.readFileSync(lp).toString("base64");
|
||||
const g = await fetch(B + rp, { headers: H });
|
||||
let sha = "";
|
||||
if (g.status === 200) sha = (await g.json()).sha || "";
|
||||
const body = { content, branch: "main", message: "chore: sync " + rp };
|
||||
if (sha) body.sha = sha;
|
||||
const r = await fetch(B + rp, { method: sha ? "PUT" : "POST", headers: H, body: JSON.stringify(body) });
|
||||
const ok = r.status === 200 || r.status === 201;
|
||||
console.log((ok ? "PUSH_OK " : "PUSH_ERR ") + rp + " " + r.status + (ok ? "" : " " + (await r.text()).slice(0, 120)));
|
||||
return ok;
|
||||
}
|
||||
|
||||
(async () => {
|
||||
let fail = 0;
|
||||
for (const arg of process.argv.slice(2)) {
|
||||
const i = arg.indexOf(":");
|
||||
const lp = arg.slice(0, i), rp = arg.slice(i + 1);
|
||||
if (!(await push(lp, rp))) fail++;
|
||||
}
|
||||
process.exit(fail ? 1 : 0);
|
||||
})();
|
||||
Reference in new issue
Block a user