mirror of
https://github.com/jagandeepbrar/lunasea.git
synced 2026-08-31 12:42:34 +00:00
fix(database): fallback to defaults on null values in profile
This commit is contained in:
@@ -22,205 +22,133 @@ class LunaProfile extends HiveObject {
|
||||
}
|
||||
|
||||
@JsonKey()
|
||||
@HiveField(0)
|
||||
@HiveField(0, defaultValue: false)
|
||||
bool lidarrEnabled;
|
||||
|
||||
@JsonKey()
|
||||
@HiveField(1)
|
||||
@HiveField(1, defaultValue: '')
|
||||
String lidarrHost;
|
||||
|
||||
@JsonKey()
|
||||
@HiveField(2)
|
||||
@HiveField(2, defaultValue: '')
|
||||
String lidarrKey;
|
||||
|
||||
@JsonKey()
|
||||
@HiveField(26)
|
||||
@HiveField(26, defaultValue: <String, String>{})
|
||||
Map<String, String> lidarrHeaders;
|
||||
|
||||
Map<String, dynamic> getLidarr() {
|
||||
return {
|
||||
'enabled': lidarrEnabled,
|
||||
'host': lidarrHost,
|
||||
'key': lidarrKey,
|
||||
'headers': lidarrHeaders,
|
||||
};
|
||||
}
|
||||
|
||||
@JsonKey()
|
||||
@HiveField(3)
|
||||
@HiveField(3, defaultValue: false)
|
||||
bool radarrEnabled;
|
||||
|
||||
@JsonKey()
|
||||
@HiveField(4)
|
||||
@HiveField(4, defaultValue: '')
|
||||
String radarrHost;
|
||||
|
||||
@JsonKey()
|
||||
@HiveField(5)
|
||||
@HiveField(5, defaultValue: '')
|
||||
String radarrKey;
|
||||
|
||||
@HiveField(27)
|
||||
@JsonKey()
|
||||
@HiveField(27, defaultValue: <String, String>{})
|
||||
Map<String, String> radarrHeaders;
|
||||
|
||||
Map<String, dynamic> getRadarr() {
|
||||
return {
|
||||
'enabled': radarrEnabled,
|
||||
'host': radarrHost,
|
||||
'key': radarrKey,
|
||||
'headers': radarrHeaders,
|
||||
};
|
||||
}
|
||||
|
||||
@JsonKey()
|
||||
@HiveField(6)
|
||||
@HiveField(6, defaultValue: false)
|
||||
bool sonarrEnabled;
|
||||
|
||||
@JsonKey()
|
||||
@HiveField(7)
|
||||
@HiveField(7, defaultValue: '')
|
||||
String sonarrHost;
|
||||
|
||||
@JsonKey()
|
||||
@HiveField(8)
|
||||
@HiveField(8, defaultValue: '')
|
||||
String sonarrKey;
|
||||
|
||||
@JsonKey()
|
||||
@HiveField(28)
|
||||
@HiveField(28, defaultValue: <String, String>{})
|
||||
Map<String, String> sonarrHeaders;
|
||||
|
||||
Map<String, dynamic> getSonarr() {
|
||||
return {
|
||||
'enabled': sonarrEnabled,
|
||||
'host': sonarrHost,
|
||||
'key': sonarrKey,
|
||||
'headers': sonarrHeaders,
|
||||
};
|
||||
}
|
||||
|
||||
@JsonKey()
|
||||
@HiveField(9)
|
||||
@HiveField(9, defaultValue: false)
|
||||
bool sabnzbdEnabled;
|
||||
|
||||
@JsonKey()
|
||||
@HiveField(10)
|
||||
@HiveField(10, defaultValue: '')
|
||||
String sabnzbdHost;
|
||||
|
||||
@JsonKey()
|
||||
@HiveField(11)
|
||||
@HiveField(11, defaultValue: '')
|
||||
String sabnzbdKey;
|
||||
|
||||
@JsonKey()
|
||||
@JsonKey()
|
||||
@HiveField(29)
|
||||
@HiveField(29, defaultValue: <String, String>{})
|
||||
Map<String, String> sabnzbdHeaders;
|
||||
|
||||
Map<String, dynamic> getSABnzbd() {
|
||||
return {
|
||||
'enabled': sabnzbdEnabled,
|
||||
'host': sabnzbdHost,
|
||||
'key': sabnzbdKey,
|
||||
'headers': sabnzbdHeaders,
|
||||
};
|
||||
}
|
||||
|
||||
@JsonKey()
|
||||
@HiveField(12)
|
||||
@HiveField(12, defaultValue: false)
|
||||
bool nzbgetEnabled;
|
||||
|
||||
@JsonKey()
|
||||
@HiveField(13)
|
||||
@HiveField(13, defaultValue: '')
|
||||
String nzbgetHost;
|
||||
|
||||
@JsonKey()
|
||||
@HiveField(14)
|
||||
@HiveField(14, defaultValue: '')
|
||||
String nzbgetUser;
|
||||
|
||||
@JsonKey()
|
||||
@HiveField(15)
|
||||
@HiveField(15, defaultValue: '')
|
||||
String nzbgetPass;
|
||||
|
||||
@JsonKey()
|
||||
@HiveField(30)
|
||||
@HiveField(30, defaultValue: <String, String>{})
|
||||
Map<String, String> nzbgetHeaders;
|
||||
|
||||
Map<String, dynamic> getNZBGet() {
|
||||
return {
|
||||
'enabled': nzbgetEnabled,
|
||||
'host': nzbgetHost,
|
||||
'user': nzbgetUser,
|
||||
'pass': nzbgetPass,
|
||||
'headers': nzbgetHeaders,
|
||||
};
|
||||
}
|
||||
|
||||
@JsonKey()
|
||||
@HiveField(23)
|
||||
@HiveField(23, defaultValue: false)
|
||||
bool wakeOnLANEnabled;
|
||||
|
||||
@JsonKey()
|
||||
@HiveField(24)
|
||||
@HiveField(24, defaultValue: '')
|
||||
String wakeOnLANBroadcastAddress;
|
||||
|
||||
@JsonKey()
|
||||
@HiveField(25)
|
||||
@HiveField(25, defaultValue: '')
|
||||
String wakeOnLANMACAddress;
|
||||
|
||||
Map<String, dynamic> getWakeOnLAN() {
|
||||
return {
|
||||
'enabled': wakeOnLANEnabled,
|
||||
'broadcastAddress': wakeOnLANBroadcastAddress,
|
||||
'MACAddress': wakeOnLANMACAddress,
|
||||
};
|
||||
}
|
||||
|
||||
@JsonKey()
|
||||
@HiveField(31)
|
||||
@HiveField(31, defaultValue: false)
|
||||
bool tautulliEnabled;
|
||||
|
||||
@JsonKey()
|
||||
@HiveField(32)
|
||||
@HiveField(32, defaultValue: '')
|
||||
String tautulliHost;
|
||||
|
||||
@JsonKey()
|
||||
@HiveField(33)
|
||||
@HiveField(33, defaultValue: '')
|
||||
String tautulliKey;
|
||||
|
||||
@JsonKey()
|
||||
@HiveField(35)
|
||||
@HiveField(35, defaultValue: <String, String>{})
|
||||
Map<String, String> tautulliHeaders;
|
||||
|
||||
Map<String, dynamic> getTautulli() {
|
||||
return {
|
||||
'enabled': tautulliEnabled,
|
||||
'host': tautulliHost,
|
||||
'key': tautulliKey,
|
||||
'headers': tautulliHeaders,
|
||||
};
|
||||
}
|
||||
|
||||
@JsonKey()
|
||||
@HiveField(40)
|
||||
@HiveField(40, defaultValue: false)
|
||||
bool overseerrEnabled;
|
||||
|
||||
@JsonKey()
|
||||
@HiveField(41)
|
||||
@HiveField(41, defaultValue: '')
|
||||
String overseerrHost;
|
||||
|
||||
@JsonKey()
|
||||
@HiveField(42)
|
||||
@HiveField(42, defaultValue: '')
|
||||
String overseerrKey;
|
||||
|
||||
@JsonKey()
|
||||
@HiveField(43)
|
||||
@HiveField(43, defaultValue: <String, String>{})
|
||||
Map<String, String> overseerrHeaders;
|
||||
|
||||
Map<String, dynamic> getOverseerr() {
|
||||
return {
|
||||
'enabled': overseerrEnabled,
|
||||
'host': overseerrHost,
|
||||
'key': overseerrKey,
|
||||
'headers': overseerrHeaders,
|
||||
};
|
||||
}
|
||||
|
||||
LunaProfile({
|
||||
//Lidarr
|
||||
this.lidarrEnabled = false,
|
||||
|
||||
@@ -9,32 +9,30 @@ import 'package:lunasea/widgets/ui.dart';
|
||||
import 'package:lunasea/vendor.dart';
|
||||
|
||||
class API {
|
||||
final Map<String, dynamic>? lidarr;
|
||||
final Map<String, dynamic>? radarr;
|
||||
final Map<String, dynamic>? sonarr;
|
||||
final LunaProfile profile;
|
||||
|
||||
API._internal({
|
||||
required this.lidarr,
|
||||
required this.radarr,
|
||||
required this.sonarr,
|
||||
required this.profile,
|
||||
});
|
||||
|
||||
factory API.from(LunaProfile? profile) {
|
||||
return API._internal(
|
||||
lidarr: profile?.getLidarr(),
|
||||
radarr: profile?.getRadarr(),
|
||||
sonarr: profile?.getSonarr(),
|
||||
);
|
||||
factory API() {
|
||||
return API._internal(profile: LunaProfile.current);
|
||||
}
|
||||
|
||||
Future<Map<DateTime, List<CalendarData>>> getUpcoming(DateTime today) async {
|
||||
Map<DateTime, List<CalendarData>> _upcoming = {};
|
||||
if (lidarr!['enabled'] && DashboardDatabase.CALENDAR_ENABLE_LIDARR.read())
|
||||
if (profile.lidarrEnabled &&
|
||||
DashboardDatabase.CALENDAR_ENABLE_LIDARR.read()) {
|
||||
await _getLidarrUpcoming(_upcoming, today);
|
||||
if (radarr!['enabled'] && DashboardDatabase.CALENDAR_ENABLE_RADARR.read())
|
||||
}
|
||||
if (profile.radarrEnabled &&
|
||||
DashboardDatabase.CALENDAR_ENABLE_RADARR.read()) {
|
||||
await _getRadarrUpcoming(_upcoming, today);
|
||||
if (sonarr!['enabled'] && DashboardDatabase.CALENDAR_ENABLE_SONARR.read())
|
||||
}
|
||||
if (profile.sonarrEnabled &&
|
||||
DashboardDatabase.CALENDAR_ENABLE_SONARR.read()) {
|
||||
await _getSonarrUpcoming(_upcoming, today);
|
||||
}
|
||||
return _upcoming;
|
||||
}
|
||||
|
||||
@@ -42,17 +40,15 @@ class API {
|
||||
Map<DateTime, List<CalendarData>> map,
|
||||
DateTime today,
|
||||
) async {
|
||||
Map<String, dynamic> _headers =
|
||||
Map<String, dynamic>.from(lidarr!['headers']);
|
||||
Dio _client = Dio(
|
||||
BaseOptions(
|
||||
baseUrl: '${lidarr!['host']}/api/v1/',
|
||||
baseUrl: '${profile.lidarrHost}/api/v1/',
|
||||
queryParameters: {
|
||||
if (lidarr!['key'] != '') 'apikey': lidarr!['key'],
|
||||
if (profile.lidarrKey != '') 'apikey': profile.lidarrKey,
|
||||
'start': _startDate(today),
|
||||
'end': _endDate(today),
|
||||
},
|
||||
headers: _headers,
|
||||
headers: profile.lidarrHeaders,
|
||||
followRedirects: true,
|
||||
maxRedirects: 5,
|
||||
),
|
||||
@@ -87,17 +83,15 @@ class API {
|
||||
Map<DateTime, List<CalendarData>> map,
|
||||
DateTime today,
|
||||
) async {
|
||||
Map<String, dynamic> _headers =
|
||||
Map<String, dynamic>.from(radarr!['headers']);
|
||||
Dio _client = Dio(
|
||||
BaseOptions(
|
||||
baseUrl: '${radarr!['host']}/api/v3/',
|
||||
baseUrl: '${profile.radarrHost}/api/v3/',
|
||||
queryParameters: {
|
||||
if (radarr!['key'] != '') 'apikey': radarr!['key'],
|
||||
if (profile.radarrKey != '') 'apikey': profile.radarrKey,
|
||||
'start': _startDate(today),
|
||||
'end': _endDate(today),
|
||||
},
|
||||
headers: _headers,
|
||||
headers: profile.radarrHeaders,
|
||||
followRedirects: true,
|
||||
maxRedirects: 5,
|
||||
),
|
||||
@@ -142,17 +136,15 @@ class API {
|
||||
Map<DateTime, List<CalendarData>> map,
|
||||
DateTime today,
|
||||
) async {
|
||||
Map<String, dynamic> _headers =
|
||||
Map<String, dynamic>.from(sonarr!['headers']);
|
||||
Dio _client = Dio(
|
||||
BaseOptions(
|
||||
baseUrl: '${sonarr!['host']}/api/v3/',
|
||||
baseUrl: '${profile.sonarrHost}/api/v3/',
|
||||
queryParameters: {
|
||||
if (sonarr!['key'] != '') 'apikey': sonarr!['key'],
|
||||
if (profile.sonarrKey != '') 'apikey': profile.sonarrKey,
|
||||
'start': _startDate(today),
|
||||
'end': _endDate(today),
|
||||
},
|
||||
headers: _headers,
|
||||
headers: profile.sonarrHeaders,
|
||||
followRedirects: true,
|
||||
maxRedirects: 5,
|
||||
),
|
||||
|
||||
@@ -7,7 +7,6 @@ import 'package:lunasea/modules/lidarr/routes/search_results.dart';
|
||||
import 'package:lunasea/modules/dashboard/core/api/data/abstract.dart';
|
||||
|
||||
class CalendarLidarrData extends CalendarData {
|
||||
final Map<String, dynamic> api = LunaProfile.current.getLidarr();
|
||||
String albumTitle;
|
||||
int artistId;
|
||||
int totalTrackCount;
|
||||
@@ -92,19 +91,27 @@ class CalendarLidarrData extends CalendarData {
|
||||
|
||||
@override
|
||||
String backgroundUrl(BuildContext context) {
|
||||
return api['enabled']
|
||||
? (api['host'] as String).endsWith('/')
|
||||
? '${api['host']}api/v1/MediaCover/Artist/$artistId/fanart-360.jpg?apikey=${api['key']}'
|
||||
: '${api['host']}/api/v1/MediaCover/Artist/$artistId/fanart-360.jpg?apikey=${api['key']}'
|
||||
: '';
|
||||
final host = LunaProfile.current.lidarrHost;
|
||||
final key = LunaProfile.current.lidarrKey;
|
||||
if (LunaProfile.current.lidarrEnabled) {
|
||||
String _base = host.endsWith('/')
|
||||
? '${host}api/v1/MediaCover/Artist'
|
||||
: '$host/api/v1/MediaCover/Artist';
|
||||
return '$_base/$artistId/fanart-360.jpg?apikey=$key';
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
@override
|
||||
String posterUrl(BuildContext context) {
|
||||
return api['enabled']
|
||||
? (api['host'] as String).endsWith('/')
|
||||
? '${api['host']}api/v1/MediaCover/Artist/$artistId/poster-500.jpg?apikey=${api['key']}'
|
||||
: '${api['host']}/api/v1/MediaCover/Artist/$artistId/poster-500.jpg?apikey=${api['key']}'
|
||||
: '';
|
||||
final host = LunaProfile.current.lidarrHost;
|
||||
final key = LunaProfile.current.lidarrKey;
|
||||
if (LunaProfile.current.lidarrEnabled) {
|
||||
String _base = host.endsWith('/')
|
||||
? '${host}api/v1/MediaCover/Artist'
|
||||
: '$host/api/v1/MediaCover/Artist';
|
||||
return '$_base/$artistId/poster-500.jpg?apikey=$key';
|
||||
}
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:lunasea/database/models/profile.dart';
|
||||
import 'package:lunasea/extensions/int/duration.dart';
|
||||
import 'package:lunasea/extensions/string/string.dart';
|
||||
import 'package:lunasea/vendor.dart';
|
||||
@@ -13,7 +12,6 @@ import 'package:lunasea/modules/dashboard/core/api/data/abstract.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
class CalendarRadarrData extends CalendarData {
|
||||
final Map<String, dynamic> api = LunaProfile.current.getRadarr();
|
||||
bool hasFile;
|
||||
String? fileQualityProfile;
|
||||
int year;
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:lunasea/database/models/profile.dart';
|
||||
import 'package:lunasea/database/tables/lunasea.dart';
|
||||
import 'package:lunasea/extensions/string/string.dart';
|
||||
|
||||
@@ -14,7 +13,6 @@ import 'package:lunasea/modules/dashboard/core/api/data/abstract.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
class CalendarSonarrData extends CalendarData {
|
||||
final Map<String, dynamic> api = LunaProfile.current.getSonarr();
|
||||
String episodeTitle;
|
||||
int seasonNumber;
|
||||
int episodeNumber;
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import 'package:lunasea/database/models/profile.dart';
|
||||
import 'package:lunasea/deprecated/state/module_state.dart';
|
||||
import 'package:lunasea/database/tables/dashboard.dart';
|
||||
import 'package:lunasea/modules/dashboard/core/adapters/calendar_starting_type.dart';
|
||||
@@ -28,8 +27,7 @@ class ModuleState extends LunaModuleState {
|
||||
API? _api;
|
||||
API? get api => _api;
|
||||
void resetAPI() {
|
||||
LunaProfile? _profile = LunaProfile.current;
|
||||
_api = API.from(_profile);
|
||||
_api = API();
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
|
||||
@@ -30,11 +30,11 @@ class ContentBlock extends StatelessWidget {
|
||||
Map getHeaders() {
|
||||
switch (data.runtimeType) {
|
||||
case CalendarLidarrData:
|
||||
return LunaProfile.current.getLidarr()['headers'];
|
||||
return LunaProfile.current.lidarrHeaders;
|
||||
case CalendarRadarrData:
|
||||
return LunaProfile.current.getRadarr()['headers'];
|
||||
return LunaProfile.current.radarrHeaders;
|
||||
case CalendarSonarrData:
|
||||
return LunaProfile.current.getSonarr()['headers'];
|
||||
return LunaProfile.current.sonarrHeaders;
|
||||
default:
|
||||
return const {};
|
||||
}
|
||||
|
||||
@@ -2,40 +2,29 @@ import 'package:lunasea/core.dart';
|
||||
import 'package:lunasea/modules/lidarr.dart';
|
||||
|
||||
class LidarrAPI {
|
||||
final Map<String, dynamic> _values;
|
||||
final Dio _dio;
|
||||
|
||||
LidarrAPI._internal(this._values, this._dio);
|
||||
LidarrAPI._internal(this._dio);
|
||||
factory LidarrAPI.from(LunaProfile profile) {
|
||||
Map<String, dynamic> _headers =
|
||||
Map<String, dynamic>.from(profile.getLidarr()['headers']);
|
||||
Dio _client = Dio(
|
||||
BaseOptions(
|
||||
baseUrl: (profile.getLidarr()['host'] as String).endsWith('/')
|
||||
? '${profile.getLidarr()['host']}api/v1/'
|
||||
: '${profile.getLidarr()['host']}/api/v1/',
|
||||
baseUrl: profile.lidarrHost.endsWith('/')
|
||||
? '${profile.lidarrHost}api/v1/'
|
||||
: '${profile.lidarrHost}/api/v1/',
|
||||
queryParameters: {
|
||||
if (profile.getLidarr()['key'] != '')
|
||||
'apikey': profile.getLidarr()['key'],
|
||||
if (profile.lidarrKey != '') 'apikey': profile.lidarrKey,
|
||||
},
|
||||
headers: _headers,
|
||||
headers: LunaProfile.current.lidarrHeaders,
|
||||
followRedirects: true,
|
||||
maxRedirects: 5,
|
||||
),
|
||||
);
|
||||
return LidarrAPI._internal(
|
||||
profile.getLidarr(),
|
||||
_client,
|
||||
);
|
||||
return LidarrAPI._internal(_client);
|
||||
}
|
||||
|
||||
void logError(String text, Object error, StackTrace trace) =>
|
||||
LunaLogger().error('Lidarr: $text', error, trace);
|
||||
|
||||
bool? get enabled => _values['enabled'];
|
||||
String? get host => _values['host'];
|
||||
String? get key => _values['key'];
|
||||
|
||||
Future<dynamic> testConnection() async => await _dio.get('system/status');
|
||||
|
||||
Future<List<LidarrCatalogueData>> getAllArtists() async {
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import 'package:lunasea/core.dart';
|
||||
|
||||
class LidarrAlbumData {
|
||||
final Map<String, dynamic> api = LunaProfile.current.getLidarr();
|
||||
String title;
|
||||
String releaseDate;
|
||||
int albumID;
|
||||
@@ -32,11 +31,13 @@ class LidarrAlbumData {
|
||||
}
|
||||
|
||||
String albumCoverURI() {
|
||||
if (api['enabled']) {
|
||||
String _base = (api['host'] as String).endsWith('/')
|
||||
? '${api['host']}api/v1/MediaCover/Album'
|
||||
: '${api['host']}/api/v1/MediaCover/Album';
|
||||
return '$_base/$albumID/cover-250.jpg?apikey=${api['key']}';
|
||||
final host = LunaProfile.current.lidarrHost;
|
||||
final key = LunaProfile.current.lidarrKey;
|
||||
if (LunaProfile.current.lidarrEnabled) {
|
||||
String _base = host.endsWith('/')
|
||||
? '${host}api/v1/MediaCover/Album'
|
||||
: '$host/api/v1/MediaCover/Album';
|
||||
return '$_base/$albumID/cover-250.jpg?apikey=$key';
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ import 'package:lunasea/extensions/int/bytes.dart';
|
||||
import 'package:lunasea/modules/lidarr.dart';
|
||||
|
||||
class LidarrCatalogueData {
|
||||
final Map<String, dynamic> api = LunaProfile.current.getLidarr();
|
||||
String title;
|
||||
String sortTitle;
|
||||
String overview;
|
||||
@@ -121,21 +120,25 @@ class LidarrCatalogueData {
|
||||
}
|
||||
|
||||
String posterURI() {
|
||||
if (api['enabled']) {
|
||||
String _base = (api['host'] as String).endsWith('/')
|
||||
? '${api['host']}api/v1/MediaCover/Artist'
|
||||
: '${api['host']}/api/v1/MediaCover/Artist';
|
||||
return '$_base/$artistID/poster-500.jpg?apikey=${api['key']}';
|
||||
final host = LunaProfile.current.lidarrHost;
|
||||
final key = LunaProfile.current.lidarrKey;
|
||||
if (LunaProfile.current.lidarrEnabled) {
|
||||
String _base = host.endsWith('/')
|
||||
? '${host}api/v1/MediaCover/Artist'
|
||||
: '$host/api/v1/MediaCover/Artist';
|
||||
return '$_base/$artistID/poster-500.jpg?apikey=$key';
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
String fanartURI() {
|
||||
if (api['enabled']) {
|
||||
String _base = (api['host'] as String).endsWith('/')
|
||||
? '${api['host']}api/v1/MediaCover/Artist'
|
||||
: '${api['host']}/api/v1/MediaCover/Artist';
|
||||
return '$_base/$artistID/fanart-360.jpg?apikey=${api['key']}';
|
||||
String fanartURI({bool highRes = false}) {
|
||||
final host = LunaProfile.current.lidarrHost;
|
||||
final key = LunaProfile.current.lidarrKey;
|
||||
if (LunaProfile.current.lidarrEnabled) {
|
||||
String _base = host.endsWith('/')
|
||||
? '${host}api/v1/MediaCover/Artist'
|
||||
: '$host/api/v1/MediaCover/Artist';
|
||||
return '$_base/$artistID/fanart-360.jpg?apikey=$key';
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import 'package:lunasea/core.dart';
|
||||
|
||||
class LidarrMissingData {
|
||||
final Map<String, dynamic> api = LunaProfile.current.getLidarr();
|
||||
String title;
|
||||
String artistTitle;
|
||||
String releaseDate;
|
||||
@@ -43,31 +42,37 @@ class LidarrMissingData {
|
||||
}
|
||||
|
||||
String albumCoverURI() {
|
||||
if (api['enabled']) {
|
||||
String _base = (api['host'] as String).endsWith('/')
|
||||
? '${api['host']}api/v1/MediaCover/Album'
|
||||
: '${api['host']}/api/v1/MediaCover/Album';
|
||||
return '$_base/$albumID/cover-250.jpg?apikey=${api['key']}';
|
||||
final host = LunaProfile.current.lidarrHost;
|
||||
final key = LunaProfile.current.lidarrKey;
|
||||
if (LunaProfile.current.lidarrEnabled) {
|
||||
String _base = host.endsWith('/')
|
||||
? '${host}api/v1/MediaCover/Album'
|
||||
: '$host/api/v1/MediaCover/Album';
|
||||
return '$_base/$albumID/cover-250.jpg?apikey=$key';
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
String posterURI() {
|
||||
if (api['enabled']) {
|
||||
String _base = (api['host'] as String).endsWith('/')
|
||||
? '${api['host']}api/v1/MediaCover/Artist'
|
||||
: '${api['host']}/api/v1/MediaCover/Artist';
|
||||
return '$_base/$artistID/poster-500.jpg?apikey=${api['key']}';
|
||||
final host = LunaProfile.current.lidarrHost;
|
||||
final key = LunaProfile.current.lidarrKey;
|
||||
if (LunaProfile.current.lidarrEnabled) {
|
||||
String _base = host.endsWith('/')
|
||||
? '${host}api/v1/MediaCover/Artist'
|
||||
: '$host/api/v1/MediaCover/Artist';
|
||||
return '$_base/$artistID/poster-500.jpg?apikey=$key';
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
String fanartURI({bool highRes = false}) {
|
||||
if (api['enabled']) {
|
||||
String _base = (api['host'] as String).endsWith('/')
|
||||
? '${api['host']}api/v1/MediaCover/Artist'
|
||||
: '${api['host']}/api/v1/MediaCover/Artist';
|
||||
return '$_base/$artistID/fanart-360.jpg?apikey=${api['key']}';
|
||||
final host = LunaProfile.current.lidarrHost;
|
||||
final key = LunaProfile.current.lidarrKey;
|
||||
if (LunaProfile.current.lidarrEnabled) {
|
||||
String _base = host.endsWith('/')
|
||||
? '${host}api/v1/MediaCover/Artist'
|
||||
: '$host/api/v1/MediaCover/Artist';
|
||||
return '$_base/$artistID/fanart-360.jpg?apikey=$key';
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
@@ -153,7 +153,7 @@ class _State extends State<LidarrAddDetails> with LunaScrollControllerMixin {
|
||||
: _arguments!.data.overview,
|
||||
uri: _arguments!.data.posterURI ?? '',
|
||||
squareImage: true,
|
||||
headers: LunaProfile.current.getLidarr()['headers'],
|
||||
headers: LunaProfile.current.lidarrHeaders,
|
||||
onLongPress: () async {
|
||||
if (_arguments!.data.discogsLink == null ||
|
||||
_arguments!.data.discogsLink == '')
|
||||
|
||||
@@ -50,13 +50,13 @@ class _State extends State<Lidarr> {
|
||||
Widget _drawer() => LunaDrawer(page: LunaModule.LIDARR.key);
|
||||
|
||||
Widget? _bottomNavigationBar() {
|
||||
if (_api.enabled!)
|
||||
if (LunaProfile.current.lidarrEnabled)
|
||||
return LidarrNavigationBar(pageController: _pageController);
|
||||
return null;
|
||||
}
|
||||
|
||||
Widget _body() {
|
||||
if (!_api.enabled!)
|
||||
if (!LunaProfile.current.lidarrEnabled)
|
||||
return LunaMessage.moduleNotEnabled(
|
||||
context: context,
|
||||
module: LunaModule.LIDARR.title,
|
||||
@@ -87,7 +87,7 @@ class _State extends State<Lidarr> {
|
||||
return arr;
|
||||
});
|
||||
List<Widget>? actions;
|
||||
if (_api.enabled!)
|
||||
if (LunaProfile.current.lidarrEnabled)
|
||||
actions = [
|
||||
LunaIconButton(
|
||||
icon: Icons.add_rounded,
|
||||
|
||||
@@ -23,7 +23,7 @@ class LidarrAddSearchResultTile extends StatelessWidget {
|
||||
customBodyMaxLines: 3,
|
||||
trailing: alreadyAdded ? null : const LunaIconButton.arrow(),
|
||||
posterIsSquare: true,
|
||||
posterHeaders: LunaProfile.current.getLidarr()['headers'],
|
||||
posterHeaders: LunaProfile.current.lidarrHeaders,
|
||||
posterPlaceholderIcon: LunaIcons.USER,
|
||||
posterUrl: _posterUrl,
|
||||
onTap: () async => _enterDetails(context),
|
||||
|
||||
@@ -47,9 +47,9 @@ class _State extends State<LidarrCatalogueTile> {
|
||||
),
|
||||
posterPlaceholderIcon: LunaIcons.USER,
|
||||
posterUrl: widget.data.posterURI(),
|
||||
posterHeaders: LunaProfile.current.getLidarr()['headers'],
|
||||
posterHeaders: LunaProfile.current.lidarrHeaders,
|
||||
backgroundUrl: widget.data.fanartURI(),
|
||||
backgroundHeaders: LunaProfile.current.getLidarr()['headers'],
|
||||
backgroundHeaders: LunaProfile.current.lidarrHeaders,
|
||||
posterIsSquare: true,
|
||||
onTap: () async => _enterArtist(),
|
||||
onLongPress: () async => _handlePopup(),
|
||||
|
||||
@@ -22,7 +22,7 @@ class _State extends State<LidarrDetailsAlbumTile> {
|
||||
return LunaBlock(
|
||||
title: widget.data.title,
|
||||
disabled: !widget.data.monitored,
|
||||
posterHeaders: LunaProfile.current.getLidarr()['headers'] ?? {},
|
||||
posterHeaders: LunaProfile.current.lidarrHeaders,
|
||||
posterPlaceholderIcon: LunaIcons.MUSIC,
|
||||
posterIsSquare: true,
|
||||
posterUrl: widget.data.albumCoverURI(),
|
||||
|
||||
@@ -32,7 +32,7 @@ class _State extends State<LidarrDetailsOverview>
|
||||
: widget.data.overview,
|
||||
uri: widget.data.posterURI(),
|
||||
squareImage: true,
|
||||
headers: LunaProfile.current.getLidarr()['headers'],
|
||||
headers: LunaProfile.current.lidarrHeaders,
|
||||
),
|
||||
LunaTableCard(
|
||||
content: [
|
||||
|
||||
@@ -49,11 +49,11 @@ class _State extends State<LidarrMissingTile> {
|
||||
onTap: () async => _enterAlbum(),
|
||||
onLongPress: () async => _enterArtist(),
|
||||
posterUrl: widget.entry.albumCoverURI(),
|
||||
posterHeaders: LunaProfile.current.getLidarr()['headers'],
|
||||
posterHeaders: LunaProfile.current.lidarrHeaders,
|
||||
posterIsSquare: true,
|
||||
posterPlaceholderIcon: LunaIcons.MUSIC,
|
||||
backgroundUrl: widget.entry.fanartURI(),
|
||||
backgroundHeaders: LunaProfile.current.getLidarr()['headers'],
|
||||
backgroundHeaders: LunaProfile.current.lidarrHeaders,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -2,40 +2,30 @@ import 'package:lunasea/core.dart';
|
||||
import 'package:lunasea/modules/nzbget.dart';
|
||||
|
||||
class NZBGetAPI {
|
||||
final Map<String, dynamic> _values;
|
||||
final Dio _dio;
|
||||
|
||||
NZBGetAPI._internal(this._values, this._dio);
|
||||
NZBGetAPI._internal(this._dio);
|
||||
factory NZBGetAPI.from(LunaProfile profile) {
|
||||
String _baseURL = Uri.encodeFull(profile.getNZBGet()['host']);
|
||||
Map<String, dynamic> _headers =
|
||||
Map<String, dynamic>.from(profile.getNZBGet()['headers']);
|
||||
_baseURL += profile.getNZBGet()['user'] != '' &&
|
||||
profile.getNZBGet()['pass'] != ''
|
||||
? '/${profile.getNZBGet()['user']}:${profile.getNZBGet()['pass']}/jsonrpc'
|
||||
String _baseURL = Uri.encodeFull(profile.nzbgetHost);
|
||||
_baseURL += profile.nzbgetUser.isNotEmpty && profile.nzbgetPass.isNotEmpty
|
||||
? '/${profile.nzbgetUser}:${profile.nzbgetPass}/jsonrpc'
|
||||
: '/jsonrpc';
|
||||
|
||||
Dio _client = Dio(
|
||||
BaseOptions(
|
||||
baseUrl: _baseURL,
|
||||
headers: _headers,
|
||||
headers: profile.nzbgetHeaders,
|
||||
followRedirects: true,
|
||||
maxRedirects: 5,
|
||||
),
|
||||
);
|
||||
return NZBGetAPI._internal(
|
||||
profile.getNZBGet(),
|
||||
_client,
|
||||
);
|
||||
|
||||
return NZBGetAPI._internal(_client);
|
||||
}
|
||||
|
||||
void logError(String text, Object error, StackTrace trace) =>
|
||||
LunaLogger().error('NZBGet: $text', error, trace);
|
||||
|
||||
bool? get enabled => _values['enabled'];
|
||||
String? get host => _values['host'];
|
||||
String? get user => _values['user'];
|
||||
String? get pass => _values['pass'];
|
||||
|
||||
String getBody(String method, {List<dynamic>? params}) {
|
||||
return json.encode({
|
||||
"jsonrpc": "2.0",
|
||||
|
||||
@@ -55,8 +55,9 @@ class _State extends State<NZBGet> {
|
||||
Widget _drawer() => LunaDrawer(page: LunaModule.NZBGET.key);
|
||||
|
||||
Widget? _bottomNavigationBar() {
|
||||
if (_api.enabled!)
|
||||
if (LunaProfile.current.nzbgetEnabled) {
|
||||
return NZBGetNavigationBar(pageController: _pageController);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -67,7 +68,7 @@ class _State extends State<NZBGet> {
|
||||
return value;
|
||||
});
|
||||
List<Widget>? actions;
|
||||
if (_api.enabled!)
|
||||
if (LunaProfile.current.nzbgetEnabled)
|
||||
actions = [
|
||||
Selector<NZBGetState, bool>(
|
||||
selector: (_, model) => model.error,
|
||||
@@ -90,7 +91,7 @@ class _State extends State<NZBGet> {
|
||||
}
|
||||
|
||||
Widget _body() {
|
||||
if (!_api.enabled!)
|
||||
if (!LunaProfile.current.nzbgetEnabled)
|
||||
return LunaMessage.moduleNotEnabled(
|
||||
context: context,
|
||||
module: LunaModule.NZBGET.title,
|
||||
|
||||
@@ -2,39 +2,31 @@ import 'package:lunasea/core.dart';
|
||||
import 'package:lunasea/modules/sabnzbd.dart';
|
||||
|
||||
class SABnzbdAPI {
|
||||
final Map<String, dynamic> _values;
|
||||
final Dio _dio;
|
||||
|
||||
SABnzbdAPI._internal(this._values, this._dio);
|
||||
SABnzbdAPI._internal(this._dio);
|
||||
factory SABnzbdAPI.from(LunaProfile profile) {
|
||||
Map<String, dynamic> _headers =
|
||||
Map<String, dynamic>.from(profile.getSABnzbd()['headers']);
|
||||
Dio _client = Dio(
|
||||
BaseOptions(
|
||||
baseUrl: '${profile.getSABnzbd()['host']}/api',
|
||||
baseUrl: profile.sabnzbdHost.endsWith('/')
|
||||
? '${profile.sabnzbdHost}api'
|
||||
: '${profile.sabnzbdHost}/api',
|
||||
queryParameters: {
|
||||
if (profile.getSABnzbd()['key'] != '')
|
||||
'apikey': profile.getSABnzbd()['key'],
|
||||
if (profile.sabnzbdKey != '') 'apikey': profile.sabnzbdKey,
|
||||
'output': 'json',
|
||||
},
|
||||
headers: _headers,
|
||||
headers: profile.sabnzbdHeaders,
|
||||
followRedirects: true,
|
||||
maxRedirects: 5,
|
||||
),
|
||||
);
|
||||
return SABnzbdAPI._internal(
|
||||
profile.getSABnzbd(),
|
||||
_client,
|
||||
);
|
||||
|
||||
return SABnzbdAPI._internal(_client);
|
||||
}
|
||||
|
||||
void logError(String text, Object error, StackTrace trace) =>
|
||||
LunaLogger().error('SABnzbd: $text', error, trace);
|
||||
|
||||
bool? get enabled => _values['enabled'];
|
||||
String? get host => _values['host'];
|
||||
String? get key => _values['key'];
|
||||
|
||||
Future<dynamic> testConnection() async => _dio.get('', queryParameters: {
|
||||
'mode': 'fullstatus',
|
||||
});
|
||||
|
||||
@@ -54,7 +54,7 @@ class _State extends State<SABnzbd> {
|
||||
Widget _drawer() => LunaDrawer(page: LunaModule.SABNZBD.key);
|
||||
|
||||
Widget? _bottomNavigationBar() {
|
||||
if (_api.enabled!)
|
||||
if (LunaProfile.current.sabnzbdEnabled)
|
||||
return SABnzbdNavigationBar(pageController: _pageController);
|
||||
return null;
|
||||
}
|
||||
@@ -66,7 +66,7 @@ class _State extends State<SABnzbd> {
|
||||
return value;
|
||||
});
|
||||
List<Widget>? actions;
|
||||
if (_api.enabled!)
|
||||
if (LunaProfile.current.sabnzbdEnabled)
|
||||
actions = [
|
||||
Selector<SABnzbdState, bool>(
|
||||
selector: (_, model) => model.error,
|
||||
@@ -89,7 +89,7 @@ class _State extends State<SABnzbd> {
|
||||
}
|
||||
|
||||
Widget _body() {
|
||||
if (!_api.enabled!)
|
||||
if (!LunaProfile.current.sabnzbdEnabled)
|
||||
return LunaMessage.moduleNotEnabled(
|
||||
context: context,
|
||||
module: LunaModule.SABNZBD.title,
|
||||
|
||||
Reference in New Issue
Block a user