From 186974ba95321f868fff30fa2a29da278f2aea87 Mon Sep 17 00:00:00 2001 From: sorairo Date: Sun, 8 Oct 2023 18:11:41 +0900 Subject: [PATCH] =?UTF-8?q?#375=20=E5=AF=BE=E5=BF=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../note_create_state_notifier.dart | 17 +++++++++- pubspec.lock | 32 +++++++++++++++++++ pubspec.yaml | 1 + 3 files changed, 49 insertions(+), 1 deletion(-) diff --git a/lib/state_notifier/note_create_page/note_create_state_notifier.dart b/lib/state_notifier/note_create_page/note_create_state_notifier.dart index 3323139ee..d90c7216b 100644 --- a/lib/state_notifier/note_create_page/note_create_state_notifier.dart +++ b/lib/state_notifier/note_create_page/note_create_state_notifier.dart @@ -4,6 +4,7 @@ import 'package:dio/dio.dart'; import 'package:file/file.dart'; import 'package:file_picker/file_picker.dart'; import 'package:flutter/material.dart'; +import 'package:flutter_image_compress/flutter_image_compress.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:freezed_annotation/freezed_annotation.dart'; import 'package:mfm_parser/mfm_parser.dart'; @@ -283,6 +284,20 @@ class NoteCreateNotifier extends StateNotifier { for (final file in state.files) { switch (file) { case ImageFile(): + final fileName = file.fileName.toLowerCase(); + var imageData = file.data; + try { + if (fileName.endsWith("jpg") || + fileName.endsWith("jpeg") || + fileName.endsWith("tiff") || + fileName.endsWith("tif")) { + imageData = + await FlutterImageCompress.compressWithList(file.data); + } + } catch (e) { + print("failed to compress file"); + } + final response = await misskey.drive.files.createAsBinary( DriveFilesCreateRequest( force: true, @@ -290,7 +305,7 @@ class NoteCreateNotifier extends StateNotifier { isSensitive: file.isNsfw, comment: file.caption, ), - file.data, + imageData, ); fileIds.add(response.id); diff --git a/pubspec.lock b/pubspec.lock index 178a45be2..6e12bebac 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -406,6 +406,38 @@ packages: url: "https://pub.dev" source: hosted version: "3.0.0-alpha.6" + flutter_image_compress: + dependency: "direct main" + description: + name: flutter_image_compress + sha256: "2725cce5c58fdeaf1db8f4203688228bb67e3523a66305ccaa6f99071beb6dc2" + url: "https://pub.dev" + source: hosted + version: "2.0.4" + flutter_image_compress_common: + dependency: transitive + description: + name: flutter_image_compress_common + sha256: "8e7299afe109dc4b97fda34bf0f4967cc1fc10bc8050c374d449cab262d095b3" + url: "https://pub.dev" + source: hosted + version: "1.0.2" + flutter_image_compress_platform_interface: + dependency: transitive + description: + name: flutter_image_compress_platform_interface + sha256: "3c7e86da7540b1adfa919b461885a41a018d4a26544d0fcbeaa769f6542e603d" + url: "https://pub.dev" + source: hosted + version: "1.0.2" + flutter_image_compress_web: + dependency: transitive + description: + name: flutter_image_compress_web + sha256: e879189dc7f246dcf8f06c07ee849231341508bf51e8ed7d5dcbe778ddde0e81 + url: "https://pub.dev" + source: hosted + version: "0.1.3+1" flutter_launcher_icons: dependency: "direct dev" description: diff --git a/pubspec.yaml b/pubspec.yaml index 6560ee335..22228919d 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -59,6 +59,7 @@ dependencies: colorfilter_generator: ^0.0.8 matrix2d: ^1.0.4 twemoji_v2: ^0.5.3 + flutter_image_compress: ^2.0.4 dependency_overrides: image_editor: