57 lines
1.7 KiB
Python
57 lines
1.7 KiB
Python
#!/usr/bin/env python
|
|
# coding:utf-8
|
|
|
|
import requests
|
|
import json
|
|
import urllib3
|
|
|
|
class clear_cdn_util:
|
|
def __init__(self, x_app_id):
|
|
self.url = "https://saas.castbox.fm/tool/api/v1/operate/batch/clearCdn"
|
|
self.x_app_id = x_app_id
|
|
self.domain_list = []
|
|
self.clear_file_list = []
|
|
|
|
# domain:cdn3-find-master.fungame.cloud
|
|
def appendDomain(self, domain):
|
|
self.domain_list.append(domain)
|
|
|
|
# storage path:/xx/xx
|
|
def appendClearFile(self, path):
|
|
self.clear_file_list.append(path)
|
|
|
|
def clearCDN(self):
|
|
try:
|
|
if self.x_app_id == "":
|
|
print("clearCDN failed!!! x_app_id is None")
|
|
return
|
|
|
|
if len(self.domain_list) == 0:
|
|
print("clearCDN failed!!! domain_list len is 0")
|
|
return
|
|
|
|
if len(self.clear_file_list) == 0:
|
|
print("clearCDN failed!!! clear_file_list len is 0")
|
|
return
|
|
|
|
params = {
|
|
"domainList": self.domain_list,
|
|
"pathSuffixList": self.clear_file_list
|
|
}
|
|
data = json.dumps(params)
|
|
print(data)
|
|
urllib3.disable_warnings()
|
|
r = requests.post(self.url,
|
|
headers={"X-APP-ID": self.x_app_id, "Content-Type": "application/json"},
|
|
data=data,
|
|
verify=False
|
|
)
|
|
|
|
print(r.status_code)
|
|
print(str(r))
|
|
if r.status_code == 200:
|
|
print(f"{str(self.clear_file_list)} clearCDN OK!!! ")
|
|
except Exception as e:
|
|
print("clearCDN failed!!! error: " + repr(e))
|
|
|