60 lines
1.4 KiB
Dart
60 lines
1.4 KiB
Dart
|
import 'dart:convert';
|
||
|
|
||
|
import 'package:http/http.dart';
|
||
|
import 'package:loris/global.dart' as global;
|
||
|
|
||
|
class InstanceInformation {
|
||
|
final InstanceConfiguration configuration;
|
||
|
|
||
|
InstanceInformation(this.configuration);
|
||
|
static InstanceInformation fromJson(Map<String, dynamic> json) {
|
||
|
return InstanceInformation(
|
||
|
InstanceConfiguration.fromJson(
|
||
|
json["configuration"],
|
||
|
),
|
||
|
);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
class InstanceConfiguration {
|
||
|
final StatusConfiguration statusconfig;
|
||
|
|
||
|
InstanceConfiguration(this.statusconfig);
|
||
|
static InstanceConfiguration fromJson(Map<String, dynamic> json) {
|
||
|
return InstanceConfiguration(
|
||
|
StatusConfiguration.fromJson(json["statuses"]),
|
||
|
);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
class StatusConfiguration {
|
||
|
final int maxChars;
|
||
|
|
||
|
StatusConfiguration(this.maxChars);
|
||
|
static StatusConfiguration fromJson(Map<String, dynamic> json) {
|
||
|
return StatusConfiguration(
|
||
|
json["max_characters"],
|
||
|
);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
Future<Map<int, InstanceInformation?>> instanceInformationForIdentity(
|
||
|
String id,
|
||
|
) async {
|
||
|
final Uri url = Uri(
|
||
|
scheme: "https",
|
||
|
host: global.settings!.identities[id]!.instanceUrl,
|
||
|
path: "/api/v1/instance",
|
||
|
);
|
||
|
final response = await get(
|
||
|
url,
|
||
|
headers: global.defaultHeaders,
|
||
|
);
|
||
|
if (response.statusCode != 200) {
|
||
|
return {response.statusCode: null};
|
||
|
}
|
||
|
return {
|
||
|
response.statusCode: InstanceInformation.fromJson(jsonDecode(response.body))
|
||
|
};
|
||
|
}
|