mirror of
https://github.com/Dr-Blank/Vaani.git
synced 2026-01-14 06:09:32 +00:00
chore: run dart format
Some checks are pending
Flutter CI & Release / Test (push) Waiting to run
Flutter CI & Release / Build Android APKs (push) Blocked by required conditions
Flutter CI & Release / build_linux (push) Blocked by required conditions
Flutter CI & Release / Create GitHub Release (push) Blocked by required conditions
Some checks are pending
Flutter CI & Release / Test (push) Waiting to run
Flutter CI & Release / Build Android APKs (push) Blocked by required conditions
Flutter CI & Release / build_linux (push) Blocked by required conditions
Flutter CI & Release / Create GitHub Release (push) Blocked by required conditions
This commit is contained in:
parent
a520136e01
commit
e23c0b6c5f
84 changed files with 1565 additions and 1945 deletions
|
|
@ -16,10 +16,8 @@ import 'package:vaani/shared/extensions/obfuscation.dart';
|
|||
part 'api_provider.g.dart';
|
||||
|
||||
// TODO: workaround for https://github.com/rrousselGit/riverpod/issues/3718
|
||||
typedef ResponseErrorHandler = void Function(
|
||||
Response response, [
|
||||
Object? error,
|
||||
]);
|
||||
typedef ResponseErrorHandler =
|
||||
void Function(Response response, [Object? error]);
|
||||
|
||||
final _logger = Logger('api_provider');
|
||||
|
||||
|
|
@ -39,9 +37,7 @@ AudiobookshelfApi audiobookshelfApi(Ref ref, Uri? baseUrl) {
|
|||
// try to get the base url from app settings
|
||||
final apiSettings = ref.watch(apiSettingsProvider);
|
||||
baseUrl ??= apiSettings.activeServer?.serverUrl;
|
||||
return AudiobookshelfApi(
|
||||
baseUrl: makeBaseUrl(baseUrl.toString()),
|
||||
);
|
||||
return AudiobookshelfApi(baseUrl: makeBaseUrl(baseUrl.toString()));
|
||||
}
|
||||
|
||||
/// get the api instance for the authenticated user
|
||||
|
|
@ -68,9 +64,9 @@ FutureOr<bool> isServerAlive(Ref ref, String address) async {
|
|||
}
|
||||
|
||||
try {
|
||||
return await AudiobookshelfApi(baseUrl: makeBaseUrl(address))
|
||||
.server
|
||||
.ping() ??
|
||||
return await AudiobookshelfApi(
|
||||
baseUrl: makeBaseUrl(address),
|
||||
).server.ping() ??
|
||||
false;
|
||||
} catch (e) {
|
||||
return false;
|
||||
|
|
@ -86,8 +82,9 @@ FutureOr<ServerStatusResponse?> serverStatus(
|
|||
]) async {
|
||||
_logger.fine('fetching server status: ${baseUrl.obfuscate()}');
|
||||
final api = ref.watch(audiobookshelfApiProvider(baseUrl));
|
||||
final res =
|
||||
await api.server.status(responseErrorHandler: responseErrorHandler);
|
||||
final res = await api.server.status(
|
||||
responseErrorHandler: responseErrorHandler,
|
||||
);
|
||||
_logger.fine('server status: $res');
|
||||
return res;
|
||||
}
|
||||
|
|
@ -113,7 +110,9 @@ class PersonalizedView extends _$PersonalizedView {
|
|||
yield [];
|
||||
return;
|
||||
}
|
||||
ref.read(apiSettingsProvider.notifier).updateState(
|
||||
ref
|
||||
.read(apiSettingsProvider.notifier)
|
||||
.updateState(
|
||||
apiSettings.copyWith(activeLibraryId: login.userDefaultLibraryId),
|
||||
);
|
||||
yield [];
|
||||
|
|
@ -122,9 +121,8 @@ class PersonalizedView extends _$PersonalizedView {
|
|||
// try to find in cache
|
||||
// final cacheKey = 'personalizedView:${apiSettings.activeLibraryId}';
|
||||
final key = 'personalizedView:${apiSettings.activeLibraryId! + user.id}';
|
||||
final cachedRes = await apiResponseCacheManager.getFileFromMemory(
|
||||
key,
|
||||
) ??
|
||||
final cachedRes =
|
||||
await apiResponseCacheManager.getFileFromMemory(key) ??
|
||||
await apiResponseCacheManager.getFileFromCache(key);
|
||||
if (cachedRes != null) {
|
||||
_logger.fine('reading from cache: $cachedRes for key: $key');
|
||||
|
|
@ -143,8 +141,9 @@ class PersonalizedView extends _$PersonalizedView {
|
|||
|
||||
// ! exaggerated delay
|
||||
// await Future.delayed(const Duration(seconds: 2));
|
||||
final res = await api.libraries
|
||||
.getPersonalized(libraryId: apiSettings.activeLibraryId!);
|
||||
final res = await api.libraries.getPersonalized(
|
||||
libraryId: apiSettings.activeLibraryId!,
|
||||
);
|
||||
// debugPrint('personalizedView: ${res!.map((e) => e).toSet()}');
|
||||
// save to cache
|
||||
if (res != null) {
|
||||
|
|
@ -172,9 +171,7 @@ class PersonalizedView extends _$PersonalizedView {
|
|||
|
||||
/// fetch continue listening audiobooks
|
||||
@riverpod
|
||||
FutureOr<GetUserSessionsResponse> fetchContinueListening(
|
||||
Ref ref,
|
||||
) async {
|
||||
FutureOr<GetUserSessionsResponse> fetchContinueListening(Ref ref) async {
|
||||
final api = ref.watch(authenticatedApiProvider);
|
||||
final res = await api.me.getSessions();
|
||||
// debugPrint(
|
||||
|
|
@ -184,9 +181,7 @@ FutureOr<GetUserSessionsResponse> fetchContinueListening(
|
|||
}
|
||||
|
||||
@riverpod
|
||||
FutureOr<User> me(
|
||||
Ref ref,
|
||||
) async {
|
||||
FutureOr<User> me(Ref ref) async {
|
||||
final api = ref.watch(authenticatedApiProvider);
|
||||
final errorResponseHandler = ErrorResponseHandler();
|
||||
final res = await api.me.getUser(
|
||||
|
|
@ -202,10 +197,7 @@ FutureOr<User> me(
|
|||
}
|
||||
|
||||
@riverpod
|
||||
FutureOr<LoginResponse?> login(
|
||||
Ref ref, {
|
||||
AuthenticatedUser? user,
|
||||
}) async {
|
||||
FutureOr<LoginResponse?> login(Ref ref, {AuthenticatedUser? user}) async {
|
||||
if (user == null) {
|
||||
// try to get the user from settings
|
||||
final apiSettings = ref.watch(apiSettingsProvider);
|
||||
|
|
|
|||
|
|
@ -35,9 +35,7 @@ class AuthenticatedUsers extends _$AuthenticatedUsers {
|
|||
Set<model.AuthenticatedUser> readFromBoxOrCreate() {
|
||||
if (_box.isNotEmpty) {
|
||||
final foundData = _box.getRange(0, _box.length);
|
||||
_logger.fine(
|
||||
'found users in box: ${foundData.obfuscate()}',
|
||||
);
|
||||
_logger.fine('found users in box: ${foundData.obfuscate()}');
|
||||
return foundData.toSet();
|
||||
} else {
|
||||
_logger.fine('no settings found in box');
|
||||
|
|
@ -59,11 +57,9 @@ class AuthenticatedUsers extends _$AuthenticatedUsers {
|
|||
ref.invalidateSelf();
|
||||
if (setActive) {
|
||||
final apiSettings = ref.read(apiSettingsProvider);
|
||||
ref.read(apiSettingsProvider.notifier).updateState(
|
||||
apiSettings.copyWith(
|
||||
activeUser: user,
|
||||
),
|
||||
);
|
||||
ref
|
||||
.read(apiSettingsProvider.notifier)
|
||||
.updateState(apiSettings.copyWith(activeUser: user));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -86,11 +82,9 @@ class AuthenticatedUsers extends _$AuthenticatedUsers {
|
|||
// replace the active user with the first user in the list
|
||||
// or null if there are no users left
|
||||
final newActiveUser = state.isNotEmpty ? state.first : null;
|
||||
ref.read(apiSettingsProvider.notifier).updateState(
|
||||
apiSettings.copyWith(
|
||||
activeUser: newActiveUser,
|
||||
),
|
||||
);
|
||||
ref
|
||||
.read(apiSettingsProvider.notifier)
|
||||
.updateState(apiSettings.copyWith(activeUser: newActiveUser));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,7 +27,8 @@ class CoverImage extends _$CoverImage {
|
|||
// await Future.delayed(const Duration(seconds: 2));
|
||||
|
||||
// try to get the image from the cache
|
||||
final file = await imageCacheManager.getFileFromMemory(itemId) ??
|
||||
final file =
|
||||
await imageCacheManager.getFileFromMemory(itemId) ??
|
||||
await imageCacheManager.getFileFromCache(itemId);
|
||||
|
||||
if (file != null) {
|
||||
|
|
@ -44,9 +45,7 @@ class CoverImage extends _$CoverImage {
|
|||
);
|
||||
return;
|
||||
} else {
|
||||
_logger.fine(
|
||||
'cover image stale for $itemId, fetching from the server',
|
||||
);
|
||||
_logger.fine('cover image stale for $itemId, fetching from the server');
|
||||
}
|
||||
} else {
|
||||
_logger.fine('cover image not found in cache for $itemId');
|
||||
|
|
|
|||
|
|
@ -26,7 +26,8 @@ class LibraryItem extends _$LibraryItem {
|
|||
|
||||
// look for the item in the cache
|
||||
final key = CacheKey.libraryItem(id);
|
||||
final cachedFile = await apiResponseCacheManager.getFileFromMemory(key) ??
|
||||
final cachedFile =
|
||||
await apiResponseCacheManager.getFileFromMemory(key) ??
|
||||
await apiResponseCacheManager.getFileFromCache(key);
|
||||
if (cachedFile != null) {
|
||||
_logger.fine(
|
||||
|
|
|
|||
|
|
@ -33,8 +33,9 @@ Future<Library?> library(Ref ref, String id) async {
|
|||
|
||||
@riverpod
|
||||
Future<Library?> currentLibrary(Ref ref) async {
|
||||
final libraryId =
|
||||
ref.watch(apiSettingsProvider.select((s) => s.activeLibraryId));
|
||||
final libraryId = ref.watch(
|
||||
apiSettingsProvider.select((s) => s.activeLibraryId),
|
||||
);
|
||||
if (libraryId == null) {
|
||||
_logger.warning('No active library id found');
|
||||
return null;
|
||||
|
|
|
|||
|
|
@ -80,11 +80,9 @@ class AudiobookShelfServer extends _$AudiobookShelfServer {
|
|||
// remove the server from the active server
|
||||
final apiSettings = ref.read(apiSettingsProvider);
|
||||
if (apiSettings.activeServer == server) {
|
||||
ref.read(apiSettingsProvider.notifier).updateState(
|
||||
apiSettings.copyWith(
|
||||
activeServer: null,
|
||||
),
|
||||
);
|
||||
ref
|
||||
.read(apiSettingsProvider.notifier)
|
||||
.updateState(apiSettings.copyWith(activeServer: null));
|
||||
}
|
||||
// remove the users of this server
|
||||
if (removeUsers) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue