Skip to content

Commit

Permalink
✨ 新增上传网盘功能
Browse files Browse the repository at this point in the history
  • Loading branch information
AnkioTomas committed Mar 10, 2024
1 parent a34de86 commit a21175b
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 9 deletions.
16 changes: 8 additions & 8 deletions configuration.json → .github/workflows/configuration.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,45 +2,45 @@
"categories": [
{
"title": "## 🚀 Features",
"labels": ["feat","feats"]
"labels": ["feat","feats","sparkles"]
},
{
"title": "## \uD83C\uDF1F Optimizes",
"labels": ["pref"]
"labels": ["art","zap","lipstick"]
},
{
"title": "## 🐛 Fixes",
"labels": ["bug","fix"]
"labels": ["bug","fix","ambulance"]
},
{
"title": "## 🧪 Tests",
"labels": ["🧪","test","tests"]
},
{
"title": "## 💬 Other",
"labels": ["💬", "🚨","other"]
"labels": ["fire", "rocket","other","tada","construction_worker","green_heart"]
},
{
"title": "## \uD83D\uDCD6 Docs",
"labels": ["doc","docs"]
"labels": ["doc","docs","memo"]
},
{
"title": "## 📦 Dependencies",
"labels": ["dependencies","deps"]
"labels": ["dependencies","deps","arrow_down","arrow_up"]
}
],
"template": "${{CHANGELOG}}",
"pr_template": "- **${{TITLE}}**",
"label_extractor": [
{
"pattern": "(\\w+):(.+)",
"pattern": ":(.+): (.+)",
"target": "$1",
"on_property": "title"
}
],
"transformers": [
{
"pattern": "(\\w+):(.+)",
"pattern": ":(.+): (.+)",
"target": "$2"
}
],
Expand Down
14 changes: 13 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,21 @@ jobs:
uses: mikepenz/release-changelog-builder-action@v3
with:
commitMode: true
configuration: "configuration.json"
configuration: ".github/workflows/configuration.json"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Generate Tag Name
id: tag_name
run: echo "TAG_VERSION_NAME=v${{ env.VERSION_NAME }}" >> $GITHUB_ENV
- name: Upload Apks
id: upload_apk
run: pip install requests && python .github/workflows/upload.py
env:
CHANGELOG: ${{steps.github_release.outputs.changelog}}
GITHUB_WORKSPACE: ${{ env.GITHUB_WORKSPACE }}
HOST_ENV_VAR: ${{ secrets.HOST_ENV_VAR }}
USERNAME_ENV_VAR: ${{ secrets.USERNAME_ENV_VAR }}
PASSWORD_ENV_VAR: ${{ secrets.PASSWORD_ENV_VAR }}
- name: Create Release
uses: mikepenz/[email protected] #softprops/action-gh-release
with:
Expand Down
88 changes: 88 additions & 0 deletions .github/workflows/upload.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
from urllib.parse import quote

import requests
import markdown
import json
import os
import re
# 登录
username = os.getenv('USERNAME_ENV_VAR')
password = os.getenv('PASSWORD_ENV_VAR')
import hashlib

hash_salt = "https://github.com/alist-org/alist"
to_hash = f"{password}-{hash_salt}"
hashed_password = hashlib.sha256(to_hash.encode()).hexdigest()

# host
host = os.getenv('HOST_ENV_VAR')
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) '
'Chrome/58.0.3029.110 Safari/537.3'
}
url = host + '/api/auth/login/hash'

d = {'Username': username, 'Password': hashed_password}
r = requests.post(url, data=d, headers=headers)

# 对登录后返回的数据进行解析
data = json.loads(r.text)

token = data.get('data').get('token')



def extract_int(s):
# 使用正则表达式匹配字符串中的第一个连续数字序列
match = re.search(r'\d+', s.replace(".", ""))
if match:
# 如果找到数字,将其转换为整数
return int(match.group())
else:
# 如果没有找到数字,返回 None 或抛出异常
return 0

def upload(filename, filename_new, auth):
# 上传文件
url2 = host + "/api/fs/put"
filename_new = quote('/阿里云盘/自动记账/规则更新/' + filename_new, 'utf-8') # 对文件名进行URL编码
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) '
'Chrome/58.0.3029.110 Safari/537.3',
'Authorization': auth,
'file-path': filename_new
}
dir = os.getenv("GITHUB_WORKSPACE")
# 读取文件内容
with open(dir+filename, 'rb') as file:
file_data = file.read()
res = requests.put(url=url2, data=file_data, headers=headers)
print(res.text)

name = os.getenv("TAG_VERSION_NAME")

changeLog = os.getenv('CHANGELOG')
html = markdown.markdown(changeLog)

t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())

data= {
"version": name,
"code": extract_int(name),
"log": html,
"date": t
}

json_str = json.dumps(data, indent=4)

with open(os.getenv("GITHUB_WORKSPACE")+"/dist/index.json", 'w') as file:
file.writelines(json_str)

with open(os.getenv("GITHUB_WORKSPACE")+"/dist/README.md", 'w') as file:
file.writelines("# 更新日志\n - 时间:"+t+"\n - 版本:"+name+"\n"+changeLog)

upload("/dist/README.md", "README.md", token)
upload("/dist/index.json", "index.json", token)
upload("/dist/category.js", "category.js", token)
upload("/dist/rule.js", "rule.js", token)
# TODO 除了上传文件到服务器以外,还需要通过bot通知到自动记账群的用户。

0 comments on commit a21175b

Please sign in to comment.