mirror of
https://github.com/simon-ding/polaris.git
synced 2026-06-10 03:57:39 +08:00
feat: support push notification clients
This commit is contained in:
@@ -33,6 +33,10 @@ class APIs {
|
||||
static final logFilesUrl = "$_baseUrl/api/v1/setting/logfiles";
|
||||
static final aboutUrl = "$_baseUrl/api/v1/setting/about";
|
||||
|
||||
static final notifierAllUrl = "$_baseUrl/api/v1/notifier/all";
|
||||
static final notifierDeleteUrl = "$_baseUrl/api/v1/notifier/id/";
|
||||
static final notifierAddUrl = "$_baseUrl/api/v1/notifier/add/";
|
||||
|
||||
static final tmdbImgBaseUrl = "$_baseUrl/api/v1/posters";
|
||||
|
||||
static const tmdbApiKey = "tmdb_api_key";
|
||||
|
||||
75
ui/lib/providers/notifier.dart
Normal file
75
ui/lib/providers/notifier.dart
Normal file
@@ -0,0 +1,75 @@
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:ui/providers/APIs.dart';
|
||||
import 'package:ui/providers/server_response.dart';
|
||||
|
||||
final notifiersDataProvider =
|
||||
AsyncNotifierProvider.autoDispose<NotifiersData, List<NotifierData>>(
|
||||
NotifiersData.new);
|
||||
|
||||
class NotifierData {
|
||||
int? id;
|
||||
String? name;
|
||||
String? service;
|
||||
Map<String, dynamic>? settings;
|
||||
bool? enabled;
|
||||
|
||||
NotifierData({this.id, this.name, this.service, this.enabled, this.settings});
|
||||
|
||||
factory NotifierData.fromJson(Map<String, dynamic> json) {
|
||||
return NotifierData(
|
||||
id: json["id"],
|
||||
name: json["name"],
|
||||
service: json["service"],
|
||||
enabled: json["enabled"] ?? true,
|
||||
settings: json["settings"]);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
final data = <String, dynamic>{};
|
||||
data["name"] = name;
|
||||
data["service"] = service;
|
||||
data["enabled"] = enabled;
|
||||
|
||||
data["settings"] = jsonEncode(settings);
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
class NotifiersData extends AutoDisposeAsyncNotifier<List<NotifierData>> {
|
||||
@override
|
||||
FutureOr<List<NotifierData>> build() async {
|
||||
final dio = APIs.getDio();
|
||||
final resp = await dio.get(APIs.notifierAllUrl);
|
||||
final sp = ServerResponse.fromJson(resp.data);
|
||||
if (sp.code != 0) {
|
||||
throw sp.message;
|
||||
}
|
||||
|
||||
return sp.data == null
|
||||
? List.empty()
|
||||
: (sp.data as List).map((e) => NotifierData.fromJson(e)).toList();
|
||||
}
|
||||
|
||||
Future<void> delete(int id) async {
|
||||
final dio = APIs.getDio();
|
||||
final resp = await dio.delete(APIs.notifierDeleteUrl + id.toString());
|
||||
final sp = ServerResponse.fromJson(resp.data);
|
||||
if (sp.code != 0) {
|
||||
throw sp.message;
|
||||
}
|
||||
ref.invalidateSelf();
|
||||
}
|
||||
|
||||
Future<void> add(NotifierData n) async {
|
||||
final dio = APIs.getDio();
|
||||
final resp = await dio.post(APIs.notifierAddUrl, data: n.toJson());
|
||||
final sp = ServerResponse.fromJson(resp.data);
|
||||
if (sp.code != 0) {
|
||||
throw sp.message;
|
||||
}
|
||||
ref.invalidateSelf();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user