mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
chore: set document id (#5585)
* chore: set document id * feat: set document id to upload image api * chore: fmt --------- Co-authored-by: Lucas.Xu <lucas.xu@appflowy.io>
This commit is contained in:
parent
bf2a00b133
commit
6b1e7b6ac8
@ -1,3 +1,4 @@
|
|||||||
|
import 'package:appflowy/plugins/document/application/prelude.dart';
|
||||||
import 'package:appflowy/plugins/document/presentation/editor_plugins/copy_and_paste/clipboard_service.dart';
|
import 'package:appflowy/plugins/document/presentation/editor_plugins/copy_and_paste/clipboard_service.dart';
|
||||||
import 'package:appflowy/plugins/document/presentation/editor_plugins/copy_and_paste/editor_state_paste_node_extension.dart';
|
import 'package:appflowy/plugins/document/presentation/editor_plugins/copy_and_paste/editor_state_paste_node_extension.dart';
|
||||||
import 'package:appflowy/plugins/document/presentation/editor_plugins/copy_and_paste/paste_from_html.dart';
|
import 'package:appflowy/plugins/document/presentation/editor_plugins/copy_and_paste/paste_from_html.dart';
|
||||||
@ -8,6 +9,7 @@ import 'package:appflowy/startup/startup.dart';
|
|||||||
import 'package:appflowy_editor/appflowy_editor.dart';
|
import 'package:appflowy_editor/appflowy_editor.dart';
|
||||||
import 'package:appflowy_editor_plugins/appflowy_editor_plugins.dart';
|
import 'package:appflowy_editor_plugins/appflowy_editor_plugins.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:string_validator/string_validator.dart';
|
import 'package:string_validator/string_validator.dart';
|
||||||
|
|
||||||
/// Paste.
|
/// Paste.
|
||||||
@ -70,8 +72,18 @@ CommandShortcutEventHandler _pasteCommandHandler = (editorState) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (image != null && image.$2?.isNotEmpty == true) {
|
if (image != null && image.$2?.isNotEmpty == true) {
|
||||||
|
final documentBloc =
|
||||||
|
editorState.document.root.context?.read<DocumentBloc>();
|
||||||
|
final documentId = documentBloc?.documentId;
|
||||||
|
if (documentId == null || documentId.isEmpty) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
await editorState.deleteSelectionIfNeeded();
|
await editorState.deleteSelectionIfNeeded();
|
||||||
final result = await editorState.pasteImage(image.$1, image.$2!);
|
final result = await editorState.pasteImage(
|
||||||
|
image.$1,
|
||||||
|
image.$2!,
|
||||||
|
documentId,
|
||||||
|
);
|
||||||
if (result) {
|
if (result) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,11 @@ extension PasteFromImage on EditorState {
|
|||||||
'gif',
|
'gif',
|
||||||
];
|
];
|
||||||
|
|
||||||
Future<bool> pasteImage(String format, Uint8List imageBytes) async {
|
Future<bool> pasteImage(
|
||||||
|
String format,
|
||||||
|
Uint8List imageBytes,
|
||||||
|
String documentId,
|
||||||
|
) async {
|
||||||
if (!supportedImageFormats.contains(format)) {
|
if (!supportedImageFormats.contains(format)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -56,7 +60,7 @@ extension PasteFromImage on EditorState {
|
|||||||
if (isLocalMode) {
|
if (isLocalMode) {
|
||||||
path = await saveImageToLocalStorage(copyToPath);
|
path = await saveImageToLocalStorage(copyToPath);
|
||||||
} else {
|
} else {
|
||||||
final result = await saveImageToCloudStorage(copyToPath);
|
final result = await saveImageToCloudStorage(copyToPath, documentId);
|
||||||
|
|
||||||
final errorMessage = result.$2;
|
final errorMessage = result.$2;
|
||||||
|
|
||||||
|
@ -638,7 +638,7 @@ class DocumentCoverState extends State<DocumentCover> {
|
|||||||
details = await saveImageToLocalStorage(details);
|
details = await saveImageToLocalStorage(details);
|
||||||
} else {
|
} else {
|
||||||
// else we should save the image to cloud storage
|
// else we should save the image to cloud storage
|
||||||
(details, _) = await saveImageToCloudStorage(details);
|
(details, _) = await saveImageToCloudStorage(details, widget.view.id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
widget.onChangeCover(type, details);
|
widget.onChangeCover(type, details);
|
||||||
|
@ -216,12 +216,16 @@ class ImagePlaceholderState extends State<ImagePlaceholder> {
|
|||||||
// don't limit the image size for local mode.
|
// don't limit the image size for local mode.
|
||||||
path = await saveImageToLocalStorage(url);
|
path = await saveImageToLocalStorage(url);
|
||||||
} else {
|
} else {
|
||||||
|
final documentId = context.read<DocumentBloc>().documentId;
|
||||||
|
if (documentId.isEmpty) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
// else we should save the image to cloud storage
|
// else we should save the image to cloud storage
|
||||||
setState(() {
|
setState(() {
|
||||||
showLoading = true;
|
showLoading = true;
|
||||||
this.errorMessage = null;
|
this.errorMessage = null;
|
||||||
});
|
});
|
||||||
(path, errorMessage) = await saveImageToCloudStorage(url);
|
(path, errorMessage) = await saveImageToCloudStorage(url, documentId);
|
||||||
setState(() {
|
setState(() {
|
||||||
showLoading = false;
|
showLoading = false;
|
||||||
this.errorMessage = errorMessage;
|
this.errorMessage = errorMessage;
|
||||||
|
@ -39,6 +39,7 @@ Future<String?> saveImageToLocalStorage(String localImagePath) async {
|
|||||||
|
|
||||||
Future<(String? path, String? errorMessage)> saveImageToCloudStorage(
|
Future<(String? path, String? errorMessage)> saveImageToCloudStorage(
|
||||||
String localImagePath,
|
String localImagePath,
|
||||||
|
String documentId,
|
||||||
) async {
|
) async {
|
||||||
final size = localImagePath.fileSize;
|
final size = localImagePath.fileSize;
|
||||||
if (size == null || size > 10 * 1024 * 1024) {
|
if (size == null || size > 10 * 1024 * 1024) {
|
||||||
@ -52,8 +53,7 @@ Future<(String? path, String? errorMessage)> saveImageToCloudStorage(
|
|||||||
Log.debug("Uploading image local path: $localImagePath");
|
Log.debug("Uploading image local path: $localImagePath");
|
||||||
final result = await documentService.uploadFile(
|
final result = await documentService.uploadFile(
|
||||||
localFilePath: localImagePath,
|
localFilePath: localImagePath,
|
||||||
// TODO(lucas): replace with actual documentId
|
documentId: documentId,
|
||||||
documentId: "temp",
|
|
||||||
);
|
);
|
||||||
return result.fold(
|
return result.fold(
|
||||||
(s) async {
|
(s) async {
|
||||||
|
@ -288,8 +288,8 @@ class _AutoCompletionBlockComponentState
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final textRobot = TextRobot(editorState: editorState);
|
final textRobot = TextRobot(editorState: editorState);
|
||||||
final aiResposity = AppFlowyAIService();
|
final aiService = AppFlowyAIService();
|
||||||
await aiResposity.streamCompletion(
|
await aiService.streamCompletion(
|
||||||
text: _rewritePrompt(previousOutput),
|
text: _rewritePrompt(previousOutput),
|
||||||
completionType: CompletionTypePB.ContinueWriting,
|
completionType: CompletionTypePB.ContinueWriting,
|
||||||
onStart: () async {
|
onStart: () async {
|
||||||
|
@ -31,8 +31,10 @@ import 'package:image_picker/image_picker.dart';
|
|||||||
class PageStyleCoverImage extends StatelessWidget {
|
class PageStyleCoverImage extends StatelessWidget {
|
||||||
PageStyleCoverImage({
|
PageStyleCoverImage({
|
||||||
super.key,
|
super.key,
|
||||||
|
required this.documentId,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
final String documentId;
|
||||||
late final ImagePicker _imagePicker = ImagePicker();
|
late final ImagePicker _imagePicker = ImagePicker();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -230,7 +232,7 @@ class PageStyleCoverImage extends StatelessWidget {
|
|||||||
type = PageStyleCoverImageType.localImage;
|
type = PageStyleCoverImageType.localImage;
|
||||||
} else {
|
} else {
|
||||||
// else we should save the image to cloud storage
|
// else we should save the image to cloud storage
|
||||||
(result, _) = await saveImageToCloudStorage(path);
|
(result, _) = await saveImageToCloudStorage(path, documentId);
|
||||||
type = PageStyleCoverImageType.customImage;
|
type = PageStyleCoverImageType.customImage;
|
||||||
}
|
}
|
||||||
if (!context.mounted) {
|
if (!context.mounted) {
|
||||||
|
@ -30,7 +30,7 @@ class PageStyleBottomSheet extends StatelessWidget {
|
|||||||
fontSize: 14.0,
|
fontSize: 14.0,
|
||||||
),
|
),
|
||||||
const VSpace(8.0),
|
const VSpace(8.0),
|
||||||
PageStyleCoverImage(),
|
PageStyleCoverImage(documentId: view.id),
|
||||||
const VSpace(20.0),
|
const VSpace(20.0),
|
||||||
// layout: font size, line height and font family.
|
// layout: font size, line height and font family.
|
||||||
FlowyText(
|
FlowyText(
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
|
|
||||||
use event_integration_test::user_event::user_localhost_af_cloud;
|
use event_integration_test::user_event::user_localhost_af_cloud;
|
||||||
use event_integration_test::EventIntegrationTest;
|
use event_integration_test::EventIntegrationTest;
|
||||||
use flowy_chat::entities::{CompletionTypePB};
|
use flowy_chat::entities::CompletionTypePB;
|
||||||
|
|
||||||
|
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
|
@ -420,11 +420,11 @@ pub(crate) async fn upload_file_handler(
|
|||||||
params: AFPluginData<UploadFileParamsPB>,
|
params: AFPluginData<UploadFileParamsPB>,
|
||||||
manager: AFPluginState<Weak<DocumentManager>>,
|
manager: AFPluginState<Weak<DocumentManager>>,
|
||||||
) -> DataResult<UploadedFilePB, FlowyError> {
|
) -> DataResult<UploadedFilePB, FlowyError> {
|
||||||
let AFPluginData(UploadFileParamsPB {
|
let UploadFileParamsPB {
|
||||||
workspace_id,
|
workspace_id,
|
||||||
document_id,
|
document_id,
|
||||||
local_file_path,
|
local_file_path,
|
||||||
}) = params;
|
} = params.try_into_inner()?;
|
||||||
|
|
||||||
let manager = upgrade_document(manager)?;
|
let manager = upgrade_document(manager)?;
|
||||||
let url = manager
|
let url = manager
|
||||||
@ -442,10 +442,10 @@ pub(crate) async fn download_file_handler(
|
|||||||
params: AFPluginData<UploadedFilePB>,
|
params: AFPluginData<UploadedFilePB>,
|
||||||
manager: AFPluginState<Weak<DocumentManager>>,
|
manager: AFPluginState<Weak<DocumentManager>>,
|
||||||
) -> FlowyResult<()> {
|
) -> FlowyResult<()> {
|
||||||
let AFPluginData(UploadedFilePB {
|
let UploadedFilePB {
|
||||||
url,
|
url,
|
||||||
local_file_path,
|
local_file_path,
|
||||||
}) = params;
|
} = params.try_into_inner()?;
|
||||||
|
|
||||||
let manager = upgrade_document(manager)?;
|
let manager = upgrade_document(manager)?;
|
||||||
manager.download_file(local_file_path, url).await
|
manager.download_file(local_file_path, url).await
|
||||||
@ -456,10 +456,10 @@ pub(crate) async fn delete_file_handler(
|
|||||||
params: AFPluginData<UploadedFilePB>,
|
params: AFPluginData<UploadedFilePB>,
|
||||||
manager: AFPluginState<Weak<DocumentManager>>,
|
manager: AFPluginState<Weak<DocumentManager>>,
|
||||||
) -> FlowyResult<()> {
|
) -> FlowyResult<()> {
|
||||||
let AFPluginData(UploadedFilePB {
|
let UploadedFilePB {
|
||||||
url,
|
url,
|
||||||
local_file_path,
|
local_file_path,
|
||||||
}) = params;
|
} = params.try_into_inner()?;
|
||||||
let manager = upgrade_document(manager)?;
|
let manager = upgrade_document(manager)?;
|
||||||
manager.delete_file(local_file_path, url).await
|
manager.delete_file(local_file_path, url).await
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user