something

This commit is contained in:
Dr-Blank 2024-05-08 05:03:49 -04:00
parent dbf4ce1959
commit a720c977c2
No known key found for this signature in database
GPG key ID: 7452CC63F210A266
115 changed files with 8819 additions and 1 deletions

View file

@ -0,0 +1,22 @@
import 'package:flutter/foundation.dart' show immutable;
import 'package:hive/hive.dart';
import 'package:whispering_pages/settings/models/models.dart';
@immutable
class AvailableHiveBoxes {
const AvailableHiveBoxes._();
/// Box for storing user preferences as [AppSettings]
static final userPrefsBox = Hive.box<AppSettings>(name: 'userPrefs');
/// Box for storing [ApiSettings]
static final apiSettingsBox = Hive.box<ApiSettings>(name: 'apiSettings');
/// stores the a list of [AudiobookShelfServer]
static final serverBox =
Hive.box<AudiobookShelfServer>(name: 'audiobookShelfServer');
/// stores the a list of [AuthenticatedUser]
static final authenticatedUserBox =
Hive.box<AuthenticatedUser>(name: 'authenticatedUser');
}

1009
lib/db/cache/image.g.dart vendored Normal file

File diff suppressed because it is too large Load diff

39
lib/db/cache/schemas/image.dart vendored Normal file
View file

@ -0,0 +1,39 @@
import 'package:isar/isar.dart';
part '../image.g.dart';
/// Represents a cover image for a library item
///
/// stores 2 paths, one is thumbnail and the other is the full size image
/// both are optional
/// also stores last fetched date for the image
/// Id is passed as a parameter to the collection annotation (the lib_item_id)
/// also index the id
/// This is because the image is a part of the library item and the library item
/// is the parent of the image
@Collection(ignore: {'path'})
@Name('CacheImage')
class Image {
@Id()
int id;
String? thumbnailPath;
String? imagePath;
DateTime lastSaved;
Image({
required this.id,
this.thumbnailPath,
this.imagePath,
}) : lastSaved = DateTime.now();
/// returns the path to the image
String? get path => thumbnailPath ?? imagePath;
/// automatically updates the last fetched date when saving a new path
void updatePath(String? thumbnailPath, String? imagePath) async {
this.thumbnailPath = thumbnailPath;
this.imagePath = imagePath;
lastSaved = DateTime.now();
}
}

19
lib/db/cache_manager.dart Normal file
View file

@ -0,0 +1,19 @@
import 'package:flutter_cache_manager/flutter_cache_manager.dart';
final imageCacheManager = CacheManager(
Config(
'image_cache_manager',
stalePeriod: const Duration(days: 365 * 10),
repo: JsonCacheInfoRepository(),
maxNrOfCacheObjects: 1000,
),
);
final apiResponseCacheManager = CacheManager(
Config(
'api_response_cache_manager',
stalePeriod: const Duration(days: 1),
repo: JsonCacheInfoRepository(),
maxNrOfCacheObjects: 1000,
),
);

26
lib/db/init.dart Normal file
View file

@ -0,0 +1,26 @@
// does the initial setup of the storage
import 'dart:io';
import 'package:hive/hive.dart';
import 'package:path/path.dart' as p;
import 'package:path_provider/path_provider.dart';
import 'package:whispering_pages/settings/constants.dart';
import 'register_models.dart';
Future initStorage() async {
final dir = await getApplicationDocumentsDirectory();
// use whispering_pages as the directory for hive
final storageDir = Directory(p.join(
dir.path,
AppMetadata.appName.toLowerCase().replaceAll(' ', '_'),
),
);
await storageDir.create(recursive: true);
Hive.defaultDirectory = storageDir.path;
await registerModels();
}

View file

@ -0,0 +1,22 @@
import 'package:hive/hive.dart';
import 'package:whispering_pages/settings/models/models.dart';
// register all models to Hive for serialization
Future registerModels() async {
Hive.registerAdapter<AppSettings>(
'AppSettings',
((json) => AppSettings.fromJson(json)),
);
Hive.registerAdapter<ApiSettings>(
'ApiSettings',
((json) => ApiSettings.fromJson(json)),
);
Hive.registerAdapter<AudiobookShelfServer>(
'AudiobookShelfServer',
((json) => AudiobookShelfServer.fromJson(json)),
);
Hive.registerAdapter<AuthenticatedUser>(
'AuthenticatedUser',
((json) => AuthenticatedUser.fromJson(json)),
);
}

3
lib/db/storage.dart Normal file
View file

@ -0,0 +1,3 @@
export 'available_boxes.dart';
export 'init.dart';
export 'register_models.dart';