diff --git a/api使用和版本发布.md b/api使用和版本发布.md new file mode 100644 index 0000000..32ef81e --- /dev/null +++ b/api使用和版本发布.md @@ -0,0 +1,333 @@ +接口:https://git.ewancle.com/api/swagger 和使用教程:https://docs.gitea.com/zh-cn/development/api-usage +# 全部作用列表https://docs.gitea.com/zh-cn/development/oauth2-provider +curl -X POST "https://git.ewancle.com/api/v1/users/xiehaijun/tokens" \ + -H "Authorization: token f5856ff0aecd675b72c1910bd4a19679927a6ba0" \ + -H "Content-Type: application/json" \ + -d '{ + "name": "full-access-token", + "scopes": [ + "repo", + "repo:status", + "admin:repo_hook", + "admin:org", + "write:issue", + "write:repository", + "read:repository" + ] + }' + +# 管理员账号进行作用域token创建 +curl -X 'POST' \ + 'https://git.ewancle.com/api/v1/users/xiehaijun/tokens' \ + -u 'xiehaijun:Xiehaijun945' \ + -H 'accept: application/json' \ + -H 'Content-Type: application/json' \ + -d '{ + "name": "full-access-token", + "scopes": [ + "write:repository", + "read:repository", + "read:user", + "write:user", + "read:organization", + "write:organization" + ] +}' +# 获取token,需要read:admin,write:admin +curl -X 'GET' \ + 'https://git.ewancle.com/api/v1/users/xiehaijun/tokens' \ + -H "Authorization: token a94110b4fa993133ceb0e04fdabfd70626e02405" \ + -H 'accept: application/json' + + + + +EOF 前有空格或 Tab → 会导致闭合失败(命令行就和run: |下面的行平齐) +你写的是 < ❗ **通用、安全的 fallback 类型:** `application/octet-stream` 可用于所有二进制文件上传,兼容性最强。 + +--- + +## 🧪 示例上传命令 + +```bash +# 上传 zip 文件 +curl -X POST "$GITEA_API_URL/repos/$OWNER/$REPO/releases/$RELEASE_ID/assets?name=release.zip" \ + -H "Authorization: token $GITEA_PAT" \ + -H "Content-Type: application/zip" \ + --data-binary @"dist/release.zip" + +# 上传 sha256 文件 +curl -X POST "$GITEA_API_URL/repos/$OWNER/$REPO/releases/$RELEASE_ID/assets?name=release.zip.sha256" \ + -H "Authorization: token $GITEA_PAT" \ + -H "Content-Type: text/plain" \ + --data-binary @"dist/release.zip.sha256" +``` + +--- + +## ✅ 生成验证文件示例(Shell) + +```bash +# 生成 sha256 验证文件 +sha256sum dist/release.zip > dist/release.zip.sha256 + +# 可选:生成 md5 验证文件 +md5sum dist/release.zip > dist/release.zip.md5 +``` + +--- + +## 🔄 自动 Content-Type 映射 Bash 函数(可嵌入 GitHub Actions) + +```bash +detect_content_type() { + case "$1" in + *.zip) echo "application/zip" ;; + *.tar.gz|*.tgz) echo "application/gzip" ;; + *.exe) echo "application/octet-stream" ;; + *.txt) echo "text/plain" ;; + *.md5|*.sha256) echo "text/plain" ;; + *) echo "application/octet-stream" ;; # fallback + esac +} +``` + +> 然后你就可以这样调用: + +```bash +CONTENT_TYPE=$(detect_content_type "$FILENAME") +``` + +--- + +## ✅ 总结 + +| 文件扩展名 | 推荐 Content-Type | +| --------- | ----------------------------- | +| `.zip` | `application/zip` | +| `.tar.gz` | `application/gzip` | +| `.exe` | `application/octet-stream` | +| `.txt` | `text/plain` | +| `.sha256` | `text/plain` 或 `octet-stream` | +| 其他未知类型 | `application/octet-stream` | + +--- + +如你希望我将这些自动识别上传逻辑封装为 GitHub Actions 步骤或脚本,并上传多个文件到 Gitea,我可以帮你生成一套模板。是否继续? + + + + +你的问题分成两大部分,我们逐一系统回答: + +--- + +# ✅ 一、`.xz`、`.pdf`、`.jpg`、`.mp4` 等常见文件的 Content-Type 设置 + +| 文件扩展名 | 示例文件 | 推荐 `Content-Type` | +| ---------------- | ------------- | ------------------ | +| `.xz` | `data.tar.xz` | `application/x-xz` | +| `.pdf` | `manual.pdf` | `application/pdf` | +| `.jpg` / `.jpeg` | `cover.jpg` | `image/jpeg` | +| `.png` | `image.png` | `image/png` | +| `.mp4` | `video.mp4` | `video/mp4` | +| `.json` | `data.json` | `application/json` | +| `.csv` | `data.csv` | `text/csv` | +| `.xml` | `data.xml` | `application/xml` | + +✅ 如果不确定,可使用通用 `application/octet-stream`,**但推荐精确设置 MIME 类型**,便于 Release 页面或浏览器识别。 + +--- + +# ✅ 二、GitHub 与 Gitee 发布 Release 并上传文件(API 对比) + +--- + +## ✅ GitHub:创建 Release 并上传 Asset 附件 + +### 🔗 GitHub API 文档: + +* [Create Release](https://docs.github.com/en/rest/releases/releases#create-a-release) +* [Upload Release Asset](https://docs.github.com/en/rest/releases/assets?apiVersion=2022-11-28#upload-a-release-asset) + +### 📦 步骤 1:创建 Release + +```bash +response=$(curl -s -X POST "https://api.github.com/repos/OWNER/REPO/releases" \ + -H "Authorization: token $GITHUB_PAT" \ + -H "Content-Type: application/json" \ + -d @- < `file --mime-type` 自动识别 MIME 类型,适合你上传 `.xz`, `.pdf`, `.mp4` 等任意格式。 + +--- + +## ✅ 可选扩展:GitHub Actions 中自动上传多个文件到 Release + +如果你希望我写一份完整的 `matrix` + MIME 自动识别 + GitHub/Gitee 多仓同时发布的 Actions,我可以马上生成。 + +是否继续?你也可以告诉我具体构建产物目录和需要上传哪些类型,我直接帮你生成 YAML 或 Shell。 + + + + + + +