From d23b703e5f3edd56efefeeb54a4d99afc9f19ae1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E8=B5=B5=E5=90=8C=E5=AD=A6?= <94612053+imzql@users.noreply.github.com> Date: Mon, 16 Sep 2024 11:51:29 +0800 Subject: [PATCH 1/3] Create RefreshCDN.py --- RefreshCDN.py | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 RefreshCDN.py diff --git a/RefreshCDN.py b/RefreshCDN.py new file mode 100644 index 00000000..04332310 --- /dev/null +++ b/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://xxxxx/'] # 替换为你的博客域名 + +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']) From ce7b8b3a2338aedf3399d62a0ce24014ba51daa8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E8=B5=B5=E5=90=8C=E5=AD=A6?= <94612053+imzql@users.noreply.github.com> Date: Mon, 16 Sep 2024 11:52:24 +0800 Subject: [PATCH 2/3] Create RefreshCDN.yml --- .github/workflows/RefreshCDN.yml | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 .github/workflows/RefreshCDN.yml diff --git a/.github/workflows/RefreshCDN.yml b/.github/workflows/RefreshCDN.yml new file mode 100644 index 00000000..287f27c6 --- /dev/null +++ b/.github/workflows/RefreshCDN.yml @@ -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 From 3212743f9dcb75a4eaa7662ffd816c713c94fae8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E8=B5=B5=E5=90=8C=E5=AD=A6?= <94612053+imzql@users.noreply.github.com> Date: Mon, 16 Sep 2024 11:54:39 +0800 Subject: [PATCH 3/3] Update RefreshCDN.py --- RefreshCDN.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/RefreshCDN.py b/RefreshCDN.py index 04332310..46af100c 100644 --- a/RefreshCDN.py +++ b/RefreshCDN.py @@ -38,7 +38,7 @@ def dogecloud_api(api_path, data={}, json_mode=False): }) return response.json() -url_list = ['https://xxxxx/'] # 替换为你的博客域名 +url_list = ['https://usj.cc/'] # 替换为你的博客域名 api = dogecloud_api('/cdn/refresh/add.json', { 'rtype': 'path',