index.mjs 1.1 KB

123456789101112131415161718192021222324252627282930
  1. #!/usr/bin/env node
  2. /**
  3. * Fmode 静态发布(OBS+CDN 公开 URL) — 辅助脚本(零 npm 依赖,Node>=18 自带 fetch)
  4. * Copyright (c) 未来飞马 MPL-2.0
  5. *
  6. * 用法:node index.mjs <action> [jsonPayload]
  7. */
  8. const BASE = "https://server.fmode.cn";
  9. async function call(method, path, body, token) {
  10. const headers = { "content-type": "application/json" };
  11. if (token) headers["authorization"] = "Bearer " + token;
  12. const res = await fetch(BASE + path, {
  13. method, headers, body: body ? JSON.stringify(body) : undefined,
  14. });
  15. const text = await res.text();
  16. // 脱敏输出:token/密钥不打印
  17. const safe = text.replace(/(token|authorization|accessKey|secretKey|securityToken)["'\s:]+([^",}]+)/gi, "$1:***");
  18. console.log(safe);
  19. return res;
  20. }
  21. const [action, raw] = process.argv.slice(2);
  22. let payload = {};
  23. try { if (raw) payload = JSON.parse(raw); } catch { payload = { _raw: raw }; }
  24. // 示例端点: POST 注册 Project {token,path:/fmode/project-register,params:{name,version,gitUrl}}
  25. // 示例端点: POST 取 STS {token,projectId}
  26. // 示例端点: POST CDN 刷新 {token,projectId,path}