Fix Resonite Essentials folder failing to open

Closes #5
This commit is contained in:
Nutcake 2023-11-01 15:10:43 +01:00
parent 2981db0d17
commit f9d014c047
4 changed files with 38 additions and 27 deletions

View file

@ -24,6 +24,13 @@ class RecordApi {
return Record.fromMap(body);
}
static Future<Record> getGroupRecordByPath(ApiClient client, {required String path, required String groupId}) async {
final response = await client.get("/groups/$groupId/records/$path");
client.checkResponse(response);
final body = jsonDecode(response.body) as Map;
return Record.fromMap(body);
}
static Future<List<Record>> getUserRecordsAt(ApiClient client, {required String path, String? user}) async {
final response = await client.get(Uri.encodeFull("/users/${user ?? client.userId}/records?path=$path"));
client.checkResponse(response);
@ -32,7 +39,7 @@ class RecordApi {
}
static Future<List<Record>> getGroupRecordsAt(ApiClient client, {required String path, required String groupId}) async {
final response = await client.get("/users/$groupId/records?path=$path");
final response = await client.get("/groups/$groupId/records?path=$path");
client.checkResponse(response);
final body = jsonDecode(response.body) as List;
return body.map((e) => Record.fromMap(e)).toList();

View file

@ -63,7 +63,8 @@ class InventoryClient extends ChangeNotifier {
Future<ResoniteDirectory>? get directoryFuture => _currentDirectory?.then(
(ResoniteDirectory value) {
value.children.sort(
(ResoniteDirectory a, ResoniteDirectory b) => _sortMode.sortFunction(a.record, b.record, reverse: _sortReverse),
(ResoniteDirectory a, ResoniteDirectory b) =>
_sortMode.sortFunction(a.record, b.record, reverse: _sortReverse),
);
return value;
},
@ -113,10 +114,29 @@ class InventoryClient extends ChangeNotifier {
);
} else {
if (record.recordType == RecordType.link) {
final linkRecord =
await RecordApi.getUserRecord(apiClient, recordId: record.linkRecordId, user: record.linkOwnerId);
records = await RecordApi.getUserRecordsAt(apiClient,
path: "${linkRecord.path}\\${linkRecord.name}", user: linkRecord.ownerId);
if (record.isGroupRecord) {
final linkRecord = await RecordApi.getGroupRecordByPath(
apiClient,
path: "root/${record.path}/${record.name}",
groupId: record.linkOwnerId,
);
records = await RecordApi.getGroupRecordsAt(
apiClient,
path: "${linkRecord.path}\\${linkRecord.name}",
groupId: linkRecord.ownerId,
);
} else {
final linkRecord = await RecordApi.getUserRecord(
apiClient,
recordId: record.linkRecordId,
user: record.linkOwnerId,
);
records = await RecordApi.getUserRecordsAt(
apiClient,
path: "${linkRecord.path}\\${linkRecord.name}",
user: linkRecord.ownerId,
);
}
} else {
records =
await RecordApi.getUserRecordsAt(apiClient, path: "${record.path}\\${record.name}", user: record.ownerId);

View file

@ -222,6 +222,8 @@ class Record {
bool get isItem => assetUri.startsWith("resdb");
bool get isGroupRecord => linkOwnerId.startsWith("G-");
String get linkRecordId {
if (!isLink) {
throw "Record is not a link.";
@ -242,12 +244,12 @@ class Record {
String ownerId = assetUri.replaceFirst("resrec:///", "");
final lastSlashIdx = ownerId.lastIndexOf("/");
if (lastSlashIdx == -1) {
final nextSlashIdx = ownerId.indexOf("/");
if (nextSlashIdx == -1) {
throw "Record has invalid assetUri";
}
return ownerId.substring(0, lastSlashIdx);
return ownerId.substring(0, nextSlashIdx);
}
Record copyWith({

View file

@ -187,24 +187,6 @@ class _InventoryBrowserState extends State<InventoryBrowser> with AutomaticKeepA
final record = objects[index];
return ObjectInventoryTile(
record: record,
selected: iClient.isRecordSelected(record),
onTap: iClient.isAnyRecordSelected
? () async {
iClient.toggleRecordSelected(record);
}
: () async {
await Navigator.push(
context,
MaterialPageRoute(
builder: (context) => PhotoView(
minScale: PhotoViewComputedScale.contained,
imageProvider:
CachedNetworkImageProvider(Aux.resdbToHttp(record.thumbnailUri)),
heroAttributes: PhotoViewHeroAttributes(tag: record.id),
),
),
);
},
onLongPress: () async {
iClient.toggleRecordSelected(record);
},