Skip to content

Commit

Permalink
refactor: new API
Browse files Browse the repository at this point in the history
  • Loading branch information
MistEO committed Mar 1, 2025
1 parent 1a55136 commit 093a533
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 37 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/demo1-MAA.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: demo1-MAA

on:
workflow_dispatch:
push:
paths:
- "action.yml"
- "python/**"
- ".github/workflows/demo1.yml"

jobs:
mirrorchyan:
runs-on: macos-latest
strategy:
matrix:
os: [win]
arch: [arm64, x64]
steps:
- id: uploading
uses: MirrorChyan/uploading-action@v1
with:
filetype: latest-release
filename: "*MAA-*-${{ matrix.os }}-${{ matrix.arch }}.zip"
mirrorchyan_rid: demo1

github_token: ${{ secrets.GITHUB_TOKEN }}

owner: MaaAssistantArknights
repo: MaaAssistantArknights
upload_token: ${{ secrets.MirrorChyanUploadTokenForDemo1 }}
os: ${{ matrix.os }}
arch: ${{ matrix.arch }}
40 changes: 3 additions & 37 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -166,43 +166,9 @@ runs:
id: upload
shell: bash
run: |
if [[ ${{ inputs.fake_upload }} != true ]]; then
response=$(curl -k --location --request POST 'https://www.mirrorchyan.com/api/resources/${{ inputs.mirrorchyan_rid }}/versions' \
--header 'Authorization:${{ inputs.upload_token }}' \
--form 'os="${{ inputs.os }}"' \
--form 'arch="${{ inputs.arch }}"' \
--form 'channel="${{ steps.information.outputs.channel }}"' \
--form 'name="${{ steps.information.outputs.version_name }}"' \
--form 'file=@"${{ steps.information.outputs.filename }}"')
else
curl --output /dev/null --location --request POST 'www.github.com' \
--header 'Authorization:${{ inputs.upload_token }}' \
--form 'os="${{ inputs.os }}"' \
--form 'arch="${{ inputs.arch }}"' \
--form 'channel="${{ steps.information.outputs.channel }}"' \
--form 'name="${{ steps.information.outputs.version_name }}"' \
--form 'file=@"${{ steps.information.outputs.filename }}"'
response='{"code":0,"msg":"success","data":{"id":114514,"name":"${{ steps.information.outputs.version_name }}","number":1919810}}'
fi
echo "response=$response" | tee -a "$GITHUB_OUTPUT"
error=$(echo "$response" | jq .code)
msg=$(echo "$response" | jq .msg)
version_id=$(echo "$response" | jq .data.id)
version_name=$(echo "$response" | jq .data.name)
version_number=$(echo "$response" | jq .data.number)
echo "error=$error" | tee -a "$GITHUB_OUTPUT"
echo "msg=$msg" | tee -a "$GITHUB_OUTPUT"
echo "version_id=$version_id" | tee -a "$GITHUB_OUTPUT"
echo "version_name=$version_name" | tee -a "$GITHUB_OUTPUT"
echo "version_number=$version_number" | tee -a "$GITHUB_OUTPUT"
if [[ $error != 0 ]]; then
echo "Bad Response!"
exit 1
fi
wget https://raw.githubusercontent.com/MirrorChyan/uploading-action/refs/heads/v1/python/upload.py
python -m pip install requests
python upload.py "${{ inputs.mirrorchyan_rid }}" "${{ steps.information.outputs.version_name }}" "${{ inputs.os }}" "${{ inputs.arch }}" "${{ steps.information.outputs.channel }}" "${{ inputs.upload_token }}" "${{ steps.information.outputs.filename }}"
- name: Create issue if failed
if: failure()
Expand Down
1 change: 1 addition & 0 deletions python/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
requests
77 changes: 77 additions & 0 deletions python/upload.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import sys
import urllib3
import requests

urllib3.disable_warnings()

_, rid, version, os, arch, channel, token, file = sys.argv

data = {
"name": version,
"os": os,
"arch": arch,
"channel": channel,
}

headers = {
"Authorization": token,
"User-Agent": "Apifox/1.0.0 (https://apifox.com)",
"Accept": "*/*",
"Content-Type": "application/x-www-form-urlencoded",
}
print(data)

# step 1

response_1 = requests.post(
f"https://mirrorchyan.com/api/resources/{rid}/versions",
headers=headers,
data=data,
verify=False,
)
print(f"step 1: {response_1.status_code}")

if response_1.status_code != 200:
print(f"step 1 failed: {response_1.status_code}, {response_1.text}")
exit(1)

# step 2
response_1_data = response_1.json()["data"]

response_2 = requests.post(
response_1_data["host"],
data={
"success_action_status": "200",
"name": response_1_data["name"],
"signature": response_1_data["signature"],
"key": response_1_data["key"],
"policy": response_1_data["policy"],
"OSSAccessKeyId": response_1_data["access_key"],
},
files={"file": open(file, "rb")},
verify=False,
)

print(f"step 2: {response_2.status_code}")

if response_2.status_code != 200:
print(f"step 2 failed: {response_2.status_code}, {response_2.text}")
exit(1)

# step 3
data["key"] = response_1_data["key"]

response_3 = requests.post(
f"https://mirrorchyan.com/api/resources/{rid}/versions/callback",
headers=headers,
data=data,
verify=False,
)

print(f"step 3: {response_3.status_code}")

if response_3.status_code != 200:
print(f"step 3 failed: {response_3.status_code}, {response_3.text}")
exit(1)

print(response_3.text)

0 comments on commit 093a533

Please sign in to comment.