mirror of
https://github.com/zoriya/Aeris.git
synced 2026-06-08 04:40:46 +00:00
Mobile Client: fix breaking change
This commit is contained in:
@@ -3,20 +3,37 @@
|
||||
"actions": [],
|
||||
"reactions": [
|
||||
{
|
||||
"name": "UpdateAbout",
|
||||
"description": "Update the about you section.",
|
||||
"name": "Anilist_UpdateAbout",
|
||||
"label": {
|
||||
"en": "Update 'About You' section",
|
||||
"fr": "Changer la bio"
|
||||
},
|
||||
"description": {
|
||||
"en": "Update 'About You' section",
|
||||
"fr": "Changer la bio"
|
||||
},
|
||||
"params": [
|
||||
{
|
||||
"name": "about",
|
||||
"type": "string",
|
||||
"description": "The description on your profile."
|
||||
"description": {
|
||||
"en": "The description of your profile",
|
||||
"fr": "Le contenu de la bio"
|
||||
}
|
||||
}
|
||||
],
|
||||
"returns": []
|
||||
},
|
||||
{
|
||||
"name": "ToggleFavourite",
|
||||
"description": "Add or remove an anime fro your favorite.",
|
||||
"name": "Anilist_ToggleFavourite",
|
||||
"label": {
|
||||
"en": "(Un)Favorite an anime",
|
||||
"fr": "(Dé)Liker un animé"
|
||||
},
|
||||
"description": {
|
||||
"en": "Add or remove an anime from your favorite.",
|
||||
"fr": "Ajouter ou modifier un animé des favoris"
|
||||
},
|
||||
"params": [
|
||||
{
|
||||
"name": "animeID",
|
||||
|
||||
@@ -40,7 +40,7 @@
|
||||
],
|
||||
"reactions": [
|
||||
{
|
||||
"name": "PlayTrack",
|
||||
"name": "Spotify_PlayTrack",
|
||||
"description": "Play a track",
|
||||
"params": [
|
||||
{
|
||||
@@ -76,7 +76,7 @@
|
||||
"returns": []
|
||||
},
|
||||
{
|
||||
"name": "AddTrackToLibrary",
|
||||
"name": "Spotify_AddTrackToLibrary",
|
||||
"description": "Add a track to library",
|
||||
"params": [
|
||||
{
|
||||
|
||||
@@ -29,7 +29,7 @@ enum AerisAPIRequestType { get, post, put, delete }
|
||||
/// Call to interact with Aeris' Back end
|
||||
class AerisAPI {
|
||||
/// Get Connection state
|
||||
bool _connected = false; //TODO Will be false later
|
||||
bool _connected = false;
|
||||
bool get isConnected => _connected;
|
||||
|
||||
/// JWT token used to request API
|
||||
@@ -37,8 +37,8 @@ class AerisAPI {
|
||||
|
||||
late final String deepLinkRoute;
|
||||
|
||||
String _baseRoute = GetIt.I<SharedPreferences>().getString('api')
|
||||
?? "http://10.0.2.2:8080";
|
||||
String _baseRoute =
|
||||
GetIt.I<SharedPreferences>().getString('api') ?? "http://10.0.2.2:8080";
|
||||
String get baseRoute => _baseRoute;
|
||||
set baseRoute(value) => _baseRoute = value;
|
||||
|
||||
@@ -141,8 +141,6 @@ class AerisAPI {
|
||||
Future<bool> editPipeline(Pipeline updatedPipeline) async {
|
||||
var res = await _requestAPI('/workflow/${updatedPipeline.id}',
|
||||
AerisAPIRequestType.put, updatedPipeline.toJSON());
|
||||
print(res.body);
|
||||
print(res.statusCode);
|
||||
return res.ok;
|
||||
}
|
||||
|
||||
@@ -150,7 +148,6 @@ class AerisAPI {
|
||||
Future<List<Pipeline>> getPipelines() async {
|
||||
var res = await _requestAPI('/workflows', AerisAPIRequestType.get, null);
|
||||
if (res.ok == false) return [];
|
||||
print(res.body);
|
||||
final List body = jsonDecode(res.body);
|
||||
|
||||
return body.map((e) => Pipeline.fromJSON(Map.from(e))).toList();
|
||||
@@ -162,7 +159,8 @@ class AerisAPI {
|
||||
await _requestAPI('/auth/services', AerisAPIRequestType.get, null);
|
||||
if (!res.ok) return [];
|
||||
return (jsonDecode(res.body) as List)
|
||||
.map((e) => Service.factory(e.toString())).toList();
|
||||
.map((e) => Service.factory(e.toString()))
|
||||
.toList();
|
||||
}
|
||||
|
||||
/// Disconnects the user from the service
|
||||
@@ -182,7 +180,8 @@ class AerisAPI {
|
||||
}
|
||||
|
||||
List<ActionTemplate> getActionsFor(Service service, aeris.Action action) {
|
||||
final catalogue = Aeris.materialKey.currentContext?.read<ActionCatalogueProvider>();
|
||||
final catalogue =
|
||||
Aeris.materialKey.currentContext?.read<ActionCatalogueProvider>();
|
||||
if (action is Trigger) {
|
||||
return catalogue!.triggerTemplates[service]!;
|
||||
}
|
||||
@@ -198,7 +197,7 @@ class AerisAPI {
|
||||
Future<http.Response> _requestAPI(
|
||||
String route, AerisAPIRequestType requestType, Object? body) async {
|
||||
final Map<String, String> header = {
|
||||
'Content-type' : 'application/json',
|
||||
'Content-type': 'application/json',
|
||||
'Accept': 'application/json',
|
||||
};
|
||||
if (_connected) {
|
||||
@@ -208,27 +207,40 @@ class AerisAPI {
|
||||
try {
|
||||
switch (requestType) {
|
||||
case AerisAPIRequestType.delete:
|
||||
return await http.delete(_encoreUri(route),
|
||||
body: jsonEncode(body), headers: header).timeout(duration,
|
||||
return await http
|
||||
.delete(_encoreUri(route),
|
||||
body: jsonEncode(body), headers: header)
|
||||
.timeout(
|
||||
duration,
|
||||
onTimeout: () {
|
||||
return http.Response('Error', 408);
|
||||
},);
|
||||
},
|
||||
);
|
||||
case AerisAPIRequestType.get:
|
||||
return await http.get(_encoreUri(route), headers: header).timeout(
|
||||
duration,
|
||||
onTimeout: () {
|
||||
return http.Response('Error', 408);
|
||||
},);
|
||||
},
|
||||
);
|
||||
case AerisAPIRequestType.post:
|
||||
return await http.post(_encoreUri(route), body: jsonEncode(body), headers: header).timeout(duration,
|
||||
return await http
|
||||
.post(_encoreUri(route), body: jsonEncode(body), headers: header)
|
||||
.timeout(
|
||||
duration,
|
||||
onTimeout: () {
|
||||
return http.Response('Error', 408);
|
||||
},);
|
||||
},
|
||||
);
|
||||
case AerisAPIRequestType.put:
|
||||
return await http.put(_encoreUri(route), body: jsonEncode(body), headers: header).timeout(duration,
|
||||
return await http
|
||||
.put(_encoreUri(route), body: jsonEncode(body), headers: header)
|
||||
.timeout(
|
||||
duration,
|
||||
onTimeout: () {
|
||||
return http.Response('Error', 408);
|
||||
},);
|
||||
},
|
||||
);
|
||||
}
|
||||
} catch (e) {
|
||||
return http.Response('{}', 400);
|
||||
|
||||
@@ -2,7 +2,6 @@ import 'package:aeris/src/models/action_parameter.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:aeris/src/models/service.dart';
|
||||
import 'package:recase/recase.dart';
|
||||
import 'package:tuple/tuple.dart';
|
||||
|
||||
///Base class for reactions and trigger
|
||||
abstract class Action {
|
||||
@@ -25,16 +24,15 @@ abstract class Action {
|
||||
this.description,
|
||||
this.parameters = const []});
|
||||
|
||||
static Tuple2<Service, String> parseServiceAndName(String rType) {
|
||||
var snake = ReCase(rType).snakeCase.split('_');
|
||||
static Service parseServiceInName(String rType) {
|
||||
var snake = rType.split('_');
|
||||
var service = snake.removeAt(0);
|
||||
return Tuple2(Service.factory(service),
|
||||
ReCase(snake.join('_')).titleCase);
|
||||
return Service.factory(service);
|
||||
}
|
||||
|
||||
static String getType(Service service, String aName) {
|
||||
String serviceName = ReCase(service.name).pascalCase;
|
||||
String actionName = ReCase(aName).pascalCase;
|
||||
return "$serviceName$actionName";
|
||||
String displayName() {
|
||||
var words = name.split('_');
|
||||
words.removeAt(0);
|
||||
return ReCase(words.join()).titleCase;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import 'package:aeris/src/models/action.dart' as aeris_action;
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:aeris/src/models/reaction.dart';
|
||||
import 'package:aeris/src/models/trigger.dart';
|
||||
@@ -51,7 +50,7 @@ class Pipeline {
|
||||
"action": {
|
||||
"id": id,
|
||||
"name": name,
|
||||
"pType": aeris_action.Action.getType(trigger.service, trigger.name),
|
||||
"pType": trigger.name,
|
||||
"pParams": { for (var e in trigger.parameters) e.name : e.value }, ///Serialize
|
||||
"enabled": enabled,
|
||||
"lastTrigger": trigger.last?.toIso8601String(),
|
||||
|
||||
@@ -4,7 +4,6 @@ import 'package:aeris/src/models/action.dart' as aeris_action;
|
||||
import 'package:aeris/src/models/action_parameter.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:aeris/src/models/service.dart';
|
||||
import 'package:tuple/tuple.dart';
|
||||
|
||||
///Object representation of a reaction
|
||||
class Reaction extends aeris_action.Action {
|
||||
@@ -21,17 +20,16 @@ class Reaction extends aeris_action.Action {
|
||||
|
||||
static Reaction fromJSON(Object reaction) {
|
||||
var reactionJSON = reaction as Map<String, dynamic>;
|
||||
Tuple2<Service, String> service = aeris_action.Action.parseServiceAndName(
|
||||
reactionJSON['rType'] as String);
|
||||
var service = aeris_action.Action.parseServiceInName(reactionJSON['rType'] as String);
|
||||
return Reaction(
|
||||
service: service.item1,
|
||||
name: service.item2,
|
||||
service: service,
|
||||
name: reactionJSON['rType'] as String,
|
||||
parameters: ActionParameter.fromJSON((reactionJSON['rParams'] as Map<String, dynamic>)));
|
||||
}
|
||||
|
||||
/// Serialize Reaction to JSON
|
||||
Object toJSON() => {
|
||||
"rType": aeris_action.Action.getType(service, name),
|
||||
"rType": name,
|
||||
"rParams": { for (var e in parameters) e.name : e.value }
|
||||
};
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ class Service {
|
||||
logoUrl =
|
||||
"https://www.presse-citron.net/app/uploads/2020/06/spotify-une-.jpg";
|
||||
const Service.anilist()
|
||||
: name = "AniList",
|
||||
: name = "Anilist",
|
||||
url = "https://anilist.co",
|
||||
logoUrl =
|
||||
"https://anilist.co/img/icons/android-chrome-512x512.png";
|
||||
@@ -50,7 +50,7 @@ class Service {
|
||||
logoUrl =
|
||||
"https://f.hellowork.com/blogdumoderateur/2019/11/twitter-logo-1200x1200.jpg";
|
||||
const Service.github()
|
||||
: name = "GitHub",
|
||||
: name = "Github",
|
||||
url = "https://github.com/",
|
||||
logoUrl = "https://avatars.githubusercontent.com/u/9919?s=280&v=4";
|
||||
const Service.youtube()
|
||||
|
||||
@@ -6,7 +6,6 @@ import 'package:aeris/main.dart';
|
||||
import 'package:aeris/src/models/service.dart';
|
||||
import 'package:aeris/src/models/action.dart' as aeris_action;
|
||||
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
||||
import 'package:tuple/tuple.dart';
|
||||
|
||||
///Object representation of a pipeline trigger
|
||||
class Trigger extends aeris_action.Action {
|
||||
@@ -23,16 +22,16 @@ class Trigger extends aeris_action.Action {
|
||||
/// Unserialize
|
||||
static Trigger fromJSON(Object action) {
|
||||
var triggerJSON = action as Map<String, dynamic>;
|
||||
Tuple2<Service, String> service =
|
||||
aeris_action.Action.parseServiceAndName(triggerJSON['pType'] as String);
|
||||
Service service =
|
||||
aeris_action.Action.parseServiceInName(triggerJSON['pType'] as String);
|
||||
var lastTriggerField = action['lastTrigger'];
|
||||
DateTime? last = lastTriggerField == null
|
||||
? null
|
||||
: DateTime.parse(lastTriggerField as String);
|
||||
|
||||
return Trigger(
|
||||
service: service.item1,
|
||||
name: service.item2,
|
||||
service: service,
|
||||
name: triggerJSON['pType'] as String,
|
||||
last: last,
|
||||
parameters: ActionParameter.fromJSON((triggerJSON['pParams'] as Map<String, dynamic>))
|
||||
);
|
||||
|
||||
@@ -14,12 +14,19 @@ class ActionCatalogueProvider extends ChangeNotifier {
|
||||
Map<Service, List<ActionTemplate>> get reactionTemplates =>
|
||||
_reactionTemplates;
|
||||
|
||||
String removeServiceFromAName(String aName) {
|
||||
var words = aName.split('_');
|
||||
words.removeAt(0);
|
||||
return words.join();
|
||||
}
|
||||
|
||||
void reloadCatalogue() {
|
||||
_triggerTemplates.clear();
|
||||
_reactionTemplates.clear();
|
||||
Service.all().forEach((element) {
|
||||
_triggerTemplates.putIfAbsent(element, () => []);
|
||||
_reactionTemplates.putIfAbsent(element, () => []);
|
||||
});
|
||||
notifyListeners();
|
||||
GetIt.I<AerisAPI>().getAbout().then((about) {
|
||||
if (about.isEmpty || about == null) return;
|
||||
final services = (about['server'] as Map<String, dynamic>)['services'] as List<dynamic>;
|
||||
|
||||
Reference in New Issue
Block a user