62 lines
1.5 KiB
Dart
62 lines
1.5 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;
|
|
final int maxMediaAttachments;
|
|
|
|
StatusConfiguration(this.maxChars, this.maxMediaAttachments);
|
|
static StatusConfiguration fromJson(Map<String, dynamic> json) {
|
|
return StatusConfiguration(
|
|
json["max_characters"],
|
|
json["max_media_attachments"],
|
|
);
|
|
}
|
|
}
|
|
|
|
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))
|
|
};
|
|
}
|