mirror of
https://gitlab.com/nkming2/nc-photos.git
synced 2025-01-22 08:46:18 +01:00
Don't do the client side fallback if it's disabled in pref
This commit is contained in:
parent
ef67d414fd
commit
cfae5d6b90
5 changed files with 36 additions and 9 deletions
|
@ -108,6 +108,7 @@ class AccountController {
|
|||
KiwiContainer().resolve(),
|
||||
account: account,
|
||||
prefController: prefController,
|
||||
serverController: serverController,
|
||||
);
|
||||
|
||||
PrefController prefController;
|
||||
|
|
|
@ -3,6 +3,7 @@ import 'dart:async';
|
|||
import 'package:logging/logging.dart';
|
||||
import 'package:nc_photos/account.dart';
|
||||
import 'package:nc_photos/controller/pref_controller.dart';
|
||||
import 'package:nc_photos/controller/server_controller.dart';
|
||||
import 'package:nc_photos/db/entity_converter.dart';
|
||||
import 'package:nc_photos/di_container.dart';
|
||||
import 'package:nc_photos/entity/file_util.dart' as file_util;
|
||||
|
@ -17,6 +18,7 @@ class MetadataController {
|
|||
this._c, {
|
||||
required this.account,
|
||||
required this.prefController,
|
||||
required this.serverController,
|
||||
}) {
|
||||
_subscriptions.add(
|
||||
prefController.isEnableClientExifChange.listen(_onSetEnableClientExif));
|
||||
|
@ -44,7 +46,12 @@ class MetadataController {
|
|||
void kickstart() {
|
||||
_log.info("[kickstart] Metadata controller enabled");
|
||||
_isEnable = true;
|
||||
if (prefController.isEnableClientExifValue && !_hasStarted) {
|
||||
// on NC28+, the service is needed to get metadata for files that are not
|
||||
// yet available the moment we queried them, and files not supported by the
|
||||
// server (if client side exif enabled).
|
||||
if ((serverController.isSupported(ServerFeature.ncMetadata) ||
|
||||
prefController.isEnableClientExifValue) &&
|
||||
!_hasStarted) {
|
||||
_startMetadataTask();
|
||||
}
|
||||
}
|
||||
|
@ -72,7 +79,7 @@ class MetadataController {
|
|||
);
|
||||
_log.info("[_startMetadataTask] Missing count: $missingCount");
|
||||
if (missingCount > 0) {
|
||||
unawaited(service.startService());
|
||||
unawaited(service.startService(prefController: prefController));
|
||||
}
|
||||
} catch (e, stackTrace) {
|
||||
_log.shout(
|
||||
|
@ -87,6 +94,7 @@ class MetadataController {
|
|||
final DiContainer _c;
|
||||
final Account account;
|
||||
final PrefController prefController;
|
||||
final ServerController serverController;
|
||||
|
||||
final _subscriptions = <StreamSubscription>[];
|
||||
var _isEnable = false;
|
||||
|
|
|
@ -2,14 +2,22 @@ part of 'service.dart';
|
|||
|
||||
class ServiceConfig {
|
||||
static Future<bool> isProcessExifWifiOnly() async {
|
||||
return Preference.getBool(_pref, _prefProcessWifiOnly, true)
|
||||
.notNull();
|
||||
return Preference.getBool(_pref, _prefProcessWifiOnly, true).notNull();
|
||||
}
|
||||
|
||||
static Future<void> setProcessExifWifiOnly(bool flag) async {
|
||||
await Preference.setBool(_pref, _prefProcessWifiOnly, flag);
|
||||
}
|
||||
|
||||
static Future<bool> isEnableClientExif() async {
|
||||
return Preference.getBool(_pref, _prefIsEnableClientExif, false).notNull();
|
||||
}
|
||||
|
||||
static Future<void> setEnableClientExif(bool flag) async {
|
||||
await Preference.setBool(_pref, _prefIsEnableClientExif, flag);
|
||||
}
|
||||
|
||||
static const _pref = "service";
|
||||
static const _prefProcessWifiOnly = "shouldProcessWifiOnly";
|
||||
static const _prefIsEnableClientExif = "isEnableClientExif";
|
||||
}
|
||||
|
|
|
@ -28,7 +28,9 @@ part 'l10n.dart';
|
|||
part 'service.g.dart';
|
||||
|
||||
/// Start the background service
|
||||
Future<void> startService() async {
|
||||
Future<void> startService({
|
||||
required PrefController prefController,
|
||||
}) async {
|
||||
_$__NpLog.log.info("[startService] Starting service");
|
||||
final service = FlutterBackgroundService();
|
||||
await service.configure(
|
||||
|
@ -46,7 +48,9 @@ Future<void> startService() async {
|
|||
);
|
||||
// sync settings
|
||||
await ServiceConfig.setProcessExifWifiOnly(
|
||||
Pref().shouldProcessExifWifiOnlyOr());
|
||||
prefController.shouldProcessExifWifiOnlyValue);
|
||||
await ServiceConfig.setEnableClientExif(
|
||||
prefController.isEnableClientExifValue);
|
||||
await service.start();
|
||||
}
|
||||
|
||||
|
|
|
@ -41,12 +41,18 @@ class _SyncByServer {
|
|||
_log.fine("[_syncDir] Syncing dir $dir");
|
||||
final files = await fileRepoRemote.list(account, dir);
|
||||
await FileSqliteCacheUpdater(db)(account, dir, remote: files);
|
||||
final isEnableClientExif = await ServiceConfig.isEnableClientExif();
|
||||
for (final f in files.where((e) => fileIds.contains(e.fdId))) {
|
||||
File? result;
|
||||
if (!_supportedMimes.contains(f.fdMime)) {
|
||||
_log.info(
|
||||
"[_syncDir] File ${f.path} (mime: ${f.fdMime}) not supported by server, fallback to client");
|
||||
result = await fallback.syncOne(f);
|
||||
if (isEnableClientExif) {
|
||||
_log.info(
|
||||
"[_syncDir] File ${f.path} (mime: ${f.fdMime}) not supported by server, fallback to client");
|
||||
result = await fallback.syncOne(f);
|
||||
} else {
|
||||
_log.info(
|
||||
"[_syncDir] File ${f.path} (mime: ${f.fdMime}) not supported by server");
|
||||
}
|
||||
} else {
|
||||
if (f.metadata != null && f.location == null) {
|
||||
result = await _syncOne(f);
|
||||
|
|
Loading…
Reference in a new issue