add proper logging

This commit is contained in:
shenlong-tanwen
2024-08-21 23:43:48 +05:30
parent 1631df70e9
commit 75448ce56b
37 changed files with 923 additions and 224 deletions
+1 -4
View File
@@ -24,7 +24,6 @@ extension LevelExtension on Level {
@immutable
class LogMessage {
final int id;
final String content;
final LogLevel level;
final DateTime createdAt;
@@ -33,7 +32,6 @@ class LogMessage {
final String? stack;
const LogMessage({
required this.id,
required this.content,
required this.level,
required this.createdAt,
@@ -51,8 +49,7 @@ class LogMessage {
@override
int get hashCode {
return id.hashCode ^
content.hashCode ^
return content.hashCode ^
level.hashCode ^
createdAt.hashCode ^
logger.hashCode ^
+22 -2
View File
@@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import 'package:immich_mobile/domain/interfaces/store.interface.dart';
import 'package:immich_mobile/domain/models/user.model.dart';
import 'package:immich_mobile/domain/utils/store_converters.dart';
import 'package:immich_mobile/presentation/modules/theme/models/app_theme.model.dart';
@@ -21,14 +22,33 @@ class StoreValue<T> {
int get hashCode => id.hashCode ^ value.hashCode;
}
class StoreKeyNotFoundException implements Exception {
final StoreKey key;
const StoreKeyNotFoundException(this.key);
@override
String toString() => "Key '${key.name}' not found in Store";
}
/// Key for each possible value in the `Store`.
/// Also stores the converter to convert the value to and from the store and the type of value stored in the Store
enum StoreKey<T, U> {
serverEndpoint<String, String>(
0,
converter: StorePrimitiveConverter(),
converter: StoreStringConverter(),
type: String,
),
accessToken<String, String>(
1,
converter: StoreStringConverter(),
type: String,
),
currentUser<User, String>(
2,
converter: StoreUserConverter(),
type: String,
),
// App settings
appTheme<AppTheme, int>(
1000,
converter: StoreEnumConverter(AppTheme.values),
@@ -44,7 +64,7 @@ enum StoreKey<T, U> {
const StoreKey(this.id, {required this.converter, required this.type});
final int id;
/// Type is also stored here easily fetch it during runtime
/// Primitive Type is also stored here to easily fetch it during runtime
final Type type;
final IStoreConverter<T, U> converter;
}
+187
View File
@@ -0,0 +1,187 @@
import 'dart:ui';
import 'package:openapi/openapi.dart' as api;
class User {
const User({
required this.id,
required this.updatedAt,
required this.name,
required this.email,
required this.isAdmin,
required this.quotaSizeInBytes,
required this.quotaUsageInBytes,
required this.inTimeline,
required this.profileImagePath,
required this.memoryEnabled,
required this.avatarColor,
});
final String id;
final DateTime updatedAt;
final String name;
final String email;
final bool isAdmin;
// Quota
final int quotaSizeInBytes;
final int quotaUsageInBytes;
// Sharing
final bool inTimeline;
// User prefs
final String profileImagePath;
final bool memoryEnabled;
final UserAvatarColor avatarColor;
User copyWith({
String? id,
DateTime? updatedAt,
String? name,
String? email,
bool? isAdmin,
int? quotaSizeInBytes,
int? quotaUsageInBytes,
bool? inTimeline,
String? profileImagePath,
bool? memoryEnabled,
UserAvatarColor? avatarColor,
}) {
return User(
id: id ?? this.id,
updatedAt: updatedAt ?? this.updatedAt,
name: name ?? this.name,
email: email ?? this.email,
isAdmin: isAdmin ?? this.isAdmin,
quotaSizeInBytes: quotaSizeInBytes ?? this.quotaSizeInBytes,
quotaUsageInBytes: quotaUsageInBytes ?? this.quotaUsageInBytes,
inTimeline: inTimeline ?? this.inTimeline,
profileImagePath: profileImagePath ?? this.profileImagePath,
memoryEnabled: memoryEnabled ?? this.memoryEnabled,
avatarColor: avatarColor ?? this.avatarColor,
);
}
@override
String toString() {
return 'User(id: $id, updatedAt: $updatedAt, name: $name, email: $email, isAdmin: $isAdmin, quotaSizeInBytes: $quotaSizeInBytes, quotaUsageInBytes: $quotaUsageInBytes, inTimeline: $inTimeline, profileImagePath: $profileImagePath, memoryEnabled: $memoryEnabled, avatarColor: $avatarColor)';
}
@override
bool operator ==(covariant User other) {
if (identical(this, other)) return true;
return other.id == id &&
other.updatedAt == updatedAt &&
other.name == name &&
other.email == email &&
other.isAdmin == isAdmin &&
other.quotaSizeInBytes == quotaSizeInBytes &&
other.quotaUsageInBytes == quotaUsageInBytes &&
other.inTimeline == inTimeline &&
other.profileImagePath == profileImagePath &&
other.memoryEnabled == memoryEnabled &&
other.avatarColor == avatarColor;
}
@override
int get hashCode {
return id.hashCode ^
updatedAt.hashCode ^
name.hashCode ^
email.hashCode ^
isAdmin.hashCode ^
quotaSizeInBytes.hashCode ^
quotaUsageInBytes.hashCode ^
inTimeline.hashCode ^
profileImagePath.hashCode ^
memoryEnabled.hashCode ^
avatarColor.hashCode;
}
factory User.fromAdminDto(
api.UserAdminResponseDto userDto, [
api.UserPreferencesResponseDto? userPreferences,
]) {
return User(
id: userDto.id,
updatedAt: DateTime.now(),
name: userDto.name,
email: userDto.email,
isAdmin: userDto.isAdmin,
quotaSizeInBytes: userDto.quotaSizeInBytes ?? 0,
quotaUsageInBytes: userDto.quotaUsageInBytes ?? 0,
inTimeline: true,
profileImagePath: userDto.profileImagePath,
memoryEnabled: userPreferences?.memories.enabled ?? true,
avatarColor: userDto.avatarColor.toEnum(),
);
}
}
enum UserAvatarColor {
// do not change this order or reuse indices for other purposes, adding is OK
primary,
pink,
red,
yellow,
blue,
green,
purple,
orange,
gray,
amber,
}
extension AvatarColorEnumHelper on api.UserAvatarColor {
UserAvatarColor toEnum() {
switch (this) {
case api.UserAvatarColor.primary:
return UserAvatarColor.primary;
case api.UserAvatarColor.pink:
return UserAvatarColor.pink;
case api.UserAvatarColor.red:
return UserAvatarColor.red;
case api.UserAvatarColor.yellow:
return UserAvatarColor.yellow;
case api.UserAvatarColor.blue:
return UserAvatarColor.blue;
case api.UserAvatarColor.green:
return UserAvatarColor.green;
case api.UserAvatarColor.purple:
return UserAvatarColor.purple;
case api.UserAvatarColor.orange:
return UserAvatarColor.orange;
case api.UserAvatarColor.gray:
return UserAvatarColor.gray;
case api.UserAvatarColor.amber:
return UserAvatarColor.amber;
}
return UserAvatarColor.primary;
}
}
extension AvatarColorToColorHelper on UserAvatarColor {
Color toColor([bool isDarkTheme = false]) {
switch (this) {
case UserAvatarColor.primary:
return isDarkTheme ? const Color(0xFFABCBFA) : const Color(0xFF4250AF);
case UserAvatarColor.pink:
return const Color.fromARGB(255, 244, 114, 182);
case UserAvatarColor.red:
return const Color.fromARGB(255, 239, 68, 68);
case UserAvatarColor.yellow:
return const Color.fromARGB(255, 234, 179, 8);
case UserAvatarColor.blue:
return const Color.fromARGB(255, 59, 130, 246);
case UserAvatarColor.green:
return const Color.fromARGB(255, 22, 163, 74);
case UserAvatarColor.purple:
return const Color.fromARGB(255, 147, 51, 234);
case UserAvatarColor.orange:
return const Color.fromARGB(255, 234, 88, 12);
case UserAvatarColor.gray:
return const Color.fromARGB(255, 75, 85, 99);
case UserAvatarColor.amber:
return const Color.fromARGB(255, 217, 119, 6);
}
}
}