Merge branch 'main' of https://github.com/imzql/blog
This commit is contained in:
commit
03b2473d88
2 files changed
+73
No files matched your search
@@ -0,0 +1,23 @@
|
|||||||
|
name: Refresh CDN
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
refresh-cdn:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: 检出代码
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
- name: 安装 Python
|
||||||
|
uses: actions/setup-python@v2
|
||||||
|
with:
|
||||||
|
python-version: '3.x'
|
||||||
|
- name: 安装依赖
|
||||||
|
run: pip install requests
|
||||||
|
- name: 等待源站部署
|
||||||
|
run: sleep 1m # 这里用了个笨办法,等待 1 分钟后进行刷新
|
||||||
|
- name: 刷新 CDN
|
||||||
|
run: python RefreshCDN.py
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
from hashlib import sha1
|
||||||
|
import hmac
|
||||||
|
import requests
|
||||||
|
import json
|
||||||
|
import urllib
|
||||||
|
import os
|
||||||
|
|
||||||
|
def dogecloud_api(api_path, data={}, json_mode=False):
|
||||||
|
"""
|
||||||
|
调用多吉云API。
|
||||||
|
|
||||||
|
:param api_path: 调用的 API 接口地址,包含 URL 请求参数 QueryString。
|
||||||
|
:param data: POST 的数据,字典格式。
|
||||||
|
:param json_mode: 数据 data 是否以 JSON 格式请求,默认为 false 则使用表单形式。
|
||||||
|
|
||||||
|
:return dict: 返回的数据。
|
||||||
|
"""
|
||||||
|
access_key = '4fa23701981899fb' # 替换为自己的 AccessKey
|
||||||
|
secret_key = 'feea91f5781378c4e7f16da1632fc7fd' # 替换为自己的 SecretKey
|
||||||
|
|
||||||
|
body = ''
|
||||||
|
mime = ''
|
||||||
|
if json_mode:
|
||||||
|
body = json.dumps(data)
|
||||||
|
mime = 'application/json'
|
||||||
|
else:
|
||||||
|
body = urllib.parse.urlencode(data)
|
||||||
|
mime = 'application/x-www-form-urlencoded'
|
||||||
|
|
||||||
|
sign_str = api_path + "\n" + body
|
||||||
|
signed_data = hmac.new(secret_key.encode('utf-8'), sign_str.encode('utf-8'), sha1)
|
||||||
|
sign = signed_data.digest().hex()
|
||||||
|
authorization = 'TOKEN ' + access_key + ':' + sign
|
||||||
|
|
||||||
|
response = requests.post('https://api.dogecloud.com' + api_path, data=body, headers={
|
||||||
|
'Authorization': authorization,
|
||||||
|
'Content-Type': mime
|
||||||
|
})
|
||||||
|
return response.json()
|
||||||
|
|
||||||
|
url_list = ['https://usj.cc/'] # 替换为你的博客域名
|
||||||
|
|
||||||
|
api = dogecloud_api('/cdn/refresh/add.json', {
|
||||||
|
'rtype': 'path',
|
||||||
|
'urls': json.dumps(url_list)
|
||||||
|
})
|
||||||
|
if api['code'] == 200:
|
||||||
|
print(api['data']['task_id'])
|
||||||
|
else:
|
||||||
|
print("API failed: " + api['msg'])
|
||||||
Reference in new issue
Block a user