new: add profile headers from comments in response! good for hosting in github and show information

This commit is contained in:
Hiddify
2023-09-15 12:25:18 +02:00
parent 759e5243e7
commit 94299ff728
3 changed files with 40 additions and 8 deletions

View File

@@ -262,10 +262,9 @@ jobs:
files: ./out/*
- name: Create service_account.json
if: matrix.platform == 'android-aab' && github.ref_type=='tag'
run: echo '${{ secrets.GOOGLE_PLAY_SERVICE_ACCOUNT_JSON }}' > service_account.json
- name: Deploy to Internal Testers
- name: Deploy to Google Play Internal Testers
uses: r0adkll/upload-google-play@v1
with:
serviceAccountJson: service_account.json

View File

@@ -188,12 +188,46 @@ class ProfilesRepositoryImpl
loggy.warning("error parsing config: $l");
return left(ProfileFailure.invalidConfig(l.msg));
},
(_) {
final profile = Profile.fromResponse(url, response.headers.map);
(_) async {
final responseString = await File(path).readAsString();
final headers = addHeadersFromBody(response.headers.map, responseString);
final profile = Profile.fromResponse(url, headers);
return right(profile);
},
);
},
);
}
Map<String, List<String>> addHeadersFromBody(
Map<String, List<String>> headers,
String responseString,
) {
final allowedHeaders = [
'profile-title',
'content-disposition',
'subscription-userinfo',
'profile-update-interval',
'support-url',
'profile-web-page-url'
];
for (final text in responseString.split("\n")) {
if (text.startsWith("#") || text.startsWith("//")) {
final index = text.indexOf(':');
if (index == -1) continue;
final headerTitle = text
.substring(0, index)
.replaceFirst(RegExp("^#|//"), "")
.trim()
.toLowerCase();
final headerValue = text.substring(index + 1).trim();
if (!headers.keys.contains(headerTitle) &&
allowedHeaders.contains(headerTitle) &&
headerValue.isNotEmpty) {
headers[headerTitle] = [headerValue];
}
}
}
return headers;
}
}

View File

@@ -1,4 +1,5 @@
import 'dart:convert';
import 'dart:io';
import 'package:dartx/dartx.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
@@ -25,11 +26,9 @@ class Profile with _$Profile {
ProfileExtra? extra,
}) = _Profile;
factory Profile.fromResponse(
String url,
Map<String, List<String>> headers,
) {
factory Profile.fromResponse(String url, Map<String, List<String>> headers) {
_loggy.debug("Profile Headers: $headers");
final titleHeader = headers['profile-title']?.single;
var title = '';
if (titleHeader != null) {