Initial commit
This commit is contained in:
+218
@@ -0,0 +1,218 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
|
||||
from app.extensions import db
|
||||
from app.models import Mirror, Profile, ProfileItem
|
||||
|
||||
|
||||
def seed_mirrors() -> None:
|
||||
if Mirror.query.first():
|
||||
return
|
||||
|
||||
mirrors = [
|
||||
# DNS
|
||||
Mirror(
|
||||
category="dns",
|
||||
name="Shecan",
|
||||
ips="178.22.122.100,185.51.200.2",
|
||||
priority=10,
|
||||
notes="DNS شکن — مناسب دسترسی به سرویسهای فیلترشده",
|
||||
),
|
||||
Mirror(
|
||||
category="dns",
|
||||
name="403.online",
|
||||
ips="10.202.10.202,10.202.10.102",
|
||||
priority=20,
|
||||
notes="DNS رادار / 403",
|
||||
),
|
||||
Mirror(
|
||||
category="dns",
|
||||
name="Begzar",
|
||||
ips="185.55.226.26,185.55.227.27",
|
||||
priority=30,
|
||||
notes="DNS community",
|
||||
),
|
||||
Mirror(
|
||||
category="dns",
|
||||
name="Electro",
|
||||
ips="10.10.34.36,10.10.34.35",
|
||||
priority=40,
|
||||
notes="DNS Electro",
|
||||
),
|
||||
Mirror(
|
||||
category="dns",
|
||||
name="Cloudflare",
|
||||
ips="1.1.1.1,1.0.0.1",
|
||||
priority=90,
|
||||
notes="fallback بینالمللی",
|
||||
),
|
||||
Mirror(
|
||||
category="dns",
|
||||
name="Google DNS",
|
||||
ips="8.8.8.8,8.8.4.4",
|
||||
priority=95,
|
||||
notes="fallback بینالمللی",
|
||||
),
|
||||
# APT
|
||||
Mirror(
|
||||
category="apt",
|
||||
name="Arvan Ubuntu",
|
||||
url="https://mirror.arvancloud.ir/ubuntu",
|
||||
priority=10,
|
||||
notes="میرور ابر آروان — Ubuntu",
|
||||
),
|
||||
Mirror(
|
||||
category="apt",
|
||||
name="Shatel Ubuntu",
|
||||
url="https://mirror.shatel.ir/ubuntu",
|
||||
priority=20,
|
||||
notes="میرور شاتل",
|
||||
),
|
||||
Mirror(
|
||||
category="apt",
|
||||
name="Ubuntu Archive",
|
||||
url="http://archive.ubuntu.com/ubuntu",
|
||||
priority=100,
|
||||
notes="مخزن رسمی — fallback",
|
||||
enabled=False,
|
||||
),
|
||||
# Docker
|
||||
Mirror(
|
||||
category="docker",
|
||||
name="Arvan Docker Registry",
|
||||
url="https://docker.arvancloud.ir",
|
||||
priority=10,
|
||||
notes="رجیstry mirror ابر آروان",
|
||||
),
|
||||
Mirror(
|
||||
category="docker",
|
||||
name="Docker Hub Direct",
|
||||
url="https://registry-1.docker.io",
|
||||
priority=100,
|
||||
notes="رجیstry مستقیم — fallback",
|
||||
enabled=False,
|
||||
),
|
||||
# GitHub
|
||||
Mirror(
|
||||
category="github",
|
||||
name="GitClone",
|
||||
url="https://gitclone.com/github.com",
|
||||
priority=10,
|
||||
notes="پروکسی clone/pull گیتهاب",
|
||||
meta_json=json.dumps({"instead_prefix": "https://gitclone.com/github.com/"}, ensure_ascii=False),
|
||||
),
|
||||
Mirror(
|
||||
category="github",
|
||||
name="GHProxy",
|
||||
url="https://mirror.ghproxy.com/https://github.com",
|
||||
priority=20,
|
||||
notes="پروکسی ghproxy",
|
||||
meta_json=json.dumps({"instead_prefix": "https://mirror.ghproxy.com/https://github.com/"}, ensure_ascii=False),
|
||||
),
|
||||
Mirror(
|
||||
category="github",
|
||||
name="GitHub Direct",
|
||||
url="https://github.com",
|
||||
priority=100,
|
||||
notes="دسترسی مستقیم",
|
||||
enabled=False,
|
||||
),
|
||||
# pip
|
||||
Mirror(
|
||||
category="pip",
|
||||
name="Arvan PyPI",
|
||||
url="https://mirror.arvancloud.ir/pypi/simple",
|
||||
priority=10,
|
||||
notes="میرور pip آروان",
|
||||
),
|
||||
Mirror(
|
||||
category="pip",
|
||||
name="PyPI Official",
|
||||
url="https://pypi.org/simple",
|
||||
priority=100,
|
||||
notes="مخزن رسمی",
|
||||
enabled=False,
|
||||
),
|
||||
# npm
|
||||
Mirror(
|
||||
category="npm",
|
||||
name="npm Official",
|
||||
url="https://registry.npmjs.org",
|
||||
priority=100,
|
||||
notes="رجیstry رسمی npm",
|
||||
enabled=False,
|
||||
),
|
||||
]
|
||||
|
||||
for mirror in mirrors:
|
||||
db.session.add(mirror)
|
||||
db.session.commit()
|
||||
|
||||
|
||||
def seed_profiles() -> None:
|
||||
if Profile.query.first():
|
||||
return
|
||||
|
||||
profiles_data = [
|
||||
(
|
||||
"آروان کامل",
|
||||
"DNS Shecan + میرور APT/Docker آروان + GitClone",
|
||||
{"dns": "Shecan", "apt": "Arvan Ubuntu", "docker": "Arvan Docker Registry", "github": "GitClone"},
|
||||
),
|
||||
(
|
||||
"403 + Shatel",
|
||||
"DNS 403 + میرور شاتل",
|
||||
{"dns": "403.online", "apt": "Shatel Ubuntu", "docker": "Arvan Docker Registry", "github": "GHProxy"},
|
||||
),
|
||||
(
|
||||
"حداقلی",
|
||||
"فقط DNS و Docker",
|
||||
{"dns": "Shecan", "docker": "Arvan Docker Registry"},
|
||||
),
|
||||
]
|
||||
|
||||
for idx, (name, desc, mapping) in enumerate(profiles_data):
|
||||
profile = Profile(name=name, description=desc, is_default=(idx == 0))
|
||||
db.session.add(profile)
|
||||
db.session.flush()
|
||||
|
||||
for order, (category, mirror_name) in enumerate(mapping.items()):
|
||||
mirror = Mirror.query.filter_by(category=category, name=mirror_name).first()
|
||||
if mirror:
|
||||
db.session.add(
|
||||
ProfileItem(
|
||||
profile_id=profile.id,
|
||||
mirror_id=mirror.id,
|
||||
category=category,
|
||||
order=order,
|
||||
)
|
||||
)
|
||||
|
||||
db.session.commit()
|
||||
|
||||
|
||||
def seed_settings() -> None:
|
||||
defaults = {
|
||||
"auto_switch_dns": "false",
|
||||
"auto_switch_apt": "false",
|
||||
"auto_switch_docker": "false",
|
||||
"auto_switch_github": "false",
|
||||
"auto_switch_pip": "false",
|
||||
"auto_switch_npm": "false",
|
||||
"auto_test_interval_minutes": "30",
|
||||
"max_switches_per_day": "3",
|
||||
"rollback_minutes": "15",
|
||||
"rollback_on_all_fail": "true",
|
||||
}
|
||||
from app.models import Setting
|
||||
|
||||
for key, value in defaults.items():
|
||||
if Setting.get(key) is None:
|
||||
Setting.set(key, value)
|
||||
|
||||
|
||||
def seed_all() -> None:
|
||||
seed_mirrors()
|
||||
seed_profiles()
|
||||
seed_settings()
|
||||
Reference in New Issue
Block a user