new: add postfix to name if it is not unique

This commit is contained in:
Hiddify
2024-01-30 19:14:05 +01:00
parent 1b372b5180
commit e13b4b269a
4 changed files with 40 additions and 22 deletions

View File

@@ -9,6 +9,7 @@ part 'profile_data_source.g.dart';
abstract interface class ProfileDataSource {
Future<ProfileEntry?> getById(String id);
Future<ProfileEntry?> getByUrl(String url);
Future<ProfileEntry?> getByName(String name);
Stream<ProfileEntry?> watchActiveProfile();
Stream<int> watchProfilesCount();
Stream<List<ProfileEntry>> watchAll({
@@ -44,6 +45,13 @@ class ProfileDao extends DatabaseAccessor<AppDatabase>
..limit(1))
.getSingleOrNull();
}
@override
Future<ProfileEntry?> getByName(String name) async {
return (select(profileEntries)
..where((tbl) => tbl.name.equals(name))
..limit(1))
.getSingleOrNull();
}
@override
Stream<ProfileEntry?> watchActiveProfile() {

View File

@@ -22,6 +22,7 @@ import 'package:uuid/uuid.dart';
abstract interface class ProfileRepository {
TaskEither<ProfileFailure, Unit> init();
TaskEither<ProfileFailure, ProfileEntity?> getById(String id);
Future<ProfileEntity?> getByName(String name);
Stream<Either<ProfileFailure, ProfileEntity?>> watchActiveProfile();
Stream<Either<ProfileFailure, bool>> watchHasAnyProfile();
@@ -97,6 +98,11 @@ class ProfileRepositoryImpl
);
}
@override
Future<ProfileEntity?> getByName(String name) async {
return (await profileDataSource.getByName(name))?.toEntity();
}
@override
Stream<Either<ProfileFailure, ProfileEntity?>> watchActiveProfile() {
return profileDataSource
@@ -361,7 +367,7 @@ class ProfileRepositoryImpl
);
}
static final _subInfoHeaders = [
static final _subInfoHeaders = [
'profile-title',
'content-disposition',
'subscription-userinfo',
@@ -422,9 +428,9 @@ class ProfileRepositoryImpl
for (final entry in contentHeaders.entries) {
if (!headers.keys.contains(entry.key) && entry.value.isNotEmpty) {
headers[entry.key] = entry.value;
}
}
}
return headers;
}