mirror of
https://codeberg.org/shroff/phylum.git
synced 2026-01-09 05:00:12 -06:00
[client] Parse resource summary for edits
This commit is contained in:
@@ -3,6 +3,7 @@ import 'dart:async';
|
||||
import 'package:drift/drift.dart';
|
||||
import 'package:offtheline/offtheline.dart';
|
||||
import 'package:phylum/libphylum/phylum_account.dart';
|
||||
import 'package:phylum/libphylum/phylum_datastore.dart';
|
||||
|
||||
class ResourceMkdirAction extends ApiAction<PhylumAccount> with JsonApiAction {
|
||||
static const actionName = 'resourceMkdir';
|
||||
@@ -16,7 +17,7 @@ class ResourceMkdirAction extends ApiAction<PhylumAccount> with JsonApiAction {
|
||||
String get endpoint => '/v1/resources/mkdir/$id';
|
||||
|
||||
@override
|
||||
dynamic get tag => 'resourceDetails';
|
||||
get tag => resourceSummaryResponse;
|
||||
|
||||
final String id;
|
||||
final String parent;
|
||||
|
||||
@@ -4,6 +4,7 @@ import 'package:drift/drift.dart';
|
||||
import 'package:offtheline/offtheline.dart';
|
||||
import 'package:phylum/libphylum/db/db.dart';
|
||||
import 'package:phylum/libphylum/phylum_account.dart';
|
||||
import 'package:phylum/libphylum/phylum_datastore.dart';
|
||||
|
||||
class ResourceMoveAction extends ApiAction<PhylumAccount> with JsonApiAction {
|
||||
static const actionName = 'resourceMove';
|
||||
@@ -17,7 +18,7 @@ class ResourceMoveAction extends ApiAction<PhylumAccount> with JsonApiAction {
|
||||
String get endpoint => '/v1/resources/move/$id';
|
||||
|
||||
@override
|
||||
get tag => 'resourceDetails';
|
||||
get tag => resourceSummaryResponse;
|
||||
|
||||
final String id;
|
||||
final String parent;
|
||||
|
||||
@@ -4,6 +4,7 @@ import 'package:drift/drift.dart';
|
||||
import 'package:offtheline/offtheline.dart';
|
||||
import 'package:phylum/libphylum/db/db.dart';
|
||||
import 'package:phylum/libphylum/phylum_account.dart';
|
||||
import 'package:phylum/libphylum/phylum_datastore.dart';
|
||||
|
||||
class ResourceRenameAction extends ApiAction<PhylumAccount> with JsonApiAction {
|
||||
static const actionName = 'resourceRename';
|
||||
@@ -17,7 +18,7 @@ class ResourceRenameAction extends ApiAction<PhylumAccount> with JsonApiAction {
|
||||
String get endpoint => '/v1/resources/rename/$id';
|
||||
|
||||
@override
|
||||
get tag => 'resourceDetails';
|
||||
get tag => resourceSummaryResponse;
|
||||
|
||||
final String id;
|
||||
final String newName;
|
||||
|
||||
@@ -5,6 +5,7 @@ import 'package:drift/drift.dart';
|
||||
import 'package:http/http.dart';
|
||||
import 'package:offtheline/offtheline.dart';
|
||||
import 'package:phylum/libphylum/phylum_account.dart';
|
||||
import 'package:phylum/libphylum/phylum_datastore.dart';
|
||||
import 'package:uuid/uuid.dart';
|
||||
|
||||
class ResourceUploadAction extends ApiAction<PhylumAccount> with FileUploadApiAction {
|
||||
@@ -19,7 +20,7 @@ class ResourceUploadAction extends ApiAction<PhylumAccount> with FileUploadApiAc
|
||||
String get endpoint => '/v1/resources/upload/$id';
|
||||
|
||||
@override
|
||||
dynamic get tag => 'resourceDetails';
|
||||
get tag => resourceSummaryResponse;
|
||||
|
||||
@override
|
||||
Future<MultipartFile> get file => MultipartFile.fromPath('contents', path, filename: resourceName);
|
||||
|
||||
@@ -2,6 +2,9 @@ import 'package:drift/drift.dart';
|
||||
import 'package:offtheline/offtheline.dart';
|
||||
import 'package:phylum/libphylum/db/db.dart';
|
||||
|
||||
const resourceDetailsResponse = 'resourceDetails';
|
||||
const resourceSummaryResponse = 'resourceSummary';
|
||||
|
||||
class PhylumDatastore with AccountListener<Map<String, dynamic>> {
|
||||
late final AppDatabase db;
|
||||
|
||||
@@ -14,26 +17,29 @@ class PhylumDatastore with AccountListener<Map<String, dynamic>> {
|
||||
|
||||
Future<void> processResponse(Map<String, dynamic>? data, dynamic tag) async {
|
||||
switch (tag) {
|
||||
case "resourceDetails":
|
||||
case resourceDetailsResponse:
|
||||
parseResourceDetails(data!);
|
||||
break;
|
||||
case resourceSummaryResponse:
|
||||
parseResourceSummary(data!);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Future parseResourceDetails(Map<String, dynamic> data) async {
|
||||
final details = parseResourceMetadata(data['metadata']);
|
||||
final details = parseResourceSummary(data['metadata']);
|
||||
final existing = Set.from(await db.managers.resources.filter((f) => f.parent.id.equals(data['metadata']['id'])).map((r) => r.id).get());
|
||||
final children = data.containsKey('children')
|
||||
? (data['children'] as List).cast<Map>().map((c) {
|
||||
existing.remove(c['id']);
|
||||
return parseResourceMetadata(c.cast<String, dynamic>());
|
||||
return parseResourceSummary(c.cast<String, dynamic>());
|
||||
})
|
||||
: <ResourcesCompanion>[];
|
||||
await db.resources.deleteWhere((o) => o.id.isIn(List.from(existing)));
|
||||
return db.insertResources([details, ...children]);
|
||||
}
|
||||
|
||||
ResourcesCompanion parseResourceMetadata(Map<String, dynamic> data) {
|
||||
ResourcesCompanion parseResourceSummary(Map<String, dynamic> data) {
|
||||
return ResourcesCompanion.insert(
|
||||
id: data['id'],
|
||||
parent: Value(data['parent']),
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
import 'package:http/http.dart';
|
||||
import 'package:offtheline/offtheline.dart';
|
||||
import 'package:phylum/libphylum/phylum_datastore.dart';
|
||||
|
||||
class ResourceDetailRequest extends ApiRequest {
|
||||
@override
|
||||
get tag => "resourceDetails";
|
||||
get tag => resourceDetailsResponse;
|
||||
|
||||
final String resourceId;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user