修复link_lite.json bug
This commit is contained in:
1 parent
8dec5359bd
commit
68e3cf372f
7 files changed
+251
-241
No files matched your search
@@ -0,0 +1,58 @@
|
||||
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 = os.environ.get('DOGECLOUD_ACCESS_KEY') # 从环境变量获取 AccessKey
|
||||
secret_key = os.environ.get('DOGECLOUD_SECRET_KEY') # 从环境变量获取 SecretKey
|
||||
|
||||
if not access_key or not secret_key:
|
||||
raise ValueError("Access Key or Secret Key is not set in environment variables.")
|
||||
|
||||
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 列表,使用逗号分隔
|
||||
url_list_env = os.environ.get('CDN_URL_LIST')
|
||||
if not url_list_env:
|
||||
raise ValueError("CDN_URL_LIST is not set in environment variables.")
|
||||
|
||||
url_list = url_list_env.split(',')
|
||||
|
||||
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'])
|
||||
@@ -84,8 +84,9 @@ foreach ($file in $files) {
|
||||
continue
|
||||
}
|
||||
|
||||
# Save file using .NET method to ensure UTF8
|
||||
[System.IO.File]::WriteAllText($file.FullName, $newContent, [System.Text.Encoding]::UTF8)
|
||||
# Save file using .NET method to ensure UTF8 without BOM
|
||||
$utf8NoBom = New-Object System.Text.UTF8Encoding $false
|
||||
[System.IO.File]::WriteAllText($file.FullName, $newContent, $utf8NoBom)
|
||||
Write-Host " -> Saved changes to $($file.Name)" -ForegroundColor Green
|
||||
$count++
|
||||
}
|
||||
|
||||
+18
-1
@@ -87,10 +87,27 @@ async function main() {
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
let linksData;
|
||||
let links;
|
||||
try {
|
||||
const fileContent = fs.readFileSync(LINKS_FILE, 'utf8');
|
||||
links = JSON.parse(fileContent);
|
||||
linksData = JSON.parse(fileContent);
|
||||
// Adapt to both array (old) and object with friends key (new)
|
||||
if (Array.isArray(linksData)) {
|
||||
links = linksData;
|
||||
} else if (linksData.friends && Array.isArray(linksData.friends)) {
|
||||
// The new format has [name, url, avatar] arrays inside friends array
|
||||
// We need to convert them to objects {name, url} for the checker
|
||||
links = linksData.friends.map(item => {
|
||||
if (Array.isArray(item)) {
|
||||
return { name: item[0], url: item[1] };
|
||||
}
|
||||
return item;
|
||||
});
|
||||
} else {
|
||||
console.error('Error: Unknown JSON format');
|
||||
process.exit(1);
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('Error parsing JSON:', e.message);
|
||||
process.exit(1);
|
||||
|
||||
@@ -94,7 +94,8 @@ if (-not (Test-Path $jsonDir)) {
|
||||
New-Item -ItemType Directory -Path $jsonDir | Out-Null
|
||||
}
|
||||
|
||||
# Write to file
|
||||
[System.IO.File]::WriteAllText($jsonPath, $json, [System.Text.Encoding]::UTF8)
|
||||
# Write to file without BOM
|
||||
$utf8NoBom = New-Object System.Text.UTF8Encoding $false
|
||||
[System.IO.File]::WriteAllText($jsonPath, $json, $utf8NoBom)
|
||||
|
||||
Write-Host "Successfully generated $jsonPath" -ForegroundColor Green
|
||||
Reference in new issue
Block a user