Skip to content

Bring projects, wikis, and teams together with AI. AppFlowy is the AI collaborative workspace where you achieve more without losing control of your data. The leading open source Notion alternative.

chore: restrict uploadable image types (#7269)

Richard Shiuea79f825ff198
diff --git a/frontend/appflowy_flutter/lib/plugins/ai_chat/presentation/message/ai_message_action_bar.dart b/frontend/appflowy_flutter/lib/plugins/ai_chat/presentation/message/ai_message_action_bar.dart
index cf20fb2742..7ae4a11f19 100644
--- a/frontend/appflowy_flutter/lib/plugins/ai_chat/presentation/message/ai_message_action_bar.dart
+++ b/frontend/appflowy_flutter/lib/plugins/ai_chat/presentation/message/ai_message_action_bar.dart
@@ -165,13 +165,14 @@ class CopyButton extends StatelessWidget {
size: const Size.square(16),
),
onPressed: () async {
+ final messageText = textMessage.text.trim();
final document = customMarkdownToDocument(
- textMessage.text,
+ messageText,
tableWidth: 250.0,
);
await getIt<ClipboardService>().setData(
ClipboardServiceData(
- plainText: _getTrimmedPlainText(textMessage.text),
+ plainText: _stripMarkdownIfNecessary(messageText),
inAppJson: jsonEncode(document.toJson()),
),
);
@@ -186,9 +187,10 @@ class CopyButton extends StatelessWidget {
);
}
- String _getTrimmedPlainText(String plainText) {
+ String _stripMarkdownIfNecessary(String plainText) {
// match and capture inner url as group
final matches = singleLineMarkdownImageRegex.allMatches(plainText);
+
if (matches.length != 1) {
return plainText;
}
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/copy_and_paste/custom_paste_command.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/copy_and_paste/custom_paste_command.dart
index 06ccf9aae5..c523453fba 100644
--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/copy_and_paste/custom_paste_command.dart
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/copy_and_paste/custom_paste_command.dart
@@ -8,6 +8,7 @@ import 'package:appflowy/plugins/document/presentation/editor_plugins/copy_and_p
import 'package:appflowy/plugins/document/presentation/editor_plugins/copy_and_paste/paste_from_plain_text.dart';
import 'package:appflowy/shared/clipboard_state.dart';
import 'package:appflowy/startup/startup.dart';
+import 'package:appflowy/util/default_extensions.dart';
import 'package:appflowy_backend/log.dart';
import 'package:appflowy_editor/appflowy_editor.dart';
import 'package:appflowy_editor_plugins/appflowy_editor_plugins.dart';
@@ -247,7 +248,8 @@ Future<bool> _isImageUrl(String text) async {
if (response.statusCode == 200) {
final contentType = response.headers['content-type'];
if (contentType != null) {
- return contentType.startsWith('image/');
+ return contentType.startsWith('image/') &&
+ defaultImageExtensions.any(contentType.contains);
}
}
diff --git a/frontend/appflowy_flutter/lib/util/default_extensions.dart b/frontend/appflowy_flutter/lib/util/default_extensions.dart
index d0d36d2698..36bbdcb6b4 100644
--- a/frontend/appflowy_flutter/lib/util/default_extensions.dart
+++ b/frontend/appflowy_flutter/lib/util/default_extensions.dart
@@ -13,13 +13,3 @@ const List<String> defaultImageExtensions = [
'webp',
'bmp',
];
-
-extension ImageStringExtension on String {
- bool isImageUrl() {
- final imagePattern = RegExp(
- r'\.(jpe?g|png|gif|webp|bmp)$',
- caseSensitive: false,
- );
- return imagePattern.hasMatch(this);
- }
-}