Remove unused code

This commit is contained in:
Ming Ming 2024-05-09 00:11:40 +08:00
parent a336542187
commit 901195442f
8 changed files with 2 additions and 356 deletions

View file

@ -2,6 +2,3 @@ import 'package:nc_photos/account.dart';
String getInstNameForAccount(String className, Account account) =>
"$className(${account.scheme}://${account.userId.toCaseInsensitiveString()}@${account.address})";
String getInstNameForRootAwareAccount(String className, Account account) =>
"$className(${account.scheme}://${account.userId.toCaseInsensitiveString()}@${account.address}?${account.roots.join('&')})";

View file

@ -11,11 +11,11 @@ import 'package:nc_photos/entity/album/provider.dart';
import 'package:nc_photos/entity/file.dart';
import 'package:nc_photos/entity/file_descriptor.dart';
import 'package:nc_photos/entity/share.dart';
import 'package:nc_photos/object_extension.dart';
import 'package:nc_photos/use_case/list_share.dart';
import 'package:nc_photos/use_case/list_sharee.dart';
import 'package:np_codegen/np_codegen.dart';
import 'package:np_collection/np_collection.dart';
import 'package:np_common/object_util.dart';
import 'package:np_string/np_string.dart';
import 'package:to_string/to_string.dart';
@ -277,7 +277,7 @@ class ListAlbumShareOutlierBloc extends Bloc<ListAlbumShareOutlierBlocEvent,
for (final fi in fileItems) {
try {
(await _processSingleFileItem(account, album, fi, albumShares, errors))
?.apply((item) {
?.also((item) {
products.add(item);
});
} catch (e, stackTrace) {

View file

@ -1,57 +1,9 @@
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:nc_photos/exception_util.dart' as exception_util;
import 'package:nc_photos/k.dart' as k;
import 'package:nc_photos/snack_bar_manager.dart';
class NotifiedAction {
NotifiedAction(
this.action,
this.processingText,
this.successText, {
this.failureText,
});
Future<void> call() async {
if (processingText != null) {
SnackBarManager().showSnackBar(
SnackBar(
content: Text(processingText!),
duration: k.snackBarDurationShort,
),
canBeReplaced: true,
);
}
try {
await action();
SnackBarManager().showSnackBar(SnackBar(
content: Text(successText),
duration: k.snackBarDurationNormal,
));
} catch (e) {
SnackBarManager().showSnackBar(SnackBar(
content: Text(
(failureText?.isNotEmpty == true ? "$failureText: " : "") +
exception_util.toUserString(e)),
duration: k.snackBarDurationNormal,
));
rethrow;
}
}
final FutureOr<void> Function() action;
/// Message to be shown before performing [action]
final String? processingText;
/// Message to be shown after [action] finished without throwing
final String successText;
/// Message to be shown if [action] threw, prepending the exception
final String? failureText;
}
class NotifiedListAction<T> {
NotifiedListAction({
required this.list,

View file

@ -1,16 +1,6 @@
import 'dart:async';
import 'package:np_common/object_util.dart';
extension ObjectExtension<T> on T {
/// Deprecated, use [also]
T apply(void Function(T obj) fn) => also(fn);
/// Deprecated, use [alsoFuture]
Future<T> applyFuture(FutureOr<void> Function(T obj) fn) => alsoFuture(fn);
/// Deprecated, use [let]
U run<U>(U Function(T obj) fn) => let(fn);
/// Deprecated, use [letFuture]
Future<U> runFuture<U>(FutureOr<U> Function(T obj) fn) => letFuture(fn);
}

View file

@ -1,72 +0,0 @@
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/use_case/update_property.dart';
import 'package:np_codegen/np_codegen.dart';
import 'package:np_common/type.dart';
part 'archive_file.g.dart';
class ArchiveFile {
ArchiveFile(DiContainer c) : _op = _SetArchiveFile(c);
/// Archive list of [files] and return the archived count
Future<int> call(
Account account,
List<File> files, {
ErrorWithValueHandler<File>? onError,
}) =>
_op(account, files, true, onError: onError);
final _SetArchiveFile _op;
}
class UnarchiveFile {
UnarchiveFile(DiContainer c) : _op = _SetArchiveFile(c);
/// Unarchive list of [files] and return the unarchived count
Future<int> call(
Account account,
List<File> files, {
ErrorWithValueHandler<File>? onError,
}) =>
_op(account, files, false, onError: onError);
final _SetArchiveFile _op;
}
@npLog
class _SetArchiveFile {
_SetArchiveFile(this._c) : assert(require(_c));
static bool require(DiContainer c) => DiContainer.has(c, DiType.fileRepo);
/// Archive list of [files] and return the archived count
Future<int> call(
Account account,
List<File> files,
bool flag, {
ErrorWithValueHandler<File>? onError,
}) async {
var count = 0;
for (final f in files) {
try {
await UpdateProperty(_c).updateIsArchived(account, f, flag);
++count;
} catch (e, stackTrace) {
_log.severe(
"[call] Failed while UpdateProperty: ${logFilename(f.strippedPath)}",
e,
stackTrace,
);
onError?.call(f, e, stackTrace);
}
}
return count;
}
final DiContainer _c;
}

View file

@ -1,14 +0,0 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'archive_file.dart';
// **************************************************************************
// NpLogGenerator
// **************************************************************************
extension _$_SetArchiveFileNpLog on _SetArchiveFile {
// ignore: unused_element
Logger get _log => log;
static final log = Logger("use_case.archive_file._SetArchiveFile");
}

View file

@ -1,55 +0,0 @@
import 'package:nc_photos/account.dart';
import 'package:nc_photos/db/entity_converter.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/remote_storage_util.dart' as remote_storage_util;
class ScanDirOffline {
const ScanDirOffline(this._c);
Future<List<FileDescriptor>> call(
Account account,
File root, {
bool isOnlySupportedFormat = true,
}) async {
final results = await _c.npDb.getFileDescriptors(
account: account.toDb(),
includeRelativeRoots: [root.strippedPathWithEmpty],
excludeRelativeRoots: [remote_storage_util.remoteStorageDirRelativePath],
mimes: isOnlySupportedFormat ? file_util.supportedFormatMimes : null,
);
return results
.map((e) =>
DbFileDescriptorConverter.fromDb(account.userId.toString(), e))
.toList();
}
final DiContainer _c;
}
class ScanDirOfflineMini {
const ScanDirOfflineMini(this._c);
Future<List<FileDescriptor>> call(
Account account,
List<File> roots,
int limit, {
bool isOnlySupportedFormat = true,
}) async {
final results = await _c.npDb.getFileDescriptors(
account: account.toDb(),
includeRelativeRoots: roots.map((e) => e.strippedPathWithEmpty).toList(),
excludeRelativeRoots: [remote_storage_util.remoteStorageDirRelativePath],
mimes: isOnlySupportedFormat ? file_util.supportedFormatMimes : null,
limit: limit,
);
return results
.map((e) =>
DbFileDescriptorConverter.fromDb(account.userId.toString(), e))
.toList();
}
final DiContainer _c;
}

View file

@ -1,152 +0,0 @@
import 'package:nc_photos/db/entity_converter.dart';
import 'package:nc_photos/di_container.dart';
import 'package:nc_photos/entity/file.dart';
import 'package:nc_photos/entity/file_util.dart' as file_util;
import 'package:nc_photos/use_case/scan_dir_offline.dart';
import 'package:np_db_sqlite/np_db_sqlite_compat.dart' as compat;
import 'package:test/test.dart';
import '../test_util.dart' as util;
void main() {
group("ScanDirOffline", () {
group("single account", () {
test("root", _root);
test("subdir", _subDir);
test("unsupported file", _unsupportedFile);
});
group("multiple account", () {
test("root", _multiAccountRoot);
});
});
}
/// Scan root dir
///
/// Files: admin/test1.jpg, admin/test/test2.jpg
/// Scan: admin
/// Expect: all files
Future<void> _root() async {
final account = util.buildAccount();
final files = (util.FilesBuilder()
..addJpeg("admin/test1.jpg")
..addJpeg("admin/test/test2.jpg"))
.build();
final c = DiContainer(
npDb: util.buildTestDb(),
);
addTearDown(() => c.sqliteDb.close());
await c.sqliteDb.transaction(() async {
await c.sqliteDb.insertAccounts([account.toDb()]);
await util.insertFiles(c.sqliteDb, account, files);
});
// convert to set because ScanDirOffline does not guarantee order
expect(
(await ScanDirOffline(c)(
account, File(path: file_util.unstripPath(account, "."))))
.toSet(),
files.map(util.fileToFileDescriptor).toSet(),
);
}
/// Scan sub dir (admin/test)
///
/// Files: admin/test1.jpg, admin/test/test2.jpg
/// Scan: admin/test
/// Expect: admin/test/test2.jpg
Future<void> _subDir() async {
final account = util.buildAccount();
final files = (util.FilesBuilder()
..addJpeg("admin/test1.jpg")
..addJpeg("admin/test/test2.jpg"))
.build();
final c = DiContainer(
npDb: util.buildTestDb(),
);
addTearDown(() => c.sqliteDb.close());
await c.sqliteDb.transaction(() async {
await c.sqliteDb.insertAccounts([account.toDb()]);
await util.insertFiles(c.sqliteDb, account, files);
});
expect(
(await ScanDirOffline(c)(
account, File(path: file_util.unstripPath(account, "test"))))
.toSet(),
[files[1]].map(util.fileToFileDescriptor).toSet(),
);
}
/// Scan dir with unsupported file
///
/// Files: admin/test1.jpg, admin/test2.pdf
/// Scan: admin
/// Expect: admin/test1.jpg
Future<void> _unsupportedFile() async {
final account = util.buildAccount();
final files = (util.FilesBuilder()
..addJpeg("admin/test1.jpg")
..addGenericFile("admin/test2.pdf", "application/pdf"))
.build();
final c = DiContainer(
npDb: util.buildTestDb(),
);
addTearDown(() => c.sqliteDb.close());
await c.sqliteDb.transaction(() async {
await c.sqliteDb.insertAccounts([account.toDb()]);
await util.insertFiles(c.sqliteDb, account, files);
});
// convert to set because ScanDirOffline does not guarantee order
expect(
(await ScanDirOffline(c)(
account, File(path: file_util.unstripPath(account, "."))))
.toSet(),
[files[0]].map(util.fileToFileDescriptor).toSet(),
);
}
/// Scan root dir with multiple accounts
///
/// Files: admin/test1.jpg, admin/test/test2.jpg, user1/test1.jpg,
/// user1/test/test2.jpg
/// Scan: admin
/// Expect: admin/test1.jpg, admin/test/test2.jpg
/// Scan: user1
/// Expect: user1/test1.jpg, user1/test/test2.jpg
Future<void> _multiAccountRoot() async {
final account = util.buildAccount();
final user1Account = util.buildAccount(userId: "user1");
final files = (util.FilesBuilder()
..addJpeg("admin/test1.jpg")
..addJpeg("admin/test/test2.jpg"))
.build();
final user1Files = (util.FilesBuilder(initialFileId: files.length)
..addJpeg("user1/test1.jpg", ownerId: "user1")
..addJpeg("user1/test/test2.jpg", ownerId: "user1"))
.build();
final c = DiContainer(
npDb: util.buildTestDb(),
);
addTearDown(() => c.sqliteDb.close());
await c.sqliteDb.transaction(() async {
await c.sqliteDb.insertAccounts([account.toDb()]);
await util.insertFiles(c.sqliteDb, account, files);
await c.sqliteDb.insertAccounts([user1Account.toDb()]);
await util.insertFiles(c.sqliteDb, user1Account, user1Files);
});
expect(
(await ScanDirOffline(c)(
account, File(path: file_util.unstripPath(account, "."))))
.toSet(),
files.map(util.fileToFileDescriptor).toSet(),
);
expect(
(await ScanDirOffline(c)(
user1Account, File(path: file_util.unstripPath(user1Account, "."))))
.toSet(),
user1Files.map(util.fileToFileDescriptor).toSet(),
);
}