async await??

master
Inex Code 8 months ago
parent 473828f498
commit b6b58e8895
  1. 22
      bin/server.dart

@ -75,7 +75,7 @@ Future<void> _postOnMastodon(reqJson) async {
final postText = reqJson['object']['text'] ?? '';
final attachments = reqJson['object']['attachments'] ?? [];
final photos =
attachments.where((attachment) => attachment['type'] == 'photo');
@ -103,12 +103,14 @@ Future<void> _postOnMastodon(reqJson) async {
if (photos.isEmpty) {
await dio.post('$instanceUrl/api/v1/statuses',
data: {'status': postText},
options: dio_lib.Options(headers: {'Authorization': 'Bearer $authToken'}));
options:
dio_lib.Options(headers: {'Authorization': 'Bearer $authToken'}));
} else {
final mediaResponses = await Future.wait(
photoUrls.map((photoUrl) async => dio.post('$instanceUrl/api/v1/media',
data: dio_lib.FormData.fromMap({'file': File(photoUrl)}),
options: dio_lib.Options(headers: {'Authorization': 'Bearer $authToken'}))));
final mediaResponses = await photoUrls.map((photoUrl) async => await dio.post(
'$instanceUrl/api/v1/media',
data: dio_lib.FormData.fromMap({'file': File(photoUrl)}),
options:
dio_lib.Options(headers: {'Authorization': 'Bearer $authToken'})));
final mediaIds = mediaResponses.map((mediaResponse) {
final mediaId = mediaResponse.data['id'];
@ -116,11 +118,9 @@ Future<void> _postOnMastodon(reqJson) async {
}).toList();
await dio.post('$instanceUrl/api/v1/statuses',
data: {
'status': postText,
'media_ids': mediaIds
},
options: dio_lib.Options(headers: {'Authorization': 'Bearer $authToken'}));
data: {'status': postText, 'media_ids': mediaIds},
options:
dio_lib.Options(headers: {'Authorization': 'Bearer $authToken'}));
await Future.wait(photoUrls.map((photoUrl) => File(photoUrl).delete()));
}

Loading…
Cancel
Save