Skip to content
This repository was archived by the owner on Dec 4, 2024. It is now read-only.

Commit d26d959

Browse files
committed
Switch to GitHub Proxy
1 parent db84981 commit d26d959

File tree

5 files changed

+134
-61
lines changed

5 files changed

+134
-61
lines changed

.github/workflows/scheduled_update.yml

+5-4
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
- uses: actions/checkout@v3
1818
- uses: actions/setup-python@v4
1919
with:
20-
python-version: '3.8'
20+
python-version: '3.9'
2121
- uses: actions/cache@v3
2222
with:
2323
path: ~/.cache/pip
@@ -50,10 +50,11 @@ jobs:
5050
run: |
5151
rm -rf ./meta/.git
5252
cd ./scripts
53+
python main.py remove
5354
python main.py meta
5455
env:
5556
github_api_token: ${{ secrets.TOKEN_FOR_GITHUB_API }}
56-
FASTGIT_URL: ${{ vars.FASTGIT_URL }}
57+
# FASTGIT_URL: ${{ vars.FASTGIT_URL }}
5758

5859
- name: Deploy meta
5960
uses: s0/git-publish-subdir-action@develop
@@ -63,7 +64,7 @@ jobs:
6364
FOLDER: meta
6465
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6566
# SSH_PRIVATE_KEY: ${{ secrets.SSH_KEY }}
66-
# SQUASH_HISTORY: true
67+
SQUASH_HISTORY: true
6768
SKIP_EMPTY_COMMITS: true
6869

6970
- name: Deploy doc
@@ -74,5 +75,5 @@ jobs:
7475
FOLDER: catalogue
7576
# SSH_PRIVATE_KEY: ${{ secrets.SSH_KEY }}
7677
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
77-
# SQUASH_HISTORY: true
78+
SQUASH_HISTORY: true
7879
SKIP_EMPTY_COMMITS: true

readme.md

+16-15
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,20 @@
11
**English** | [中文](readme_cn.md)
22

33
<h1 align="center"> MCDReforged PluginCatalogue</h1>
4-
<h3 align="center"><i> (with <a href="https://fastgit.org/">FastGit UK</a>)</i></h3>
4+
<h3 align="center"><i> (with <a href="https://mirror.ghproxy.com//">GitHub Proxy</a>)</i></h3>
55
<p align="center">
66
A repository for listing <a href="https://github.com/Fallen-Breath/MCDReforged">MCDReforged</a> plugins.
77
<br><i>
8-
Replaced all the URLs to fastgit in <a href="https://github.com/Lazy-Bing-Server/PluginCatalogue-FG/tree/meta">meta</a> branch to accelerate automatic plugin management
8+
Replaced all the download URLs to GitHub in <a href="https://github.com/Lazy-Bing-Server/PluginCatalogue-GP/tree/meta">meta</a> branch to accelerate automatic plugin management
99
</i><br>
1010
<br>
11-
<a href="https://github.com/Lazy-Bing-Server/PluginCatalogue-FG/blob/catalogue/readme.md"><strong>Main Plugins Catalogue</strong></a>
11+
<a href="https://github.com/Lazy-Bing-Server/PluginCatalogue-GP/blob/catalogue/readme.md"><strong>Main Plugins Catalogue</strong></a>
1212
·
1313
<a href="https://github.com/MCDReforged/PluginCatalogue/blob/legacy/readme.md">Legacy Plugins Catalogue</a>
1414
<br>
1515
<i>Current repository didn't copy the data of original repository and therefore the legacy catalogue link above still directs to the legacy branch of original repository</i>
1616
<br>
17-
<br>
18-
<a href="https://hub.fgit.ml/Lazy-Bing-Server/PluginCatalogue-FG">Access this repository with FastGit UK</a>
19-
<br>
20-
<i>If you are accessing this repo with FastGit, clicking this link will only bring you back here and nothing will happen</i>
17+
<i>If you are accessing this repo with GitHub Proxy, clicking this link will only bring you back here and nothing will happen</i>
2118
</p>
2219
<br>
2320

@@ -32,24 +29,28 @@
3229

3330
If you would like to add your plugin to the plugin repository, you may wish to submit a PR. **Note that these PR should be submitted to [the original repository](https://github.com/MCDReforged/PluginCatalogue).** Check out the [documentation](https://mcdreforged.readthedocs.io/en/latest/plugin_dev/plugin_catalogue.html) for more information
3431

35-
You can learn about the plugin data provided by the plugin repository [here](https://github.com/Lazy-Bing-Server/PluginCatalogue-FG/tree/meta)
32+
You can learn about the plugin data provided by the plugin repository [here](https://github.com/Lazy-Bing-Server/PluginCatalogue-GP/tree/meta)
3633

3734
## Plugin Source Configuration
3835

3936
When connection to GitHub is unstable, change the plugin source configuration to this repo for plugin managers to accelerate download. The following are the ways to configure plugin source for plugin managers, if there's any different in configuration to the document of the mentioned plugin manager, please make the description in its own document your primary reference
4037

41-
> ⚠️ <strong>Warning: FastGit service is not absolutely stable. when access to the plugin source configured as following is denied, please restore plugin source config. </strong>
38+
> ⚠️ <strong>Warning: GitHub Proxy service is not absolutely stable. when access to the plugin source configured as following is denied, please restore plugin source config. </strong>
4239
43-
### [MCDReforged Plugin Manager](https://github.com/Ivan-1F/MCDReforgedPluginManager) *(by [Ivan1F](https://github.com/Ivan-1F))*
40+
### [MCDReforged](https://mcdreforged.com) official plugin management
4441

45-
Configure the following field in its configuration file `config/mcdreforged_plugin_manager/config.yml` to:
42+
MCDReforged introduced plugin installation feature in version 2.13
43+
44+
Configure the specified field here in MCDR config file `config.yml` to:
4645

4746
```commandline
48-
source: https://hub.fgit.gq/Lazy-Bing-Server/PluginCatalogue-FG/archive/refs/heads/meta.zip
47+
catalogue_meta_url: https://mirror.ghproxy.com/https://raw.githubusercontent.com/Lazy-Bing-Server/PluginCatalogue-GP/meta/everything.json.xz
4948
```
50-
or
49+
50+
### [MCDReforged Plugin Manager](https://github.com/Ivan-1F/MCDReforgedPluginManager) *(by [Ivan1F](https://github.com/Ivan-1F))*
51+
52+
Configure the following field in its configuration file `config/mcdreforged_plugin_manager/config.yml` to:
5153

5254
```commandline
53-
source: https://hub.fgit.ml/Lazy-Bing-Server/PluginCatalogue-FG/archive/refs/heads/meta.zip
55+
source: https://mirror.ghproxy.com/https://github.com/Lazy-Bing-Server/PluginCatalogue-GP/archive/refs/heads/meta.zip
5456
```
55-

readme_cn.md

+14-16
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,20 @@
11
[English](readme.md) | **中文**
22

33
<h1 align="center">MCDReforged PluginCatalogue</h1>
4-
<h3 align="center"><i> (使用 <a href="http://fastgit.org/">FastGit UK</a>)</i></h3>
4+
<h3 align="center"><i> (使用 <a href="https://mirror.ghproxy.com/">GitHub Proxy</a>)</i></h3>
55

66
<p align="center">
77
一个用于列出 <a href="https://github.com/Fallen-Breath/MCDReforged">MCDReforged</a> 插件的仓库。
88
<br>
9-
<i><a href="https://github.com/Lazy-Bing-Server/PluginCatalogue-FG/tree/meta">meta</a> 分支中的 URL 已被替换为指向 FastGit 用以加速自动化插件管理</i>
9+
<i><a href="https://github.com/Lazy-Bing-Server/PluginCatalogue-GP/tree/meta">meta</a> 分支中的下载 URL 已被替换为指向 GitHub Proxy 用以加速自动化插件管理</i>
1010
<br>
1111
<br>
12-
<a href="https://github.com/Lazy-Bing-Server/PluginCatalogue-FG/blob/catalogue/readme-zh_cn.md"><strong>主插件目录</strong></a>
12+
<a href="https://github.com/Lazy-Bing-Server/PluginCatalogue-GP/blob/catalogue/readme-zh_cn.md"><strong>主插件目录</strong></a>
1313
·
1414
<a href="https://github.com/MCDReforged/PluginCatalogue/blob/legacy/readme_cn.md">旧插件目录</a>
1515
<br>
1616
<i>当前仓库未对原插件仓库中的旧插件目录实施镜像,因此上方的旧插件目录链接仍指向原插件仓库的旧插件分支</i>
1717
<br>
18-
<br>
19-
<a href="https://hub.fgit.ml/Lazy-Bing-Server/PluginCatalogue-FG">通过 FastGit UK 访问该仓库</a>
20-
<br>
21-
<i>若当前已经是通过 FastGit 访问,则点击以上链接将回到此处,无事发生</i>
22-
<br>
2318
</p>
2419
<br>
2520

@@ -33,27 +28,30 @@
3328

3429
如果你想添加你的插件到插件仓库中,不妨交个 PR。**请注意这些 PR 应该被提交至[原插件仓库](https://github.com/MCDReforged/PluginCatalogue)**。查看 [文档](https://mcdreforged.readthedocs.io/zh_CN/latest/plugin_dev/plugin_catalogue.html) 以了解更多信息
3530

36-
你可以在 [这里](https://github.com/MCDReforged/PluginCatalogue/tree/meta) 了解到插件仓库提供的插件数据
31+
你可以在 [这里](https://github.com/Lazy-Bing-Server/PluginCatalogue-GP/tree/meta) 了解到插件仓库提供的插件数据
3732

3833

3934
## 插件源配置
4035

4136
当 GitHub 连接不稳定时,变更插件管理器的插件源配置指向该仓库可加速下载,以下介绍插件管理器中配置插件源的方式,如配置方式与该插件管理器文档存在出入,请首先参考它自己文档的描述
4237

43-
> ⚠️ **注意:FastGit 的服务并非绝对稳定,当无法访问如下配置的插件源时,请还原插件源配置**
38+
> ⚠️ **注意:GitHub Proxy 的服务并非绝对稳定,当无法访问如下配置的插件源时,请还原插件源配置**
4439
45-
### [MCDReforged Plugin Manager](https://github.com/Ivan-1F/MCDReforgedPluginManager) *(由 [Ivan1F](https://github.com/Ivan-1F) 开发)*
4640

41+
### [MCDReforged](https://mcdreforged.com) 官方插件管理
4742

48-
在其配置文件 `config/mcdreforged_plugin_manager/config.yml` 中调整如下配置:
43+
MCDReforged 在 2.13 版本引入了插件安装特性
44+
45+
在其配置文件 `config.yml` 中调整如下配置:
4946

5047
```commandline
51-
source: https://hub.fgit.gq/Lazy-Bing-Server/PluginCatalogue-FG/archive/refs/heads/meta.zip
48+
catalogue_meta_url: https://mirror.ghproxy.com/https://raw.githubusercontent.com/Lazy-Bing-Server/PluginCatalogue-GP/meta/everything.json.xz
5249
```
5350

54-
或者是
51+
### [MCDReforged Plugin Manager](https://github.com/Ivan-1F/MCDReforgedPluginManager) *(由 [Ivan1F](https://github.com/Ivan-1F) 开发)*
52+
53+
在其配置文件 `config/mcdreforged_plugin_manager/config.yml` 中调整如下配置:
5554

5655
```commandline
57-
source: https://hub.fgit.ml/Lazy-Bing-Server/PluginCatalogue-FG/archive/refs/heads/meta.zip
56+
source: https://mirror.ghproxy.com/https://github.com/Lazy-Bing-Server/PluginCatalogue-GP/archive/refs/heads/meta.zip
5857
```
59-

scripts/constants.py

+5
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@
2222
CATALOGUE_FOLDER = os.path.join(ROOT, 'catalogue')
2323
META_FOLDER = os.path.join(ROOT, 'meta')
2424

25+
GHPROXY_URL = "https://mirror.ghproxy.com/"
26+
CREATE_GZ = ["all.json", "authors.json", "everything.json", "everything_slim.json", "plugins.json"]
27+
CREATE_LZMA = ["everything.json", "everything_slim.json"]
28+
COMPACT = ["everything.json", "everything_slim.json", "plugins.json"]
29+
2530
PROXIES = None
2631
if 'http_proxy' in os.environ:
2732
http_proxy = os.environ['http_proxy'] # e.g. 127.0.0.1:1082

scripts/main.py

+94-26
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,71 @@
11
import json
22
from argparse import ArgumentParser
3-
from constants import CATALOGUE_FOLDER, META_FOLDER, MAPPING_FILE
3+
from constants import CATALOGUE_FOLDER, META_FOLDER, GHPROXY_URL, CREATE_LZMA, CREATE_GZ, COMPACT
44
from collections import namedtuple
55

66
import os
77
import typing as ty
88

9+
import gzip
10+
import lzma
11+
12+
from contextlib import contextmanager
13+
914

1015
WalkedDir = namedtuple('WalkedDir', 'dirpath dirnames filenames')
1116
Iterable = ty.Optional[ty.Iterable]
1217

1318

14-
def get_fastgit_urls_from_file() -> ty.Dict[str, str]:
15-
with open(MAPPING_FILE, 'r', encoding='utf8') as f:
16-
return json.load(f)
19+
@contextmanager
20+
def open_for_write(file_path: str):
21+
"""
22+
Just like open() in 'w' mode, but create the directory automatically
23+
"""
24+
dir_path = os.path.dirname(file_path)
25+
if not os.path.isdir(dir_path):
26+
os.makedirs(dir_path)
27+
with open(file_path, 'w', encoding='utf8') as file:
28+
yield file
29+
30+
31+
def save_json(data: dict, file_path: str, *, compact: bool = False, with_gz: bool = False, with_xz: bool = False):
32+
if compact:
33+
s = json.dumps(data, ensure_ascii=False, separators=(',', ':'))
34+
else:
35+
s = json.dumps(data, indent=2, ensure_ascii=False)
36+
37+
with open_for_write(file_path) as f:
38+
f.write(s)
39+
if with_gz:
40+
with gzip.GzipFile(file_path + '.gz', 'wb', mtime=0) as zf:
41+
zf.write(s.encode('utf8'))
42+
if with_xz:
43+
with lzma.open(file_path + '.xz', 'wb', format=lzma.FORMAT_XZ) as xf:
44+
xf.write(s.encode('utf8'))
45+
46+
47+
def _update(folder, included_suffixes: Iterable = None, excluded_prefixes: Iterable = None):
48+
return __walk_n_process(
49+
folder, __update,
50+
included_suffixes=included_suffixes, excluded_prefixes=excluded_prefixes
51+
)
52+
53+
54+
def __update(matched: bool, path: str):
55+
if not matched:
56+
print(f'Excluded {path}')
57+
return
58+
print(f'Processing {path}...')
1759

60+
with open(path, 'r', encoding='utf8') as f:
61+
data = json.load(f)
62+
result_data = recursively_add_ghproxy_prefix(data)
1863

19-
def get_fastgit_urls() -> ty.Dict[str, str]:
20-
return json.loads(os.getenv('FASTGIT_URL'))
64+
file_name = os.path.basename(path)
65+
save_json(result_data, path, compact=file_name in COMPACT, with_gz=file_name in CREATE_GZ, with_xz=file_name in CREATE_LZMA)
2166

2267

23-
def __update(folder, included_suffixes: Iterable = None, excluded_prefixes: Iterable = None):
68+
def __walk_n_process(folder, func: ty.Callable[[bool, str], ty.Any], included_suffixes: Iterable = None, excluded_prefixes: Iterable = None):
2469
if included_suffixes is None:
2570
included_suffixes = []
2671
if excluded_prefixes is None:
@@ -38,37 +83,58 @@ def __update(folder, included_suffixes: Iterable = None, excluded_prefixes: Iter
3883
matched = False
3984

4085
path = os.path.join(folder.dirpath, file)
41-
if not matched:
42-
print(f'Excluded {path}')
43-
continue
44-
45-
print(f'Processing {file}...')
46-
to_replace = get_fastgit_urls()
47-
48-
path = os.path.join(folder.dirpath, file)
49-
with open(path, 'r', encoding='utf8') as f:
50-
data = f.read()
51-
52-
for old, new in to_replace.items():
53-
data = data.replace(old, new)
54-
55-
with open(path, 'w', encoding='utf8') as f:
56-
f.write(data)
86+
func(matched, path)
87+
88+
89+
def recursively_add_ghproxy_prefix(data: ty.Union[dict, list, ty.Any]):
90+
if isinstance(data, dict):
91+
result_dict = {}
92+
for k, v in data.items():
93+
if k == "browser_download_url" and isinstance(v, str):
94+
result_dict[k] = GHPROXY_URL + v
95+
else:
96+
result_dict[k] = recursively_add_ghproxy_prefix(v)
97+
return result_dict
98+
elif isinstance(data, list):
99+
result_list = []
100+
for item in data:
101+
result_list.append(recursively_add_ghproxy_prefix(item))
102+
return result_list
103+
else:
104+
return data
57105

58106

59107
def update_data():
60108
print('Processing meta branch')
61-
__update(META_FOLDER, included_suffixes=['.json'], excluded_prefixes=['.'])
109+
_update(META_FOLDER, included_suffixes=['.json'], excluded_prefixes=['.'])
62110

63111

64112
def update_doc():
65113
print('Processing catalogue branch')
66-
__update(CATALOGUE_FOLDER, included_suffixes=['.md'])
114+
_update(CATALOGUE_FOLDER, included_suffixes=['.md'])
115+
116+
117+
def _remove(folder, included_suffixes: Iterable = None, excluded_prefixes: Iterable = None):
118+
__walk_n_process(
119+
folder, __remove,
120+
included_suffixes=included_suffixes, excluded_prefixes=excluded_prefixes
121+
)
122+
123+
124+
def __remove(match: bool, path: str):
125+
if match:
126+
print(f"Removing file {path}")
127+
os.remove(path)
128+
129+
130+
def remove_meta_archives():
131+
print("Remove LZMA and GZ files...")
132+
_remove(META_FOLDER, included_suffixes=['.xz', '.gz'])
67133

68134

69135
def main():
70136
parser = ArgumentParser(
71-
prog='python manager', description='Plugin Catalogue (FastGit Accelerated) Manager'
137+
prog='python manager', description='Plugin Catalogue (GitHub Proxy Accelerated) Manager'
72138
)
73139

74140
subparsers = parser.add_subparsers(title='Command', help='Available commands', dest='subparser_name')
@@ -78,6 +144,8 @@ def main():
78144
args = parser.parse_args()
79145
if args.subparser_name == 'meta':
80146
update_data()
147+
elif args.subparser_name == 'remove':
148+
remove_meta_archives()
81149
elif args.subparser_name == 'doc':
82150
update_doc()
83151

0 commit comments

Comments
 (0)