mirror of
https://github.com/gabehf/Fladder.git
synced 2026-03-07 21:48:14 -08:00
chore:cleanup-packages breaking: remove isar (#474)
Co-authored-by: PartyDonut <PartyDonut@users.noreply.github.com>
This commit is contained in:
parent
ab6182f69d
commit
6357b9843c
81 changed files with 31400 additions and 25673 deletions
|
|
@ -14,7 +14,7 @@ final applicationInfoProvider = StateProvider<ApplicationInfo>((ref) {
|
|||
});
|
||||
|
||||
@Freezed(toJson: false, fromJson: false)
|
||||
class ApplicationInfo with _$ApplicationInfo {
|
||||
abstract class ApplicationInfo with _$ApplicationInfo {
|
||||
const ApplicationInfo._();
|
||||
|
||||
factory ApplicationInfo({
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
// coverage:ignore-file
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
// coverage:ignore-file
|
||||
// ignore_for_file: type=lint
|
||||
// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark
|
||||
|
||||
|
|
@ -9,23 +9,183 @@ part of 'application_info.dart';
|
|||
// FreezedGenerator
|
||||
// **************************************************************************
|
||||
|
||||
// dart format off
|
||||
T _$identity<T>(T value) => value;
|
||||
|
||||
final _privateConstructorUsedError = UnsupportedError(
|
||||
'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#adding-getters-and-methods-to-our-models');
|
||||
|
||||
/// @nodoc
|
||||
mixin _$ApplicationInfo {
|
||||
String get name => throw _privateConstructorUsedError;
|
||||
String get version => throw _privateConstructorUsedError;
|
||||
String get buildNumber => throw _privateConstructorUsedError;
|
||||
String get os => throw _privateConstructorUsedError;
|
||||
String get name;
|
||||
String get version;
|
||||
String get buildNumber;
|
||||
String get os;
|
||||
}
|
||||
|
||||
/// Adds pattern-matching-related methods to [ApplicationInfo].
|
||||
extension ApplicationInfoPatterns on ApplicationInfo {
|
||||
/// A variant of `map` that fallback to returning `orElse`.
|
||||
///
|
||||
/// It is equivalent to doing:
|
||||
/// ```dart
|
||||
/// switch (sealedClass) {
|
||||
/// case final Subclass value:
|
||||
/// return ...;
|
||||
/// case _:
|
||||
/// return orElse();
|
||||
/// }
|
||||
/// ```
|
||||
|
||||
@optionalTypeArgs
|
||||
TResult maybeMap<TResult extends Object?>(
|
||||
TResult Function(_ApplicationInfo value)? $default, {
|
||||
required TResult orElse(),
|
||||
}) {
|
||||
final _that = this;
|
||||
switch (_that) {
|
||||
case _ApplicationInfo() when $default != null:
|
||||
return $default(_that);
|
||||
case _:
|
||||
return orElse();
|
||||
}
|
||||
}
|
||||
|
||||
/// A `switch`-like method, using callbacks.
|
||||
///
|
||||
/// Callbacks receives the raw object, upcasted.
|
||||
/// It is equivalent to doing:
|
||||
/// ```dart
|
||||
/// switch (sealedClass) {
|
||||
/// case final Subclass value:
|
||||
/// return ...;
|
||||
/// case final Subclass2 value:
|
||||
/// return ...;
|
||||
/// }
|
||||
/// ```
|
||||
|
||||
@optionalTypeArgs
|
||||
TResult map<TResult extends Object?>(
|
||||
TResult Function(_ApplicationInfo value) $default,
|
||||
) {
|
||||
final _that = this;
|
||||
switch (_that) {
|
||||
case _ApplicationInfo():
|
||||
return $default(_that);
|
||||
case _:
|
||||
throw StateError('Unexpected subclass');
|
||||
}
|
||||
}
|
||||
|
||||
/// A variant of `map` that fallback to returning `null`.
|
||||
///
|
||||
/// It is equivalent to doing:
|
||||
/// ```dart
|
||||
/// switch (sealedClass) {
|
||||
/// case final Subclass value:
|
||||
/// return ...;
|
||||
/// case _:
|
||||
/// return null;
|
||||
/// }
|
||||
/// ```
|
||||
|
||||
@optionalTypeArgs
|
||||
TResult? mapOrNull<TResult extends Object?>(
|
||||
TResult? Function(_ApplicationInfo value)? $default,
|
||||
) {
|
||||
final _that = this;
|
||||
switch (_that) {
|
||||
case _ApplicationInfo() when $default != null:
|
||||
return $default(_that);
|
||||
case _:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// A variant of `when` that fallback to an `orElse` callback.
|
||||
///
|
||||
/// It is equivalent to doing:
|
||||
/// ```dart
|
||||
/// switch (sealedClass) {
|
||||
/// case Subclass(:final field):
|
||||
/// return ...;
|
||||
/// case _:
|
||||
/// return orElse();
|
||||
/// }
|
||||
/// ```
|
||||
|
||||
@optionalTypeArgs
|
||||
TResult maybeWhen<TResult extends Object?>(
|
||||
TResult Function(
|
||||
String name, String version, String buildNumber, String os)?
|
||||
$default, {
|
||||
required TResult orElse(),
|
||||
}) {
|
||||
final _that = this;
|
||||
switch (_that) {
|
||||
case _ApplicationInfo() when $default != null:
|
||||
return $default(_that.name, _that.version, _that.buildNumber, _that.os);
|
||||
case _:
|
||||
return orElse();
|
||||
}
|
||||
}
|
||||
|
||||
/// A `switch`-like method, using callbacks.
|
||||
///
|
||||
/// As opposed to `map`, this offers destructuring.
|
||||
/// It is equivalent to doing:
|
||||
/// ```dart
|
||||
/// switch (sealedClass) {
|
||||
/// case Subclass(:final field):
|
||||
/// return ...;
|
||||
/// case Subclass2(:final field2):
|
||||
/// return ...;
|
||||
/// }
|
||||
/// ```
|
||||
|
||||
@optionalTypeArgs
|
||||
TResult when<TResult extends Object?>(
|
||||
TResult Function(String name, String version, String buildNumber, String os)
|
||||
$default,
|
||||
) {
|
||||
final _that = this;
|
||||
switch (_that) {
|
||||
case _ApplicationInfo():
|
||||
return $default(_that.name, _that.version, _that.buildNumber, _that.os);
|
||||
case _:
|
||||
throw StateError('Unexpected subclass');
|
||||
}
|
||||
}
|
||||
|
||||
/// A variant of `when` that fallback to returning `null`
|
||||
///
|
||||
/// It is equivalent to doing:
|
||||
/// ```dart
|
||||
/// switch (sealedClass) {
|
||||
/// case Subclass(:final field):
|
||||
/// return ...;
|
||||
/// case _:
|
||||
/// return null;
|
||||
/// }
|
||||
/// ```
|
||||
|
||||
@optionalTypeArgs
|
||||
TResult? whenOrNull<TResult extends Object?>(
|
||||
TResult? Function(
|
||||
String name, String version, String buildNumber, String os)?
|
||||
$default,
|
||||
) {
|
||||
final _that = this;
|
||||
switch (_that) {
|
||||
case _ApplicationInfo() when $default != null:
|
||||
return $default(_that.name, _that.version, _that.buildNumber, _that.os);
|
||||
case _:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
|
||||
class _$ApplicationInfoImpl extends _ApplicationInfo {
|
||||
_$ApplicationInfoImpl(
|
||||
class _ApplicationInfo extends ApplicationInfo {
|
||||
_ApplicationInfo(
|
||||
{required this.name,
|
||||
required this.version,
|
||||
required this.buildNumber,
|
||||
|
|
@ -42,20 +202,4 @@ class _$ApplicationInfoImpl extends _ApplicationInfo {
|
|||
final String os;
|
||||
}
|
||||
|
||||
abstract class _ApplicationInfo extends ApplicationInfo {
|
||||
factory _ApplicationInfo(
|
||||
{required final String name,
|
||||
required final String version,
|
||||
required final String buildNumber,
|
||||
required final String os}) = _$ApplicationInfoImpl;
|
||||
_ApplicationInfo._() : super._();
|
||||
|
||||
@override
|
||||
String get name;
|
||||
@override
|
||||
String get version;
|
||||
@override
|
||||
String get buildNumber;
|
||||
@override
|
||||
String get os;
|
||||
}
|
||||
// dart format on
|
||||
|
|
|
|||
|
|
@ -1,82 +0,0 @@
|
|||
import 'dart:convert';
|
||||
import 'dart:developer';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
|
||||
import 'package:drift/drift.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:isar/isar.dart';
|
||||
import 'package:path/path.dart' as path;
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
|
||||
import 'package:fladder/models/syncing/database_item.dart';
|
||||
import 'package:fladder/models/syncing/i_synced_item.dart';
|
||||
import 'package:fladder/models/syncing/sync_item.dart';
|
||||
|
||||
Future<void> isarMigration(Ref ref, AppDatabase db, String savePath) async {
|
||||
if (kIsWeb) return;
|
||||
|
||||
//Return if the database is already migrated or not empty
|
||||
final isNotEmtpy = await db.select(db.databaseItems).get().then((value) => value.isNotEmpty);
|
||||
if (isNotEmtpy) {
|
||||
log('Drift database is not empty, skipping migration');
|
||||
return;
|
||||
}
|
||||
|
||||
//Open isar database
|
||||
final applicationDirectory = await getApplicationDocumentsDirectory();
|
||||
final isarPath = Directory(path.joinAll([applicationDirectory.path, 'Fladder', 'Database']));
|
||||
await isarPath.create(recursive: true);
|
||||
final isar = Isar.open(
|
||||
schemas: [ISyncedItemSchema],
|
||||
directory: isarPath.path,
|
||||
);
|
||||
|
||||
//Fetch all synced items from the old database
|
||||
List<SyncedItem> items = isar.iSyncedItems
|
||||
.where()
|
||||
.findAll()
|
||||
.map((e) => SyncedItem.fromIsar(e, path.joinAll([savePath, e.userId ?? "Unkown User"])))
|
||||
.toList();
|
||||
|
||||
//Clear any missing paths
|
||||
items = items.where((e) => e.path != null ? Directory(e.path!).existsSync() : false).toList();
|
||||
|
||||
//Convert to drift database items
|
||||
final driftItems = items.map(
|
||||
(item) => DatabaseItemsCompanion(
|
||||
id: Value(item.id),
|
||||
parentId: Value(item.parentId),
|
||||
syncing: Value(item.syncing),
|
||||
userId: Value(item.userId),
|
||||
path: Value(item.path),
|
||||
fileSize: Value(item.fileSize),
|
||||
sortName: Value(item.sortName),
|
||||
videoFileName: Value(item.videoFileName),
|
||||
trickPlayModel: Value(item.fTrickPlayModel != null ? jsonEncode(item.fTrickPlayModel?.toJson()) : null),
|
||||
mediaSegments: Value(item.mediaSegments != null ? jsonEncode(item.mediaSegments?.toJson()) : null),
|
||||
images: Value(item.fImages != null ? jsonEncode(item.fImages?.toJson()) : null),
|
||||
chapters: Value(jsonEncode(item.fChapters.map((e) => e.toJson()).toList())),
|
||||
subtitles: Value(jsonEncode(item.subtitles.map((e) => e.toJson()).toList())),
|
||||
userData: Value(item.userData != null ? jsonEncode(item.userData?.toJson()) : null),
|
||||
),
|
||||
);
|
||||
|
||||
await db.batch((batch) {
|
||||
batch.insertAll(
|
||||
db.databaseItems,
|
||||
driftItems,
|
||||
mode: InsertMode.insertOrReplace,
|
||||
);
|
||||
});
|
||||
|
||||
isar.close();
|
||||
|
||||
//Delete isar database after a few versions?
|
||||
// await Future.delayed(const Duration(seconds: 1));
|
||||
// if (await isarPath.exists()) {
|
||||
// log('Deleting old Fladder base folder: ${isarPath.path}');
|
||||
// await isarPath.delete(recursive: true);
|
||||
// }
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue