outsourced lots of api calls to api folder

centered error message when failed loading video feed
display server url on settings page
This commit is contained in:
2022-10-15 20:28:31 +02:00
parent cb42db80af
commit 9ef317f0ba
17 changed files with 147 additions and 159 deletions

View File

@ -1,5 +1,6 @@
import 'dart:convert';
import '../log/log.dart';
import '../types/actor.dart';
import 'api.dart';
@ -10,3 +11,26 @@ Future<List<Actor>> loadAllActors() async {
final actors = d.map((e) => Actor.fromJson(e)).toList(growable: false);
return actors;
}
Future<List<Actor>> loadActorsOfVideo(int movieId) async {
final data =
await API.query("actor", "getActorsOfVideo", {'MovieId': movieId});
if (data == 'null') {
return [];
}
final d = jsonDecode(data);
List<Actor> dta = (d as List).map((e) => Actor.fromJson(e)).toList();
return dta;
}
Future<void> addActorToVideo(int actorId, int movieId) async {
final data = await API.query(
"actor", "addActorToVideo", {'ActorId': actorId, 'MovieId': movieId});
final d = jsonDecode(data);
if (d["result"] != "success") {
Log.w("couldn't add actor to video");
}
}

23
lib/api/tag_api.dart Normal file
View File

@ -0,0 +1,23 @@
import 'dart:convert';
import '../log/log.dart';
import '../types/tag.dart';
import 'api.dart';
Future<List<Tag>> loadAllTags() async {
final data = await API.query("tags", "getAllTags", {});
final d = (jsonDecode(data) ?? []) as List<dynamic>;
final tags = d.map((e) => Tag.fromJson(e)).toList(growable: false);
return tags;
}
Future<void> addTagToVideo(int tagId, int movieId) async {
final data =
await API.query("tags", "addTag", {'TagId': tagId, 'MovieId': movieId});
final d = jsonDecode(data);
if (d["result"] != "success") {
Log.w("couldn't add actor to video");
}
}

View File

@ -1,5 +1,11 @@
import 'dart:convert';
import 'dart:math';
import 'dart:typed_data';
import '../log/log.dart';
import '../types/actor.dart';
import '../types/tag.dart';
import '../types/video.dart';
import '../types/video_data.dart';
import 'api.dart';
@ -10,3 +16,55 @@ Future<VideoData> loadVideoData(int videoId) async {
final video = VideoData.fromJson(d);
return video;
}
Future<List<VideoT>> loadVideo(Tag? tag, int filterIdx) async {
final data = await API
.query("video", "getMovies", {'Tag': tag?.tagId ?? 1, 'Sort': filterIdx});
final d = jsonDecode(data);
List<VideoT> dta =
(d['Videos'] as List).map((e) => VideoT.fromJson(e)).toList();
return dta;
}
Future<List<VideoT>> loadShuffledVideos(int nr) async {
final data = await API.query("video", "getRandomMovies",
{'Number': nr, 'Seed': Random().nextInt(0x7fffffff)});
final d = jsonDecode(data);
List<VideoT> dta =
(d['Videos'] as List).map((e) => VideoT.fromJson(e)).toList();
return dta;
}
Future<List<VideoT>> loadVideoByActor(Actor actor) async {
final data =
await API.query("actor", "getActorInfo", {'ActorId': actor.actorId});
final d = jsonDecode(data);
List<VideoT> dta =
(d['Videos'] as List).map((e) => VideoT.fromJson(e)).toList();
return dta;
}
Future<bool> addLike(int movieId) async {
final data = await API.query("video", "addLike", {'MovieId': movieId});
final d = jsonDecode(data);
if (d["result"] != 'success') {
Log.w(d);
}
return d["result"] == 'success';
}
Future<Uint8List> fetchThumbnail(int movieId) async {
final base64str =
await API.query("video", "readThumbnail", {'Movieid': movieId});
return base64Decode(base64str.substring(23));
}