diff --git a/.github/workflows/demo1-MAA.yml b/.github/workflows/demo1-MAA.yml new file mode 100644 index 0000000..c218751 --- /dev/null +++ b/.github/workflows/demo1-MAA.yml @@ -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 }} diff --git a/action.yml b/action.yml index 53ca113..6e6aa9e 100644 --- a/action.yml +++ b/action.yml @@ -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() diff --git a/python/requirements.txt b/python/requirements.txt new file mode 100644 index 0000000..f229360 --- /dev/null +++ b/python/requirements.txt @@ -0,0 +1 @@ +requests diff --git a/python/upload.py b/python/upload.py new file mode 100644 index 0000000..241b308 --- /dev/null +++ b/python/upload.py @@ -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)