mirror of
https://gitlab.com/nkming2/nc-photos.git
synced 2025-02-24 02:18:50 +01:00
List and create share now take file descriptor instead of file
This commit is contained in:
parent
59a5741c50
commit
07ee28d0cb
5 changed files with 28 additions and 23 deletions
|
@ -70,15 +70,18 @@ String unstripPath(Account account, String strippedPath) {
|
|||
}
|
||||
|
||||
/// For a path "remote.php/dav/files/foo/bar.jpg", return foo
|
||||
CiString getUserDirName(File file) {
|
||||
if (file.path.startsWith("remote.php/dav/files/")) {
|
||||
CiString getUserDirName(File file) => getUserDirNamePath(file.path);
|
||||
|
||||
/// For a path "remote.php/dav/files/foo/bar.jpg", return foo
|
||||
CiString getUserDirNamePath(String filePath) {
|
||||
if (filePath.startsWith("remote.php/dav/files/")) {
|
||||
const beg = "remote.php/dav/files/".length;
|
||||
final end = file.path.indexOf("/", beg);
|
||||
final end = filePath.indexOf("/", beg);
|
||||
if (end != -1) {
|
||||
return file.path.substring(beg, end).toCi();
|
||||
return filePath.substring(beg, end).toCi();
|
||||
}
|
||||
}
|
||||
throw ArgumentError("Invalid path: ${file.path}");
|
||||
throw ArgumentError("Invalid path: $filePath");
|
||||
}
|
||||
|
||||
String renameConflict(String filename, int conflictCount) {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import 'package:equatable/equatable.dart';
|
||||
import 'package:nc_photos/account.dart';
|
||||
import 'package:nc_photos/entity/file.dart';
|
||||
import 'package:nc_photos/entity/file_descriptor.dart';
|
||||
import 'package:np_string/np_string.dart';
|
||||
import 'package:path/path.dart' as path_lib;
|
||||
import 'package:to_string/to_string.dart';
|
||||
|
@ -150,7 +151,7 @@ class ShareRepo {
|
|||
/// See [ShareDataSource.list]
|
||||
Future<List<Share>> list(
|
||||
Account account,
|
||||
File file, {
|
||||
FileDescriptor file, {
|
||||
bool? isIncludeReshare,
|
||||
}) =>
|
||||
dataSrc.list(account, file, isIncludeReshare: isIncludeReshare);
|
||||
|
@ -171,7 +172,8 @@ class ShareRepo {
|
|||
dataSrc.reverseListAll(account);
|
||||
|
||||
/// See [ShareDataSource.create]
|
||||
Future<Share> create(Account account, File file, String shareWith) =>
|
||||
Future<Share> create(
|
||||
Account account, FileDescriptor file, String shareWith) =>
|
||||
dataSrc.create(account, file, shareWith);
|
||||
|
||||
/// See [ShareDataSource.createLink]
|
||||
|
@ -193,7 +195,7 @@ abstract class ShareDataSource {
|
|||
/// List all shares from a given file
|
||||
Future<List<Share>> list(
|
||||
Account account,
|
||||
File file, {
|
||||
FileDescriptor file, {
|
||||
bool? isIncludeReshare,
|
||||
});
|
||||
|
||||
|
@ -210,7 +212,7 @@ abstract class ShareDataSource {
|
|||
Future<List<Share>> reverseListAll(Account account);
|
||||
|
||||
/// Share a file/folder with a user
|
||||
Future<Share> create(Account account, File file, String shareWith);
|
||||
Future<Share> create(Account account, FileDescriptor file, String shareWith);
|
||||
|
||||
/// Share a file/folder with a share link
|
||||
///
|
||||
|
|
|
@ -18,12 +18,12 @@ part 'data_source.g.dart';
|
|||
@npLog
|
||||
class ShareRemoteDataSource implements ShareDataSource {
|
||||
@override
|
||||
list(
|
||||
Future<List<Share>> list(
|
||||
Account account,
|
||||
File file, {
|
||||
FileDescriptor file, {
|
||||
bool? isIncludeReshare,
|
||||
}) async {
|
||||
_log.info("[list] ${file.path}");
|
||||
_log.info("[list] ${file.fdPath}");
|
||||
final response =
|
||||
await ApiUtil.fromAccount(account).ocs().filesSharing().shares().get(
|
||||
path: file.strippedPath,
|
||||
|
@ -73,8 +73,9 @@ class ShareRemoteDataSource implements ShareDataSource {
|
|||
}
|
||||
|
||||
@override
|
||||
create(Account account, File file, String shareWith) async {
|
||||
_log.info("[create] Share '${file.path}' with '$shareWith'");
|
||||
Future<Share> create(
|
||||
Account account, FileDescriptor file, String shareWith) async {
|
||||
_log.info("[create] Share '${file.fdPath}' with '$shareWith'");
|
||||
final response =
|
||||
await ApiUtil.fromAccount(account).ocs().filesSharing().shares().post(
|
||||
path: file.strippedPath,
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
import 'package:nc_photos/account.dart';
|
||||
import 'package:nc_photos/entity/file.dart';
|
||||
import 'package:nc_photos/entity/file_descriptor.dart';
|
||||
import 'package:nc_photos/entity/share.dart';
|
||||
|
||||
class CreateUserShare {
|
||||
const CreateUserShare(this.shareRepo);
|
||||
|
||||
Future<Share> call(Account account, File file, String shareWith) =>
|
||||
Future<Share> call(Account account, FileDescriptor file, String shareWith) =>
|
||||
shareRepo.create(account, file, shareWith);
|
||||
|
||||
final ShareRepo shareRepo;
|
||||
|
|
|
@ -2,7 +2,7 @@ import 'package:logging/logging.dart';
|
|||
import 'package:nc_photos/account.dart';
|
||||
import 'package:nc_photos/debug_util.dart';
|
||||
import 'package:nc_photos/di_container.dart';
|
||||
import 'package:nc_photos/entity/file.dart';
|
||||
import 'package:nc_photos/entity/file_descriptor.dart';
|
||||
import 'package:nc_photos/entity/file_util.dart' as file_util;
|
||||
import 'package:nc_photos/entity/share.dart';
|
||||
import 'package:nc_photos/use_case/find_file.dart';
|
||||
|
@ -13,22 +13,20 @@ part 'list_share.g.dart';
|
|||
/// List all shares from a given file
|
||||
@npLog
|
||||
class ListShare {
|
||||
ListShare(this._c) : assert(require(_c));
|
||||
|
||||
static bool require(DiContainer c) => DiContainer.has(c, DiType.shareRepo);
|
||||
const ListShare(this._c);
|
||||
|
||||
Future<List<Share>> call(
|
||||
Account account,
|
||||
File file, {
|
||||
FileDescriptor file, {
|
||||
bool? isIncludeReshare,
|
||||
}) async {
|
||||
try {
|
||||
if (file_util.getUserDirName(file) != account.userId) {
|
||||
file = (await FindFile(_c)(account, [file.fileId!])).first;
|
||||
if (file_util.getUserDirNamePath(file.fdPath) != account.userId) {
|
||||
file = (await FindFile(_c)(account, [file.fdId])).first;
|
||||
}
|
||||
} catch (_) {
|
||||
// file not found
|
||||
_log.warning("[call] File not found in db: ${logFilename(file.path)}");
|
||||
_log.warning("[call] File not found in db: ${logFilename(file.fdPath)}");
|
||||
}
|
||||
return _c.shareRepo.list(
|
||||
account,
|
||||
|
|
Loading…
Reference in a new issue