mirror of
https://gitlab.com/nkming2/nc-photos.git
synced 2025-02-24 18:38:48 +01:00
Put server-side storage path together
This commit is contained in:
parent
a1f7bd684a
commit
15e1591622
5 changed files with 23 additions and 13 deletions
|
@ -7,6 +7,7 @@ import 'package:nc_photos/entity/album.dart';
|
|||
import 'package:nc_photos/entity/file.dart';
|
||||
import 'package:nc_photos/mobile/platform.dart'
|
||||
if (dart.library.html) 'package:nc_photos/web/platform.dart' as platform;
|
||||
import 'package:nc_photos/remote_storage_util.dart' as remote_storage_util;
|
||||
import 'package:synchronized/synchronized.dart';
|
||||
|
||||
class AppDb {
|
||||
|
@ -128,7 +129,7 @@ class AppDbAlbumEntry {
|
|||
}
|
||||
|
||||
static String toRootPath(Account account) =>
|
||||
"${account.url}/${getAlbumFileRoot(account)}";
|
||||
"${account.url}/${remote_storage_util.getRemoteAlbumsDir(account)}";
|
||||
static String toPath(Account account, File albumFile) =>
|
||||
"${account.url}/${albumFile.path}";
|
||||
static String toPrimaryKey(Account account, File albumFile, int index) =>
|
||||
|
|
|
@ -8,13 +8,13 @@ import 'package:flutter/foundation.dart';
|
|||
import 'package:idb_sqflite/idb_sqflite.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
import 'package:nc_photos/account.dart';
|
||||
import 'package:nc_photos/api/api_util.dart' as api_util;
|
||||
import 'package:nc_photos/app_db.dart';
|
||||
import 'package:nc_photos/entity/file.dart';
|
||||
import 'package:nc_photos/exception.dart';
|
||||
import 'package:nc_photos/int_util.dart' as int_util;
|
||||
import 'package:nc_photos/iterable_extension.dart';
|
||||
import 'package:nc_photos/list_extension.dart';
|
||||
import 'package:nc_photos/remote_storage_util.dart' as remote_storage_util;
|
||||
import 'package:nc_photos/use_case/create_dir.dart';
|
||||
import 'package:nc_photos/use_case/get_file_binary.dart';
|
||||
import 'package:nc_photos/use_case/ls.dart';
|
||||
|
@ -23,9 +23,6 @@ import 'package:path/path.dart' as path;
|
|||
import 'package:quiver/iterables.dart';
|
||||
import 'package:tuple/tuple.dart';
|
||||
|
||||
String getAlbumFileRoot(Account account) =>
|
||||
"${api_util.getWebdavRootUrlRelative(account)}/.com.nkming.nc_photos/albums";
|
||||
|
||||
bool isAlbumFile(File file) =>
|
||||
path.dirname(file.path).endsWith(".com.nkming.nc_photos/albums");
|
||||
|
||||
|
@ -296,7 +293,8 @@ class AlbumRemoteDataSource implements AlbumDataSource {
|
|||
create(Account account, Album album) async {
|
||||
_log.info("[create]");
|
||||
final fileName = _makeAlbumFileName();
|
||||
final filePath = "${getAlbumFileRoot(account)}/$fileName";
|
||||
final filePath =
|
||||
"${remote_storage_util.getRemoteAlbumsDir(account)}/$fileName";
|
||||
final fileRepo = FileRepo(FileWebdavDataSource());
|
||||
try {
|
||||
await PutFileBinary(fileRepo)(
|
||||
|
@ -305,7 +303,8 @@ class AlbumRemoteDataSource implements AlbumDataSource {
|
|||
if (e.response.statusCode == 404) {
|
||||
_log.info("[create] Missing album dir, creating");
|
||||
// no dir
|
||||
await CreateDir(fileRepo)(account, getAlbumFileRoot(account));
|
||||
await CreateDir(fileRepo)(
|
||||
account, remote_storage_util.getRemoteAlbumsDir(account));
|
||||
// then retry
|
||||
await PutFileBinary(fileRepo)(
|
||||
account, filePath, utf8.encode(jsonEncode(album.toRemoteJson())));
|
||||
|
|
8
lib/remote_storage_util.dart
Normal file
8
lib/remote_storage_util.dart
Normal file
|
@ -0,0 +1,8 @@
|
|||
import 'package:nc_photos/account.dart';
|
||||
import 'package:nc_photos/api/api_util.dart' as api_util;
|
||||
|
||||
String getRemoteAlbumsDir(Account account) =>
|
||||
"${_getRemoteStorageDir(account)}/albums";
|
||||
|
||||
String _getRemoteStorageDir(Account account) =>
|
||||
"${api_util.getWebdavRootUrlRelative(account)}/.com.nkming.nc_photos";
|
|
@ -1,9 +1,9 @@
|
|||
import 'package:logging/logging.dart';
|
||||
import 'package:nc_photos/account.dart';
|
||||
import 'package:nc_photos/api/api_util.dart' as api_util;
|
||||
import 'package:nc_photos/entity/album.dart';
|
||||
import 'package:nc_photos/entity/file.dart';
|
||||
import 'package:nc_photos/exception.dart';
|
||||
import 'package:nc_photos/remote_storage_util.dart' as remote_storage_util;
|
||||
import 'package:nc_photos/use_case/create_dir.dart';
|
||||
import 'package:nc_photos/use_case/ls.dart';
|
||||
import 'package:path/path.dart' as path;
|
||||
|
@ -37,7 +37,8 @@ class _MigrateAlbumFiles {
|
|||
return false;
|
||||
}
|
||||
// copy to an intermediate location
|
||||
final intermediateDir = "${getAlbumFileRoot(account)}.tmp";
|
||||
final intermediateDir =
|
||||
"${remote_storage_util.getRemoteAlbumsDir(account)}.tmp";
|
||||
_log.info("[call] Copy album files to '$intermediateDir'");
|
||||
if (!ls.any((element) =>
|
||||
element.isCollection == true && element.path == intermediateDir)) {
|
||||
|
@ -49,10 +50,10 @@ class _MigrateAlbumFiles {
|
|||
shouldOverwrite: true);
|
||||
}
|
||||
// rename intermediate
|
||||
await fileRepo.move(
|
||||
account, File(path: intermediateDir), getAlbumFileRoot(account));
|
||||
await fileRepo.move(account, File(path: intermediateDir),
|
||||
remote_storage_util.getRemoteAlbumsDir(account));
|
||||
_log.info(
|
||||
"[call] Album files moved to '${getAlbumFileRoot(account)}' successfully");
|
||||
"[call] Album files moved to '${remote_storage_util.getRemoteAlbumsDir(account)}' successfully");
|
||||
// remove old files
|
||||
for (final f in albumFiles) {
|
||||
try {
|
||||
|
|
|
@ -3,6 +3,7 @@ import 'package:nc_photos/account.dart';
|
|||
import 'package:nc_photos/entity/album.dart';
|
||||
import 'package:nc_photos/entity/file.dart';
|
||||
import 'package:nc_photos/exception.dart';
|
||||
import 'package:nc_photos/remote_storage_util.dart' as remote_storage_util;
|
||||
import 'package:nc_photos/use_case/compat/v15.dart';
|
||||
import 'package:nc_photos/use_case/ls.dart';
|
||||
|
||||
|
@ -30,7 +31,7 @@ class ListAlbum {
|
|||
final ls = await Ls(fileRepo)(
|
||||
account,
|
||||
File(
|
||||
path: getAlbumFileRoot(account),
|
||||
path: remote_storage_util.getRemoteAlbumsDir(account),
|
||||
));
|
||||
final albumFiles =
|
||||
ls.where((element) => element.isCollection != true).toList();
|
||||
|
|
Loading…
Reference in a new issue