Update ACL4SSR_Online_Full_WithIcon.yaml #9
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Convert Icon URL to Base64 | |
on: | |
push: | |
paths: | |
- yaml/ACL4SSR_Online_Full_WithIcon.yaml | |
jobs: | |
convert-icons: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Set up Python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: '3.x' | |
- name: Check if the YAML file exists | |
id: check_file | |
run: | | |
if [ ! -f "yaml/ACL4SSR_Online_Full_WithIcon.yaml" ]; then | |
echo "File does not exist." | |
exit 0 | |
fi | |
- name: Install dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip install pyyaml requests | |
- name: Convert icon URLs to Base64 and modify YAML | |
run: | | |
python - <<EOF | |
import yaml | |
import requests | |
import base64 | |
input_file = 'yaml/ACL4SSR_Online_Full_WithIcon.yaml' | |
output_file = 'yaml/ACL4SSR_Online_Full_WithBase64Icon.yaml' | |
with open(input_file, 'r', encoding='utf-8') as file: | |
data = yaml.safe_load(file) | |
def url_to_base64(url): | |
response = requests.get(url) | |
if response.status_code == 200: | |
img_type = url.split('.')[-1] | |
base64_str = base64.b64encode(response.content).decode('utf-8') | |
return f"data:image/{img_type};base64,{base64_str}" | |
else: | |
return url | |
for group in data.get('proxy-groups', []): | |
if 'icon' in group: | |
group['icon'] = repr(url_to_base64(group['icon'])) | |
with open(output_file, 'w', encoding='utf-8') as file: | |
yaml.dump(data, file, allow_unicode=True) | |
print(f"Conversion completed: {output_file}") | |
EOF | |
- name: Commit and Push changes | |
run: | | |
git config --global user.name "github-actions" | |
git config --global user.email "[email protected]" | |
git add yaml/ACL4SSR_Online_Full_WithBase64Icon.yaml | |
git commit -m "Converted image URL to base64 in ACL4SSR_Online_Full_WithBase64Icon.yaml" | |
git push | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |