latest server code
Some checks failed
Build and Push Multi-Arch Docker Image / build-and-push (push) Failing after 38s
Some checks failed
Build and Push Multi-Arch Docker Image / build-and-push (push) Failing after 38s
Signed-off-by: Peter Siegmund <developer@mars3142.org>
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:cinema/common/env_module.dart';
|
||||
import 'package:cinema/feature/version/version.dart';
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:injectable/injectable.dart';
|
||||
@@ -11,29 +12,27 @@ const dioIMAGES = 'images';
|
||||
abstract class DioModule {
|
||||
@Named(dioAPI)
|
||||
@lazySingleton
|
||||
Dio get apiDio =>
|
||||
Dio( // Der Getter selbst wird annotiert und gibt die Instanz zurück
|
||||
BaseOptions(
|
||||
baseUrl: 'https://api.themoviedb.org/3',
|
||||
connectTimeout: const Duration(seconds: 10),
|
||||
receiveTimeout: const Duration(seconds: 10),
|
||||
headers: {
|
||||
'Authorization': 'Bearer ${Platform.environment['TMDB_API_KEY']}',
|
||||
'Content-Type': 'application/json',
|
||||
'Accept': 'application/json',
|
||||
'User-Agent': 'Cinema Service (v${Version().appVersion})'
|
||||
},
|
||||
),
|
||||
);
|
||||
Dio apiDio(@Named(apiKey) String apiKey) => Dio(
|
||||
BaseOptions(
|
||||
baseUrl: 'https://api.themoviedb.org/3',
|
||||
connectTimeout: const Duration(seconds: 10),
|
||||
receiveTimeout: const Duration(seconds: 10),
|
||||
headers: {
|
||||
'Authorization': 'Bearer $apiKey',
|
||||
'Content-Type': 'application/json',
|
||||
'Accept': 'application/json',
|
||||
'User-Agent': 'Cinema Service (v${Version().appVersion})',
|
||||
},
|
||||
),
|
||||
);
|
||||
|
||||
@Named(dioIMAGES)
|
||||
@lazySingleton
|
||||
Dio get imagesDio =>
|
||||
Dio( // Der Getter selbst wird annotiert und gibt die Instanz zurück
|
||||
BaseOptions(
|
||||
baseUrl: 'https://image.tmdb.org/t/p/original',
|
||||
connectTimeout: const Duration(seconds: 10),
|
||||
receiveTimeout: const Duration(seconds: 10),
|
||||
),
|
||||
);
|
||||
Dio get imagesDio => Dio(
|
||||
BaseOptions(
|
||||
baseUrl: 'https://image.tmdb.org/t/p/original',
|
||||
connectTimeout: const Duration(seconds: 10),
|
||||
receiveTimeout: const Duration(seconds: 10),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
18
server/cinema/lib/common/env_module.dart
Normal file
18
server/cinema/lib/common/env_module.dart
Normal file
@@ -0,0 +1,18 @@
|
||||
import 'dart:io';
|
||||
import 'package:injectable/injectable.dart';
|
||||
import 'package:cinema/common/env_not_found_exception.dart';
|
||||
|
||||
const apiKey = "apiKey";
|
||||
|
||||
@module
|
||||
abstract class EnvModule {
|
||||
@lazySingleton
|
||||
@Named(apiKey)
|
||||
String get api_key {
|
||||
final key = Platform.environment['TMDB_API_KEY'];
|
||||
if (key == null || key.isEmpty) {
|
||||
throw EnvNotFoundException('TMDB_API_KEY environment variable is missing.');
|
||||
}
|
||||
return key;
|
||||
}
|
||||
}
|
||||
8
server/cinema/lib/common/env_not_found_exception.dart
Normal file
8
server/cinema/lib/common/env_not_found_exception.dart
Normal file
@@ -0,0 +1,8 @@
|
||||
class EnvNotFoundException implements Exception {
|
||||
final String message;
|
||||
EnvNotFoundException([this.message = '']);
|
||||
|
||||
@override
|
||||
String toString() => 'EnvNotFoundException: $message';
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user