Skip to content

Commit

Permalink
feat(sabnzbd): rewrite SABnzbd API interface
Browse files Browse the repository at this point in the history
[skip ci]
  • Loading branch information
JagandeepBrar committed Sep 3, 2022
1 parent 2adfe59 commit a1b736a
Show file tree
Hide file tree
Showing 30 changed files with 958 additions and 1 deletion.
24 changes: 24 additions & 0 deletions assets/localization/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,30 @@
"radarr.Wanted": "Wanted",
"radarr.Weight": "Weight",
"radarr.Year": "Year",
"sabnzbd.Age": "Age",
"sabnzbd.All": "All",
"sabnzbd.Ascending": "Ascending",
"sabnzbd.CategoryDefault": "Category Default",
"sabnzbd.Completed": "Completed",
"sabnzbd.Descending": "Descending",
"sabnzbd.Duplicate": "Duplicate",
"sabnzbd.Failed": "Failed",
"sabnzbd.Force": "Force",
"sabnzbd.HibernatePC": "Hibernate PC",
"sabnzbd.High": "High",
"sabnzbd.Low": "Low",
"sabnzbd.Name": "Name",
"sabnzbd.None": "None",
"sabnzbd.Normal": "Normal",
"sabnzbd.Paused": "Paused",
"sabnzbd.Repair": "Repair",
"sabnzbd.RepairUnpack": "Repair/Unpack",
"sabnzbd.RepairUnpackDelete": "Repair/Unpack/Delete",
"sabnzbd.Size": "Size",
"sabnzbd.ShutdownPC": "Shutdown PC",
"sabnzbd.ShutdownSABnzbd": "Shutdown SABnzbd",
"sabnzbd.StandbyPC": "Standby PC",
"sabnzbd.Stop": "Stop",
"search.Age": "Age",
"search.AllSubcategories": "All Subcategories",
"search.Alphabetical": "Alphabetical",
Expand Down
15 changes: 15 additions & 0 deletions lib/api/sabnzbd/extensions/types/clear_history.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import 'package:lunasea/api/sabnzbd/types/clear_history.dart';
import 'package:lunasea/vendor.dart';

extension SABnzbdClearHistoryExtension on SABnzbdClearHistory {
String get readable {
switch (this) {
case SABnzbdClearHistory.ALL:
return 'sabnzbd.All'.tr();
case SABnzbdClearHistory.COMPLETED:
return 'sabnzbd.Completed'.tr();
case SABnzbdClearHistory.FAILED:
return 'sabnzbd.Failed'.tr();
}
}
}
19 changes: 19 additions & 0 deletions lib/api/sabnzbd/extensions/types/on_complete_action.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import 'package:lunasea/api/sabnzbd/types/on_complete_action.dart';
import 'package:lunasea/vendor.dart';

extension SABnzbdOnCompleteActionExtension on SABnzbdOnCompleteAction {
String get readable {
switch (this) {
case SABnzbdOnCompleteAction.SHUTDOWN_PROGRAM:
return 'sabnzbd.ShutdownSABnzbd'.tr();
case SABnzbdOnCompleteAction.SHUTDOWN_PC:
return 'sabnzbd.ShutdownPC'.tr();
case SABnzbdOnCompleteAction.HIBERNATE_PC:
return 'sabnzbd.HibernatePC'.tr();
case SABnzbdOnCompleteAction.STANDBY_PC:
return 'sabnzbd.StandbyPC'.tr();
case SABnzbdOnCompleteAction.NONE:
return 'sabnzbd.None'.tr();
}
}
}
19 changes: 19 additions & 0 deletions lib/api/sabnzbd/extensions/types/post_processing.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import 'package:lunasea/api/sabnzbd/types/post_processing.dart';
import 'package:lunasea/vendor.dart';

extension SABnzbdPostProcessingExtension on SABnzbdPostProcessing {
String get readable {
switch (this) {
case SABnzbdPostProcessing.DEFAULT:
return 'sabnzbd.CategoryDefault'.tr();
case SABnzbdPostProcessing.NONE:
return 'sabnzbd.None'.tr();
case SABnzbdPostProcessing.REPAIR:
return 'sabnzbd.Repair'.tr();
case SABnzbdPostProcessing.REPAIR_UNPACK:
return 'sabnzbd.RepairUnpack'.tr();
case SABnzbdPostProcessing.REPAIR_UNPACK_DELETE:
return 'sabnzbd.RepairUnpackDelete'.tr();
}
}
}
25 changes: 25 additions & 0 deletions lib/api/sabnzbd/extensions/types/priority.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import 'package:lunasea/api/sabnzbd/types/priority.dart';
import 'package:lunasea/vendor.dart';

extension SABnzbdPriorityExtension on SABnzbdPriority {
String get readable {
switch (this) {
case SABnzbdPriority.FORCE:
return 'sabnzbd.Force'.tr();
case SABnzbdPriority.HIGH:
return 'sabnzbd.High'.tr();
case SABnzbdPriority.NORMAL:
return 'sabnzbd.Normal'.tr();
case SABnzbdPriority.LOW:
return 'sabnzbd.Low'.tr();
case SABnzbdPriority.STOP:
return 'sabnzbd.Stop'.tr();
case SABnzbdPriority.DEFAULT:
return 'sabnzbd.CategoryDefault'.tr();
case SABnzbdPriority.PAUSED:
return 'sabnzbd.Paused'.tr();
case SABnzbdPriority.DUPLICATE:
return 'sabnzbd.Duplicate'.tr();
}
}
}
15 changes: 15 additions & 0 deletions lib/api/sabnzbd/extensions/types/sort_category.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import 'package:lunasea/api/sabnzbd/types/sort_category.dart';
import 'package:lunasea/vendor.dart';

