Skip to content

Commit

Permalink
update refresh_cdn_cache.py
Browse files Browse the repository at this point in the history
  • Loading branch information
x1jumping committed Sep 24, 2023
1 parent 0b1c3c9 commit 5b9dbbe
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ freecdn-js能提高网站稳定性,如果其中一个cdn链接不可用则启

> P.S. cdn有缓存,如果freecdn失效请检查`freecdn-manifest.txt`或`manifest-full.txt`是否和对应原文件一致。

在上传hexo博客后使用`refresh_cdn_cache.py`进行刷新。

生成的`freecdn-manifest.txt`[示例](https://github.com/xingpingcn/picture-bed-using-freecdn/blob/main/freecdn-manifest.txt)如下

<details> <summary>点击查看</summary>
Expand Down Expand Up @@ -140,6 +142,7 @@ freecdn-js能提高网站稳定性,如果其中一个cdn链接不可用则启
python ../generate_external_manifest_file.py
freecdn js --make --cdn "https://jsd.cdn.zzko.cn/gh/user/repo@main/freecdn-internal/ver/freecdn-main.min.js unpkg jsdelivr elemecdn " #此命令为配置cdn链接用于加速.min.js文件,详细请查看freecdn项目的GitHub
gulp && hexo d
python ../refresh_cdn_cache.py
```

## 感谢
Expand Down
27 changes: 27 additions & 0 deletions refresh_cdn_cache.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import requests,re
import os
from generate_custom_conf import proxies_dict
from concurrent.futures import ThreadPoolExecutor, wait
import threading
def main():
pool = ThreadPoolExecutor(32)
lock = threading.Lock()
ThreadPool_list = []
url_list = []
re_obj = re.compile(r'cdn.jsdelivr.net/gh/(.*)')
with open(os.path.join('./public','manifest-full.txt'),'r',encoding='utf8') as f:
f_content = f.read()
with open(os.path.join('./public','freecdn-manifest.txt'),'r',encoding='utf8') as f:
f_content = f_content+'\n'+f.read()
re_res = re_obj.findall(f_content)
for res in re_res:
if res not in url_list:
with lock:
url_list.append(res)
ThreadPool_list.append(pool.submit(refresh_cdn_cache,res))
wait(ThreadPool_list)
print('refresh cdn cache complete.')
def refresh_cdn_cache(url):
requests.get('https://purge.jsdelivr.net/gh/'+url, proxies=proxies_dict)
if __name__ == '__main__':
main()

0 comments on commit 5b9dbbe

Please sign in to comment.