implemented internal file sharing and saving, added server-side file references, refactored share pickers for unified flows, and updated UI branding labels
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:nextcloud/nextcloud.dart';
|
||||
|
||||
import '../api/marianumcloud/webdav/webdav_api.dart';
|
||||
import '../widget/confirm_dialog.dart';
|
||||
import 'remote_file_ref.dart';
|
||||
|
||||
/// Server-side WebDAV copy of [source] into [targetFolderPath]. On a 412
|
||||
/// conflict the user is asked whether to overwrite; on confirmation the call
|
||||
/// is retried with `overwrite: true`. Returns true when the file ended up at
|
||||
/// the target, false when the user cancelled.
|
||||
Future<bool> copyRemoteFileTo({
|
||||
required BuildContext context,
|
||||
required RemoteFileRef source,
|
||||
required String targetFolderPath,
|
||||
}) async {
|
||||
final webdav = await WebdavApi.webdav;
|
||||
final dst = targetFolderPath.isEmpty
|
||||
? source.name
|
||||
: '${targetFolderPath.replaceAll(RegExp(r'/+$'), '')}/${source.name}';
|
||||
final src = PathUri.parse(source.path);
|
||||
final dstUri = PathUri.parse(dst);
|
||||
|
||||
try {
|
||||
await webdav.copy(src, dstUri);
|
||||
return true;
|
||||
} on DynamiteApiException catch (e) {
|
||||
if (e.statusCode != 412) rethrow;
|
||||
if (!context.mounted) return false;
|
||||
final overwrite = await showDialog<bool>(
|
||||
context: context,
|
||||
builder: (ctx) => ConfirmDialog(
|
||||
title: 'Datei existiert bereits',
|
||||
content:
|
||||
'"${source.name}" existiert in /$targetFolderPath. Überschreiben?',
|
||||
confirmButton: 'Überschreiben',
|
||||
cancelButton: 'Abbrechen',
|
||||
onConfirm: () => Navigator.of(ctx).pop(true),
|
||||
),
|
||||
);
|
||||
if (overwrite != true) return false;
|
||||
await webdav.copy(src, dstUri, overwrite: true);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
import '../api/marianumcloud/talk/chat/get_chat_response.dart';
|
||||
import '../api/marianumcloud/webdav/queries/list_files/cacheable_file.dart';
|
||||
|
||||
/// References a file that already lives on the Nextcloud server. Used by the
|
||||
/// in-app share/save flows that operate on remote paths instead of local
|
||||
/// cache files (no upload needed).
|
||||
class RemoteFileRef {
|
||||
final String path;
|
||||
final String name;
|
||||
|
||||
const RemoteFileRef({required this.path, required this.name});
|
||||
|
||||
/// Caller must verify `file.path != null` first — Talk message parameters
|
||||
/// without a path (system events, mentions, polls) are not file refs.
|
||||
factory RemoteFileRef.fromTalk(RichObjectString file) =>
|
||||
RemoteFileRef(path: file.path!, name: file.name);
|
||||
|
||||
factory RemoteFileRef.fromCacheable(CacheableFile file) =>
|
||||
RemoteFileRef(path: file.path, name: file.name);
|
||||
}
|
||||
Reference in New Issue
Block a user