mirror of
https://github.com/GradienceTeam/Gradience.git
synced 2024-10-06 17:37:54 +00:00
f934901570
* move some snippets to other modules
48 lines
1.8 KiB
Python
48 lines
1.8 KiB
Python
# networking.py
|
|
#
|
|
# Change the look of Adwaita, with ease
|
|
# Copyright (C) 2023, Gradience Team
|
|
#
|
|
# This program is free software: you can redistribute it and/or modify
|
|
# it under the terms of the GNU General Public License as published by
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
# (at your option) any later version.
|
|
#
|
|
# This program is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU General Public License
|
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
from urllib.parse import urlparse
|
|
|
|
|
|
def get_preset_repos(use_jsdeliver: bool) -> dict:
|
|
if use_jsdeliver:
|
|
from gradience.backend.globals import preset_repos_jsdeliver
|
|
preset_repos = preset_repos_jsdeliver
|
|
else:
|
|
from gradience.backend.globals import preset_repos_github
|
|
preset_repos = preset_repos_github
|
|
|
|
return preset_repos
|
|
|
|
def github_to_jsdeliver_url(github_url: str) -> str:
|
|
"""
|
|
Converts Github raw data URL link to JSDeliver CDN link.
|
|
"""
|
|
|
|
jsdeliver_url = None
|
|
|
|
# https://github.com/GradienceTeam/Community/raw/next/official/builder.json =>
|
|
# https://cdn.jsdelivr.net/gh/GradienceTeam/Community@next/official/builder.json
|
|
if "https://github.com" in github_url:
|
|
JSDELIVER_FORMAT = "https://cdn.jsdelivr.net/gh/{user}/{repo}@{branch}/{path}"
|
|
path = urlparse(github_url).path
|
|
user, repo, _, branch, *path = path.strip('/').split('/')
|
|
path = "/".join(path)
|
|
jsdeliver_url = JSDELIVER_FORMAT.format(user=user, repo=repo, branch=branch, path=path)
|
|
|
|
return jsdeliver_url
|