extension SABnzbdSortCategoryExtension on SABnzbdSortCategory {
String get readable {
switch (this) {
case SABnzbdSortCategory.AGE:
return 'sabnzbd.Age'.tr();
case SABnzbdSortCategory.NAME:
return 'sabnzbd.Name'.tr();
case SABnzbdSortCategory.SIZE:
return 'sabnzbd.Size'.tr();
}
}
}
13 changes: 13 additions & 0 deletions lib/api/sabnzbd/extensions/types/sort_direction.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import 'package:lunasea/api/sabnzbd/types/sort_direction.dart';
import 'package:lunasea/vendor.dart';

extension SABnzbdSortDirectionExtension on SABnzbdSortDirection {
String get readable {
switch (this) {
case SABnzbdSortDirection.ASCENDING:
return 'sabnzbd.Ascending'.tr();
case SABnzbdSortDirection.DESCENDING:
return 'sabnzbd.Descending'.tr();
}
}
}
9 changes: 9 additions & 0 deletions lib/api/sabnzbd/models.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export 'models/action_result.dart';
export 'models/categories.dart';
export 'models/history.dart';
export 'models/queue.dart';
export 'models/server.dart';
export 'models/server_stats.dart';
export 'models/stage_log.dart';
export 'models/status.dart';
export 'models/version.dart';
24 changes: 24 additions & 0 deletions lib/api/sabnzbd/models/action_result.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import 'dart:convert';
import 'package:json_annotation/json_annotation.dart';

part 'action_result.g.dart';

@JsonSerializable(explicitToJson: true, includeIfNull: false)
class SABnzbdActionResult {
bool status;

SABnzbdActionResult({
required this.status,
});

@override
String toString() => json.encode(this.toJson());

factory SABnzbdActionResult.fromJson(Map<String, dynamic> json) {
return _$SABnzbdActionResultFromJson(json);
}

Map<String, dynamic> toJson() {
return _$SABnzbdActionResultToJson(this);
}
}
24 changes: 24 additions & 0 deletions lib/api/sabnzbd/models/categories.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import 'dart:convert';
import 'package:json_annotation/json_annotation.dart';

part 'categories.g.dart';

@JsonSerializable(explicitToJson: true, includeIfNull: false)
class SABnzbdCategories {
List<String> categories;

SABnzbdCategories({
required this.categories,
});

@override
String toString() => json.encode(this.toJson());

factory SABnzbdCategories.fromJson(Map<String, dynamic> json) {
return _$SABnzbdCategoriesFromJson(json);
}

Map<String, dynamic> toJson() {
return _$SABnzbdCategoriesToJson(this);
}
}
117 changes: 117 additions & 0 deletions lib/api/sabnzbd/models/history.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
import 'dart:convert';
import 'package:json_annotation/json_annotation.dart';
import 'package:lunasea/api/sabnzbd/models.dart';

part 'history.g.dart';

@JsonSerializable(explicitToJson: true, includeIfNull: false)
class SABnzbdHistory {
SABnzbdHistoryResult history;

SABnzbdHistory({
required this.history,
});

@override
String toString() => json.encode(this.toJson());

factory SABnzbdHistory.fromJson(Map<String, dynamic> json) {
return _$SABnzbdHistoryFromJson(json);
}

Map<String, dynamic> toJson() {
return _$SABnzbdHistoryToJson(this);
}
}

@JsonSerializable(explicitToJson: true, includeIfNull: false)
class SABnzbdHistoryResult {
List<SABnzbdHistorySlot> slots;

@JsonKey(name: 'day_size')
String dailySize;

@JsonKey(name: 'week_size')
String weeklySize;

@JsonKey(name: 'month_size')
String monthlySize;

@JsonKey(name: 'total_size')
String totalSize;

SABnzbdHistoryResult({
required this.slots,
required this.dailySize,
required this.weeklySize,
required this.monthlySize,
required this.totalSize,
});

@override
String toString() => json.encode(this.toJson());

factory SABnzbdHistoryResult.fromJson(Map<String, dynamic> json) {
return _$SABnzbdHistoryResultFromJson(json);
}

Map<String, dynamic> toJson() {
return _$SABnzbdHistoryResultToJson(this);
}
}

@JsonSerializable(explicitToJson: true, includeIfNull: false)
class SABnzbdHistorySlot {
String name;
String status;
String script;
String category;
String storage;

@JsonKey(name: 'completed')
int timestamp;

@JsonKey(name: 'nzo_id')
String nzoId;

@JsonKey(name: 'bytes')
int size;

@JsonKey(name: 'fail_message')
String failMessage;

@JsonKey(name: 'action_line')
String actionLine;

@JsonKey(name: 'download_time')
int downloadTime;

@JsonKey(name: 'stage_log')
List<SABnzbdStageLog> stageLog;

SABnzbdHistorySlot({
required this.name,
required this.status,
required this.script,
required this.category,
required this.nzoId,
required this.size,
required this.failMessage,
required this.timestamp,
required this.actionLine,
required this.downloadTime,
required this.stageLog,
required this.storage,
});

@override
String toString() => json.encode(this.toJson());

factory SABnzbdHistorySlot.fromJson(Map<String, dynamic> json) {
return _$SABnzbdHistorySlotFromJson(json);
}

Map<String, dynamic> toJson() {
return _$SABnzbdHistorySlotToJson(this);
}
}
Loading

0 comments on commit a1b736a

Please sign in to comment.