mirror of
https://gitlab.com/nkming2/nc-photos.git
synced 2025-01-22 08:46:18 +01:00
Migrate from kDebugMode to something we can control
This commit is contained in:
parent
df400b2690
commit
cf1ad9eb0e
22 changed files with 66 additions and 43 deletions
|
@ -3,11 +3,11 @@ import 'dart:math';
|
|||
import 'package:clock/clock.dart';
|
||||
import 'package:copy_with/copy_with.dart';
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
import 'package:np_codegen/np_codegen.dart';
|
||||
import 'package:np_collection/np_collection.dart';
|
||||
import 'package:np_common/type.dart';
|
||||
import 'package:np_log/np_log.dart';
|
||||
import 'package:np_string/np_string.dart';
|
||||
import 'package:to_string/to_string.dart';
|
||||
|
||||
|
@ -82,15 +82,15 @@ class Account with EquatableMixin {
|
|||
|
||||
final String id;
|
||||
final String scheme;
|
||||
@Format(r"${kDebugMode ? $? : '***'}")
|
||||
@Format(r"${isDevMode ? $? : '***'}")
|
||||
final String address;
|
||||
// For non LDAP users, this is the username used to sign in
|
||||
@Format(r"${kDebugMode ? $? : '***'}")
|
||||
@Format(r"${isDevMode ? $? : '***'}")
|
||||
final CiString userId;
|
||||
// Username used to sign in. For non-LDAP users, this is identical to userId
|
||||
@Format(r"${kDebugMode ? $? : '***'}")
|
||||
@Format(r"${isDevMode ? $? : '***'}")
|
||||
final String username2;
|
||||
@Format(r"${$?.isNotEmpty ? (kDebugMode ? $? : '***') : null}")
|
||||
@Format(r"${$?.isNotEmpty ? (isDevMode ? $? : '***') : null}")
|
||||
final String password;
|
||||
|
||||
@deepCopy
|
||||
|
|
|
@ -78,6 +78,6 @@ extension _$AccountUpgraderV1NpLog on AccountUpgraderV1 {
|
|||
extension _$AccountToString on Account {
|
||||
String _$toString() {
|
||||
// ignore: unnecessary_string_interpolations
|
||||
return "Account {id: $id, scheme: $scheme, address: ${kDebugMode ? address : '***'}, userId: ${kDebugMode ? userId : '***'}, username2: ${kDebugMode ? username2 : '***'}, password: ${password.isNotEmpty ? (kDebugMode ? password : '***') : null}, roots: ${roots.toReadableString()}}";
|
||||
return "Account {id: $id, scheme: $scheme, address: ${isDevMode ? address : '***'}, userId: ${isDevMode ? userId : '***'}, username2: ${isDevMode ? username2 : '***'}, password: ${password.isNotEmpty ? (isDevMode ? password : '***') : null}, roots: ${roots.toReadableString()}}";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,13 +2,13 @@
|
|||
import 'dart:convert';
|
||||
|
||||
import 'package:clock/clock.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
import 'package:nc_photos/account.dart';
|
||||
import 'package:nc_photos/entity/file_descriptor.dart';
|
||||
import 'package:nc_photos/entity/file_util.dart' as file_util;
|
||||
import 'package:nc_photos/exception.dart';
|
||||
import 'package:np_api/np_api.dart' hide NcAlbumItem;
|
||||
import 'package:np_log/np_log.dart';
|
||||
import 'package:to_string/to_string.dart';
|
||||
|
||||
part 'api_util.g.dart';
|
||||
|
@ -46,7 +46,8 @@ String getFilePreviewUrlRelative(
|
|||
// We can't use the generic file preview url because collaborative albums do
|
||||
// not create a file share for photos not belonging to you, that means you
|
||||
// can only access the file view the Photos API
|
||||
url = "index.php/apps/photos/api/v1/preview/${file.fdId}?x=$width&y=$height";
|
||||
url =
|
||||
"index.php/apps/photos/api/v1/preview/${file.fdId}?x=$width&y=$height";
|
||||
} else {
|
||||
if (file_util.isTrash(account, file)) {
|
||||
// trashbin does not support preview.png endpoint
|
||||
|
@ -225,7 +226,7 @@ class InitiateLoginPollOptions {
|
|||
return clock.now().isBefore(_validUntil);
|
||||
}
|
||||
|
||||
@Format(r"${kDebugMode ? $? : '***'}")
|
||||
@Format(r"${isDevMode ? $? : '***'}")
|
||||
final String token;
|
||||
final Uri endpoint;
|
||||
final DateTime _validUntil;
|
||||
|
@ -255,7 +256,7 @@ class AppPasswordSuccess implements AppPasswordResponse {
|
|||
|
||||
final Uri server;
|
||||
final String loginName;
|
||||
@Format(r"${kDebugMode ? appPassword : '***'}")
|
||||
@Format(r"${isDevMode ? appPassword : '***'}")
|
||||
final String appPassword;
|
||||
}
|
||||
|
||||
|
|
|
@ -16,13 +16,13 @@ extension _$InitiateLoginResponseToString on InitiateLoginResponse {
|
|||
extension _$InitiateLoginPollOptionsToString on InitiateLoginPollOptions {
|
||||
String _$toString() {
|
||||
// ignore: unnecessary_string_interpolations
|
||||
return "InitiateLoginPollOptions {token: ${kDebugMode ? token : '***'}, endpoint: $endpoint, _validUntil: $_validUntil}";
|
||||
return "InitiateLoginPollOptions {token: ${isDevMode ? token : '***'}, endpoint: $endpoint, _validUntil: $_validUntil}";
|
||||
}
|
||||
}
|
||||
|
||||
extension _$AppPasswordSuccessToString on AppPasswordSuccess {
|
||||
String _$toString() {
|
||||
// ignore: unnecessary_string_interpolations
|
||||
return "AppPasswordSuccess {server: $server, loginName: $loginName, appPassword: ${kDebugMode ? appPassword : '***'}}";
|
||||
return "AppPasswordSuccess {server: $server, loginName: $loginName, appPassword: ${isDevMode ? appPassword : '***'}}";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -93,7 +93,7 @@ void initLog() {
|
|||
}
|
||||
|
||||
np_log.initLog(
|
||||
isDebugMode: kDebugMode,
|
||||
isDebugMode: np_log.isDevMode,
|
||||
print: (log) => debugPrint(log, wrapWidth: 1024),
|
||||
);
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@ import 'package:nc_photos/use_case/list_tag.dart';
|
|||
import 'package:nc_photos/use_case/person/list_person.dart';
|
||||
import 'package:np_codegen/np_codegen.dart';
|
||||
import 'package:np_collection/np_collection.dart';
|
||||
import 'package:np_log/np_log.dart';
|
||||
import 'package:np_string/np_string.dart';
|
||||
import 'package:to_string/to_string.dart';
|
||||
import 'package:woozy_search/woozy_search.dart';
|
||||
|
@ -162,7 +163,7 @@ class HomeSearchSuggestionBloc
|
|||
emit(HomeSearchSuggestionBlocLoading(state.results));
|
||||
// doesn't work with upper case
|
||||
final results = _search.search(ev.phrase.toCaseInsensitiveString());
|
||||
if (kDebugMode) {
|
||||
if (isDevMode) {
|
||||
final str = results.map((e) => "${e.score}: ${e.text}").join("\n");
|
||||
_log.fine("[_onEventSearch] Search '${ev.phrase}':\n$str");
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ import 'package:flutter_bloc/flutter_bloc.dart';
|
|||
import 'package:logging/logging.dart';
|
||||
import 'package:np_codegen/np_codegen.dart';
|
||||
import 'package:np_collection/np_collection.dart';
|
||||
import 'package:np_log/np_log.dart';
|
||||
import 'package:np_string/np_string.dart';
|
||||
import 'package:to_string/to_string.dart';
|
||||
import 'package:woozy_search/woozy_search.dart';
|
||||
|
@ -81,7 +82,7 @@ class SearchSuggestionBloc<T>
|
|||
emit(SearchSuggestionBlocLoading(state.results));
|
||||
// doesn't work with upper case
|
||||
final results = _search.search(ev.phrase.toCaseInsensitiveString());
|
||||
if (kDebugMode) {
|
||||
if (isDevMode) {
|
||||
final str = results.map((e) => "${e.score}: ${e.text}").join("\n");
|
||||
_log.info("[_onEventSearch] Search '${ev.phrase}':\n$str");
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:nc_photos/mobile/platform.dart'
|
||||
if (dart.library.html) 'package:nc_photos/web/platform.dart' as platform;
|
||||
import 'package:np_log/np_log.dart';
|
||||
|
@ -39,8 +38,11 @@ class LogCapturer {
|
|||
static LogCapturer? _inst;
|
||||
}
|
||||
|
||||
String logFilename(String? filename) {
|
||||
if (shouldLogFileName || filename == null) {
|
||||
String logFilename(
|
||||
String? filename, {
|
||||
bool? shouldLogFileName,
|
||||
}) {
|
||||
if ((shouldLogFileName ?? isDevMode) || filename == null) {
|
||||
return "$filename";
|
||||
}
|
||||
try {
|
||||
|
@ -55,6 +57,3 @@ String logFilename(String? filename) {
|
|||
return "***";
|
||||
}
|
||||
}
|
||||
|
||||
@visibleForTesting
|
||||
bool shouldLogFileName = kDebugMode;
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
import 'package:nc_photos/account.dart';
|
||||
import 'package:nc_photos/exception.dart';
|
||||
import 'package:nc_photos/np_api_util.dart';
|
||||
import 'package:np_codegen/np_codegen.dart';
|
||||
import 'package:np_log/np_log.dart';
|
||||
import 'package:to_string/to_string.dart';
|
||||
|
||||
part 'app_password_exchange_bloc.g.dart';
|
||||
|
@ -40,7 +40,7 @@ class AppPasswordExchangeBlocSuccess extends AppPasswordExchangeBlocState {
|
|||
@override
|
||||
String toString() => _$toString();
|
||||
|
||||
@Format(r"${kDebugMode ? password : '***'}")
|
||||
@Format(r"${isDevMode ? password : '***'}")
|
||||
final String password;
|
||||
}
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@ extension _$AppPasswordExchangeBlocSuccessToString
|
|||
on AppPasswordExchangeBlocSuccess {
|
||||
String _$toString() {
|
||||
// ignore: unnecessary_string_interpolations
|
||||
return "AppPasswordExchangeBlocSuccess {password: ${kDebugMode ? password : '***'}}";
|
||||
return "AppPasswordExchangeBlocSuccess {password: ${isDevMode ? password : '***'}}";
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
import 'package:collection/collection.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
import 'package:np_codegen/np_codegen.dart';
|
||||
import 'package:np_collection/np_collection.dart';
|
||||
import 'package:np_log/np_log.dart';
|
||||
import 'package:np_string/np_string.dart';
|
||||
import 'package:woozy_search/woozy_search.dart';
|
||||
|
||||
|
@ -24,7 +24,7 @@ class Suggester<T> {
|
|||
|
||||
List<T> search(CiString phrase) {
|
||||
final results = _searcher.search(phrase.toCaseInsensitiveString());
|
||||
if (kDebugMode) {
|
||||
if (isDevMode) {
|
||||
final str = results.map((e) => "${e.score}: ${e.text}").join("\n");
|
||||
_log.info("[search] Search '$phrase':\n$str");
|
||||
}
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:kiwi/kiwi.dart';
|
||||
|
@ -13,6 +12,7 @@ import 'package:nc_photos/entity/file_util.dart' as file_util;
|
|||
import 'package:nc_photos/k.dart' as k;
|
||||
import 'package:nc_photos/snack_bar_manager.dart';
|
||||
import 'package:np_codegen/np_codegen.dart';
|
||||
import 'package:np_log/np_log.dart';
|
||||
import 'package:np_ui/np_ui.dart';
|
||||
import 'package:path/path.dart' as path_lib;
|
||||
|
||||
|
@ -226,7 +226,7 @@ class DirPickerState extends State<DirPicker> {
|
|||
if (state is LsDirBlocSuccess) {
|
||||
if (!_fillResult(_root, state)) {
|
||||
_log.shout("[_onStateChange] Failed while _fillResult" +
|
||||
(kDebugMode
|
||||
(isDevMode
|
||||
? ", root:\n${_root.toString(isDeep: true)}\nstate: ${state.root.path}"
|
||||
: ""));
|
||||
}
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
import 'package:copy_with/copy_with.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:kiwi/kiwi.dart';
|
||||
|
@ -13,6 +12,7 @@ import 'package:nc_photos/mobile/self_signed_cert_manager.dart';
|
|||
import 'package:nc_photos/snack_bar_manager.dart';
|
||||
import 'package:nc_photos/widget/page_visibility_mixin.dart';
|
||||
import 'package:np_codegen/np_codegen.dart';
|
||||
import 'package:np_log/np_log.dart';
|
||||
import 'package:np_platform_util/np_platform_util.dart';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
import 'package:to_string/to_string.dart';
|
||||
|
@ -90,7 +90,7 @@ class _WrappedDeveloperSettingsState extends State<_WrappedDeveloperSettings>
|
|||
context.read<_Bloc>().add(const _VacuumDb());
|
||||
},
|
||||
),
|
||||
if (kDebugMode) ...[
|
||||
if (isDevMode) ...[
|
||||
ListTile(
|
||||
title: const Text("Export SQLite DB"),
|
||||
onTap: () {
|
||||
|
|
|
@ -4,25 +4,41 @@ import 'package:test/test.dart';
|
|||
void main() {
|
||||
group("debug_util", () {
|
||||
group("logFilename", () {
|
||||
shouldLogFileName = false;
|
||||
|
||||
test("null", () {
|
||||
expect(logFilename(null), "null");
|
||||
expect(
|
||||
logFilename(null, shouldLogFileName: false),
|
||||
"null",
|
||||
);
|
||||
});
|
||||
test("path + name + ext", () {
|
||||
expect(logFilename("path/to/a/fancy_file.ext"), "***/fan***ile.ext");
|
||||
expect(
|
||||
logFilename("path/to/a/fancy_file.ext", shouldLogFileName: false),
|
||||
"***/fan***ile.ext",
|
||||
);
|
||||
});
|
||||
test("path + short name + ext", () {
|
||||
expect(logFilename("path/to/a/file01.ext"), "***/file01.ext");
|
||||
expect(
|
||||
logFilename("path/to/a/file01.ext", shouldLogFileName: false),
|
||||
"***/file01.ext",
|
||||
);
|
||||
});
|
||||
test("path + name", () {
|
||||
expect(logFilename("path/to/a/fancy_file"), "***/fan***ile");
|
||||
expect(
|
||||
logFilename("path/to/a/fancy_file", shouldLogFileName: false),
|
||||
"***/fan***ile",
|
||||
);
|
||||
});
|
||||
test("name + ext", () {
|
||||
expect(logFilename("fancy_file"), "fan***ile");
|
||||
expect(
|
||||
logFilename("fancy_file", shouldLogFileName: false),
|
||||
"fan***ile",
|
||||
);
|
||||
});
|
||||
test("name", () {
|
||||
expect(logFilename("fancy_file.ext"), "fan***ile.ext");
|
||||
expect(
|
||||
logFilename("fancy_file.ext", shouldLogFileName: false),
|
||||
"fan***ile.ext",
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:np_api/src/util.dart';
|
||||
import 'package:np_log/np_log.dart';
|
||||
import 'package:np_string/np_string.dart';
|
||||
import 'package:to_string/to_string.dart';
|
||||
|
||||
|
@ -23,7 +23,7 @@ class Response {
|
|||
/// Content of the response body, String if isResponseString == true during
|
||||
/// request, Uint8List otherwise
|
||||
@Format(
|
||||
r"${kDebugMode ? $?.toString().replaceAll(RegExp(r'\n\t'), '').slice(0, 200) : '...'}")
|
||||
r"${isDevMode ? $?.toString().replaceAll(RegExp(r'\n\t'), '').slice(0, 200) : '...'}")
|
||||
final dynamic body;
|
||||
}
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ part of 'type.dart';
|
|||
extension _$ResponseToString on Response {
|
||||
String _$toString() {
|
||||
// ignore: unnecessary_string_interpolations
|
||||
return "Response {statusCode: $statusCode, headers: ..., body: ${kDebugMode ? body.toString().replaceAll(RegExp(r'\n\t'), '').slice(0, 200) : '...'}}";
|
||||
return "Response {statusCode: $statusCode, headers: ..., body: ${isDevMode ? body.toString().replaceAll(RegExp(r'\n\t'), '').slice(0, 200) : '...'}}";
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ bool isHttpStatusGood(int status) => status ~/ 100 == 2;
|
|||
|
||||
void initLog() {
|
||||
np_log.initLog(
|
||||
isDebugMode: kDebugMode,
|
||||
isDebugMode: np_log.isDevMode,
|
||||
print: (log) => debugPrint(log, wrapWidth: 1024),
|
||||
);
|
||||
}
|
||||
|
|
|
@ -57,7 +57,7 @@ extension SqliteDbCompatExtension on SqliteDb {
|
|||
|
||||
_log.info(
|
||||
"[migrateV55] ${dateTimeUpdates.length} rows require updating, ${imageRemoves.length} rows require removing");
|
||||
if (kDebugMode) {
|
||||
if (isDevMode) {
|
||||
_log.fine(
|
||||
"[migrateV55] dateTimeUpdates: ${dateTimeUpdates.map((e) => e.rowId).toReadableString()}");
|
||||
_log.fine(
|
||||
|
|
|
@ -20,6 +20,7 @@ import 'package:np_db_sqlite/src/k.dart' as k;
|
|||
import 'package:np_db_sqlite/src/table.dart';
|
||||
import 'package:np_db_sqlite/src/util.dart';
|
||||
import 'package:np_geocoder/np_geocoder.dart';
|
||||
import 'package:np_log/np_log.dart';
|
||||
import 'package:np_platform_lock/np_platform_lock.dart';
|
||||
import 'package:np_platform_util/np_platform_util.dart';
|
||||
|
||||
|
|
|
@ -35,6 +35,8 @@ dependencies:
|
|||
path: ../np_db
|
||||
np_geocoder:
|
||||
path: ../np_geocoder
|
||||
np_log:
|
||||
path: ../np_log
|
||||
np_platform_lock:
|
||||
path: ../np_platform_lock
|
||||
np_platform_util:
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
library np_log;
|
||||
|
||||
export 'src/dev_mode.dart';
|
||||
export 'src/log.dart';
|
||||
|
|
1
np_log/lib/src/dev_mode.dart
Normal file
1
np_log/lib/src/dev_mode.dart
Normal file
|
@ -0,0 +1 @@
|
|||
const isDevMode = false;
|
Loading…
Reference in a new issue