mirror of
https://github.com/austinried/subtracks.git
synced 2026-02-10 15:02:42 +01:00
display albums from db
This commit is contained in:
39
lib/app/state/source.dart
Normal file
39
lib/app/state/source.dart
Normal file
@@ -0,0 +1,39 @@
|
||||
import 'package:drift/drift.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
|
||||
import '../../sources/music_source.dart';
|
||||
import '../../sources/subsonic/client.dart';
|
||||
import '../../sources/subsonic/source.dart';
|
||||
import '../../util/http.dart';
|
||||
import 'database.dart';
|
||||
import 'settings.dart';
|
||||
|
||||
final _sourceProvider = FutureProvider<MusicSource>((ref) async {
|
||||
final db = ref.watch(databaseProvider);
|
||||
final sourceId = ref.watch(sourceIdProvider);
|
||||
|
||||
final query = db.sources.select().join([
|
||||
leftOuterJoin(
|
||||
db.subsonicSettings,
|
||||
db.subsonicSettings.sourceId.equalsExp(db.sources.id),
|
||||
),
|
||||
])..where(db.sources.id.equals(sourceId));
|
||||
|
||||
final result = await query.getSingle();
|
||||
final subsonicSettings = result.readTable(db.subsonicSettings);
|
||||
|
||||
return SubsonicSource(
|
||||
SubsonicClient(
|
||||
http: SubtracksHttpClient(),
|
||||
address: subsonicSettings.address,
|
||||
username: subsonicSettings.username,
|
||||
password: subsonicSettings.password,
|
||||
useTokenAuth: subsonicSettings.useTokenAuth,
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
final sourceProvider = Provider<MusicSource>((ref) {
|
||||
final source = ref.watch(_sourceProvider);
|
||||
return source.requireValue;
|
||||
});
|
||||
Reference in New Issue
Block a user