Merge branch 'mime-refactor-use-mime' into 'master'

Use mime instead of mime_type

See merge request famedly/famedlysdk!368
This commit is contained in:
Christian Pauly 2020-06-26 07:54:55 +00:00
commit ab812e0da2
4 changed files with 10 additions and 17 deletions

View file

@ -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 = <String, String>{};
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';

View file

@ -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 = <String, dynamic>{
'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;

View file

@ -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:

View file

@ -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