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:
Nathan.fooo 2024-06-25 17:36:41 +08:00 committed by GitHub
parent bf2a00b133
commit 6b1e7b6ac8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
10 changed files with 40 additions and 20 deletions

View File

@ -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/editor_state_paste_node_extension.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_plugins/appflowy_editor_plugins.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:string_validator/string_validator.dart';
/// Paste.
@ -70,8 +72,18 @@ CommandShortcutEventHandler _pasteCommandHandler = (editorState) {
}
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();
final result = await editorState.pasteImage(image.$1, image.$2!);
final result = await editorState.pasteImage(
image.$1,
image.$2!,
documentId,
);
if (result) {
return;
}

View File

@ -21,7 +21,11 @@ extension PasteFromImage on EditorState {
'gif',
];
Future<bool> pasteImage(String format, Uint8List imageBytes) async {
Future<bool> pasteImage(
String format,
Uint8List imageBytes,
String documentId,
) async {
if (!supportedImageFormats.contains(format)) {
return false;
}
@ -56,7 +60,7 @@ extension PasteFromImage on EditorState {
if (isLocalMode) {
path = await saveImageToLocalStorage(copyToPath);
} else {
final result = await saveImageToCloudStorage(copyToPath);
final result = await saveImageToCloudStorage(copyToPath, documentId);
final errorMessage = result.$2;

View File

@ -638,7 +638,7 @@ class DocumentCoverState extends State<DocumentCover> {
details = await saveImageToLocalStorage(details);
} else {
// else we should save the image to cloud storage
(details, _) = await saveImageToCloudStorage(details);
(details, _) = await saveImageToCloudStorage(details, widget.view.id);
}
}
widget.onChangeCover(type, details);

View File

@ -216,12 +216,16 @@ class ImagePlaceholderState extends State<ImagePlaceholder> {
// don't limit the image size for local mode.
path = await saveImageToLocalStorage(url);
} else {
final documentId = context.read<DocumentBloc>().documentId;
if (documentId.isEmpty) {
return;
}
// else we should save the image to cloud storage
setState(() {
showLoading = true;
this.errorMessage = null;
});
(path, errorMessage) = await saveImageToCloudStorage(url);
(path, errorMessage) = await saveImageToCloudStorage(url, documentId);
setState(() {
showLoading = false;
this.errorMessage = errorMessage;

View File

@ -39,6 +39,7 @@ Future<String?> saveImageToLocalStorage(String localImagePath) async {
Future<(String? path, String? errorMessage)> saveImageToCloudStorage(
String localImagePath,
String documentId,
) async {
final size = localImagePath.fileSize;
if (size == null || size > 10 * 1024 * 1024) {
@ -52,8 +53,7 @@ Future<(String? path, String? errorMessage)> saveImageToCloudStorage(
Log.debug("Uploading image local path: $localImagePath");
final result = await documentService.uploadFile(
localFilePath: localImagePath,
// TODO(lucas): replace with actual documentId
documentId: "temp",
documentId: documentId,
);
return result.fold(
(s) async {

View File

@ -288,8 +288,8 @@ class _AutoCompletionBlockComponentState
return;
}
final textRobot = TextRobot(editorState: editorState);
final aiResposity = AppFlowyAIService();
await aiResposity.streamCompletion(
final aiService = AppFlowyAIService();
await aiService.streamCompletion(
text: _rewritePrompt(previousOutput),
completionType: CompletionTypePB.ContinueWriting,
onStart: () async {

View File

@ -31,8 +31,10 @@ import 'package:image_picker/image_picker.dart';
class PageStyleCoverImage extends StatelessWidget {
PageStyleCoverImage({
super.key,
required this.documentId,
});
final String documentId;
late final ImagePicker _imagePicker = ImagePicker();
@override
@ -230,7 +232,7 @@ class PageStyleCoverImage extends StatelessWidget {
type = PageStyleCoverImageType.localImage;
} else {
// else we should save the image to cloud storage
(result, _) = await saveImageToCloudStorage(path);
(result, _) = await saveImageToCloudStorage(path, documentId);
type = PageStyleCoverImageType.customImage;
}
if (!context.mounted) {

View File

@ -30,7 +30,7 @@ class PageStyleBottomSheet extends StatelessWidget {
fontSize: 14.0,
),
const VSpace(8.0),
PageStyleCoverImage(),
PageStyleCoverImage(documentId: view.id),
const VSpace(20.0),
// layout: font size, line height and font family.
FlowyText(

View File

@ -1,8 +1,6 @@
use event_integration_test::user_event::user_localhost_af_cloud;
use event_integration_test::EventIntegrationTest;
use flowy_chat::entities::{CompletionTypePB};
use flowy_chat::entities::CompletionTypePB;
use std::time::Duration;

View File

@ -420,11 +420,11 @@ pub(crate) async fn upload_file_handler(
params: AFPluginData<UploadFileParamsPB>,
manager: AFPluginState<Weak<DocumentManager>>,
) -> DataResult<UploadedFilePB, FlowyError> {
let AFPluginData(UploadFileParamsPB {
let UploadFileParamsPB {
workspace_id,
document_id,
local_file_path,
}) = params;
} = params.try_into_inner()?;
let manager = upgrade_document(manager)?;
let url = manager
@ -442,10 +442,10 @@ pub(crate) async fn download_file_handler(
params: AFPluginData<UploadedFilePB>,
manager: AFPluginState<Weak<DocumentManager>>,
) -> FlowyResult<()> {
let AFPluginData(UploadedFilePB {
let UploadedFilePB {
url,
local_file_path,
}) = params;
} = params.try_into_inner()?;
let manager = upgrade_document(manager)?;
manager.download_file(local_file_path, url).await
@ -456,10 +456,10 @@ pub(crate) async fn delete_file_handler(
params: AFPluginData<UploadedFilePB>,
manager: AFPluginState<Weak<DocumentManager>>,
) -> FlowyResult<()> {
let AFPluginData(UploadedFilePB {
let UploadedFilePB {
url,
local_file_path,
}) = params;
} = params.try_into_inner()?;
let manager = upgrade_document(manager)?;
manager.delete_file(local_file_path, url).await
}