mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
feat: use default publish name
This commit is contained in:
parent
be4d60ca0d
commit
0daabd2f3c
@ -68,17 +68,8 @@ class DocumentShareBloc extends Bloc<DocumentShareEvent, DocumentShareState> {
|
||||
publish: (nameSpace, publishName) async {
|
||||
// set space name
|
||||
try {
|
||||
final getNameSpaceResult =
|
||||
await ViewBackendService.getPublishNameSpace();
|
||||
final name = await getNameSpaceResult.fold((s) async {
|
||||
Log.error('get publish namespace success: ${s.namespace}');
|
||||
return s.namespace;
|
||||
}, (f) async {
|
||||
Log.error('get publish namespace error: $f');
|
||||
await ViewBackendService.setPublishNameSpace(nameSpace)
|
||||
.getOrThrow();
|
||||
return nameSpace;
|
||||
});
|
||||
final result =
|
||||
await ViewBackendService.getPublishNameSpace().getOrThrow();
|
||||
|
||||
await ViewBackendService.publish(
|
||||
view,
|
||||
@ -89,7 +80,7 @@ class DocumentShareBloc extends Bloc<DocumentShareEvent, DocumentShareState> {
|
||||
state.copyWith(
|
||||
isPublished: true,
|
||||
publishResult: FlowySuccess(null),
|
||||
url: '$_url/$name/$publishName',
|
||||
url: '$_url/${result.namespace}/$publishName',
|
||||
),
|
||||
);
|
||||
} catch (e) {
|
||||
@ -107,10 +98,15 @@ class DocumentShareBloc extends Bloc<DocumentShareEvent, DocumentShareState> {
|
||||
}
|
||||
},
|
||||
unPublish: () async {
|
||||
await ViewBackendService.unpublish(view);
|
||||
final result = await ViewBackendService.unpublish(view);
|
||||
final isPublished = !result.isSuccess;
|
||||
result.onFailure((f) {
|
||||
Log.error('unpublish error: $f');
|
||||
});
|
||||
|
||||
emit(
|
||||
state.copyWith(
|
||||
isPublished: false,
|
||||
isPublished: isPublished,
|
||||
publishResult: null,
|
||||
url: '',
|
||||
),
|
||||
|
@ -1,20 +1,19 @@
|
||||
import 'dart:math';
|
||||
|
||||
import 'package:flowy_infra/uuid.dart';
|
||||
|
||||
final _regExp = RegExp(r'[^\w\-\.@:/]');
|
||||
|
||||
Future<String> generateNameSpace() async {
|
||||
const workspaceName = '';
|
||||
final id = uuid().substring(0, 8);
|
||||
return '$workspaceName$id'.replaceAll(_regExp, '-');
|
||||
String replaceInvalidChars(String input) {
|
||||
final RegExp invalidCharsRegex = RegExp('[^a-zA-Z0-9-]');
|
||||
return input.replaceAll(invalidCharsRegex, '');
|
||||
}
|
||||
|
||||
// The backend limits the publish name to a maximum of 50 characters.
|
||||
// If the combined length of the ID and the name exceeds 50 characters,
|
||||
Future<String> generateNameSpace() async {
|
||||
return '';
|
||||
}
|
||||
|
||||
// The backend limits the publish name to a maximum of 120 characters.
|
||||
// If the combined length of the ID and the name exceeds 120 characters,
|
||||
// we will truncate the name to ensure the final result is within the limit.
|
||||
// The name should only contain alphanumeric characters and hyphens.
|
||||
Future<String> generatePublishName(String id, String name) async {
|
||||
final result = '${name.substring(0, min(49 - id.length, name.length))}-$id';
|
||||
return result.replaceAll(_regExp, '-');
|
||||
if (name.length >= 120 - id.length) {
|
||||
name = name.substring(0, 120 - id.length);
|
||||
}
|
||||
return replaceInvalidChars('$name-$id');
|
||||
}
|
||||
|
@ -45,10 +45,9 @@ class PublishTab extends StatelessWidget {
|
||||
id,
|
||||
state.viewName,
|
||||
);
|
||||
final nameSpace = await generateNameSpace();
|
||||
if (context.mounted) {
|
||||
context.read<DocumentShareBloc>().add(
|
||||
DocumentShareEvent.publish(nameSpace, publishName),
|
||||
DocumentShareEvent.publish('', publishName),
|
||||
);
|
||||
}
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user