From 58dcedb883583732634a9bbf17b1b6f282758b95 Mon Sep 17 00:00:00 2001 From: Lukas Lihotzki Date: Thu, 25 Jun 2020 17:35:46 +0200 Subject: [PATCH] Use mime instead of mime_type --- lib/matrix_api/matrix_api.dart | 5 +++-- lib/src/room.dart | 13 ++++++------- pubspec.lock | 7 ------- pubspec.yaml | 2 +- 4 files changed, 10 insertions(+), 17 deletions(-) diff --git a/lib/matrix_api/matrix_api.dart b/lib/matrix_api/matrix_api.dart index d0d716d..8eac0e4 100644 --- a/lib/matrix_api/matrix_api.dart +++ b/lib/matrix_api/matrix_api.dart @@ -32,7 +32,7 @@ import 'package:famedlysdk/matrix_api/model/third_party_location.dart'; import 'package:famedlysdk/matrix_api/model/timeline_history_response.dart'; import 'package:famedlysdk/matrix_api/model/user_search_result.dart'; import 'package:http/http.dart' as http; -import 'package:mime_type/mime_type.dart'; +import 'package:mime/mime.dart'; import 'package:moor/moor.dart'; import 'model/device.dart'; @@ -1326,7 +1326,8 @@ class MatrixApi { fileName = fileName.split('/').last; var headers = {}; headers['Authorization'] = 'Bearer $accessToken'; - headers['Content-Type'] = contentType ?? mime(fileName); + headers['Content-Type'] = + contentType ?? lookupMimeType(fileName, headerBytes: file); fileName = Uri.encodeQueryComponent(fileName); final url = '${homeserver.toString()}/_matrix/media/r0/upload?filename=$fileName'; diff --git a/lib/src/room.dart b/lib/src/room.dart index a6fa024..3cfe836 100644 --- a/lib/src/room.dart +++ b/lib/src/room.dart @@ -27,7 +27,7 @@ import 'package:famedlysdk/src/utils/room_update.dart'; import 'package:famedlysdk/src/utils/matrix_file.dart'; import 'package:image/image.dart'; import 'package:matrix_file_e2ee/matrix_file_e2ee.dart'; -import 'package:mime_type/mime_type.dart'; +import 'package:mime/mime.dart'; import 'package:html_unescape/html_unescape.dart'; import './user.dart'; @@ -524,7 +524,7 @@ class Room { String thumbnailUploadResp; var fileName = file.path.split('/').last; - final mimeType = mime(file.path) ?? ''; + final mimeType = lookupMimeType(file.path, headerBytes: file.bytes) ?? ''; if (msgType == null) { final metaType = (mimeType).split('/')[0]; switch (metaType) { @@ -647,7 +647,7 @@ class Room { inReplyTo: inReplyTo, info: { 'size': file.size, - 'mimetype': mime(file.path.split('/').last), + 'mimetype': lookupMimeType(file.path, headerBytes: file.bytes), 'w': width, 'h': height, }); @@ -663,10 +663,9 @@ class Room { int thumbnailWidth, int thumbnailHeight, Event inReplyTo}) async { - var fileName = file.path.split('/').last; var info = { 'size': file.size, - 'mimetype': mime(fileName), + 'mimetype': lookupMimeType(file.path, headerBytes: file.bytes), }; if (videoWidth != null) { info['w'] = videoWidth; @@ -678,7 +677,6 @@ class Room { info['duration'] = duration; } if (thumbnail != null && !(encrypted && client.encryptionEnabled)) { - var thumbnailName = file.path.split('/').last; final thumbnailUploadResp = await client.api.upload( thumbnail.bytes, thumbnail.path, @@ -686,7 +684,8 @@ class Room { info['thumbnail_url'] = thumbnailUploadResp; info['thumbnail_info'] = { 'size': thumbnail.size, - 'mimetype': mime(thumbnailName), + 'mimetype': + lookupMimeType(thumbnail.path, headerBytes: thumbnail.bytes), }; if (thumbnailWidth != null) { info['thumbnail_info']['w'] = thumbnailWidth; diff --git a/pubspec.lock b/pubspec.lock index 5c8e154..0584b3f 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -353,13 +353,6 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "0.9.6+3" - mime_type: - dependency: "direct main" - description: - name: mime_type - url: "https://pub.dartlang.org" - source: hosted - version: "0.3.0" moor: dependency: "direct main" description: diff --git a/pubspec.yaml b/pubspec.yaml index 324dcd4..9050d1d 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -9,7 +9,7 @@ environment: dependencies: http: ^0.12.1 - mime_type: ^0.3.0 + mime: ^0.9.6 canonical_json: ^1.0.0 image: ^2.1.4 markdown: ^2.1.3