mirror of
https://gitlab.com/nkming2/nc-photos.git
synced 2025-01-22 08:46:18 +01:00
Add Album upgrader when reading from DB
This commit is contained in:
parent
f99fc25c71
commit
0eb13273a1
4 changed files with 384 additions and 77 deletions
|
@ -46,56 +46,56 @@ class Album with EquatableMixin {
|
|||
final jsonVersion = json["version"];
|
||||
JsonObj? result = json;
|
||||
if (jsonVersion < 2) {
|
||||
result = upgraderFactory?.buildV1()?.call(result);
|
||||
result = upgraderFactory?.buildV1()?.doJson(result);
|
||||
if (result == null) {
|
||||
_log.info("[fromJson] Version $jsonVersion not compatible");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
if (jsonVersion < 3) {
|
||||
result = upgraderFactory?.buildV2()?.call(result);
|
||||
result = upgraderFactory?.buildV2()?.doJson(result);
|
||||
if (result == null) {
|
||||
_log.info("[fromJson] Version $jsonVersion not compatible");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
if (jsonVersion < 4) {
|
||||
result = upgraderFactory?.buildV3()?.call(result);
|
||||
result = upgraderFactory?.buildV3()?.doJson(result);
|
||||
if (result == null) {
|
||||
_log.info("[fromJson] Version $jsonVersion not compatible");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
if (jsonVersion < 5) {
|
||||
result = upgraderFactory?.buildV4()?.call(result);
|
||||
result = upgraderFactory?.buildV4()?.doJson(result);
|
||||
if (result == null) {
|
||||
_log.info("[fromJson] Version $jsonVersion not compatible");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
if (jsonVersion < 6) {
|
||||
result = upgraderFactory?.buildV5()?.call(result);
|
||||
result = upgraderFactory?.buildV5()?.doJson(result);
|
||||
if (result == null) {
|
||||
_log.info("[fromJson] Version $jsonVersion not compatible");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
if (jsonVersion < 7) {
|
||||
result = upgraderFactory?.buildV6()?.call(result);
|
||||
result = upgraderFactory?.buildV6()?.doJson(result);
|
||||
if (result == null) {
|
||||
_log.info("[fromJson] Version $jsonVersion not compatible");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
if (jsonVersion < 8) {
|
||||
result = upgraderFactory?.buildV7()?.call(result);
|
||||
result = upgraderFactory?.buildV7()?.doJson(result);
|
||||
if (result == null) {
|
||||
_log.info("[fromJson] Version $jsonVersion not compatible");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
if (jsonVersion < 9) {
|
||||
result = upgraderFactory?.buildV8()?.call(result);
|
||||
result = upgraderFactory?.buildV8()?.doJson(result);
|
||||
if (result == null) {
|
||||
_log.info("[fromJson] Version $jsonVersion not compatible");
|
||||
return null;
|
||||
|
|
|
@ -175,8 +175,13 @@ class AlbumSqliteDbDataSource2 implements AlbumDataSource2 {
|
|||
try {
|
||||
final queriedFile = sql.SqliteFileConverter.fromSql(
|
||||
account.userId.toString(), item["file"]);
|
||||
var dbAlbum = item["album"] as sql.Album;
|
||||
if (dbAlbum.version < 9) {
|
||||
dbAlbum = AlbumUpgraderV8(logFilePath: queriedFile.path)
|
||||
.doDb(dbAlbum)!;
|
||||
}
|
||||
return sql.SqliteAlbumConverter.fromSql(
|
||||
item["album"], queriedFile, item["shares"] ?? []);
|
||||
dbAlbum, queriedFile, item["shares"] ?? []);
|
||||
} catch (e, stackTrace) {
|
||||
_log.severe("[getAlbums] Failed while converting DB entry", e,
|
||||
stackTrace);
|
||||
|
|
|
@ -1,9 +1,12 @@
|
|||
import 'dart:convert';
|
||||
|
||||
import 'package:clock/clock.dart';
|
||||
import 'package:collection/collection.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
import 'package:nc_photos/account.dart';
|
||||
import 'package:nc_photos/entity/exif.dart';
|
||||
import 'package:nc_photos/entity/file.dart';
|
||||
import 'package:nc_photos/entity/sqlite/database.dart' as sql;
|
||||
import 'package:nc_photos/object_extension.dart';
|
||||
import 'package:np_codegen/np_codegen.dart';
|
||||
import 'package:np_common/ci_string.dart';
|
||||
|
@ -13,7 +16,8 @@ import 'package:tuple/tuple.dart';
|
|||
part 'upgrader.g.dart';
|
||||
|
||||
abstract class AlbumUpgrader {
|
||||
JsonObj? call(JsonObj json);
|
||||
JsonObj? doJson(JsonObj json);
|
||||
sql.Album? doDb(sql.Album dbObj);
|
||||
}
|
||||
|
||||
/// Upgrade v1 Album to v2
|
||||
|
@ -24,14 +28,17 @@ class AlbumUpgraderV1 implements AlbumUpgrader {
|
|||
});
|
||||
|
||||
@override
|
||||
call(JsonObj json) {
|
||||
doJson(JsonObj json) {
|
||||
// v1 album items are corrupted in one of the updates, drop it
|
||||
_log.fine("[call] Upgrade v1 Album for file: $logFilePath");
|
||||
_log.fine("[doJson] Upgrade v1 Album for file: $logFilePath");
|
||||
final result = JsonObj.from(json);
|
||||
result["items"] = [];
|
||||
return result;
|
||||
}
|
||||
|
||||
@override
|
||||
sql.Album? doDb(sql.Album dbObj) => null;
|
||||
|
||||
/// File path for logging only
|
||||
final String? logFilePath;
|
||||
}
|
||||
|
@ -44,9 +51,9 @@ class AlbumUpgraderV2 implements AlbumUpgrader {
|
|||
});
|
||||
|
||||
@override
|
||||
call(JsonObj json) {
|
||||
doJson(JsonObj json) {
|
||||
// move v2 items to v3 provider
|
||||
_log.fine("[call] Upgrade v2 Album for file: $logFilePath");
|
||||
_log.fine("[doJson] Upgrade v2 Album for file: $logFilePath");
|
||||
final result = JsonObj.from(json);
|
||||
result["provider"] = <String, dynamic>{
|
||||
"type": "static",
|
||||
|
@ -64,6 +71,9 @@ class AlbumUpgraderV2 implements AlbumUpgrader {
|
|||
return result;
|
||||
}
|
||||
|
||||
@override
|
||||
sql.Album? doDb(sql.Album dbObj) => null;
|
||||
|
||||
/// File path for logging only
|
||||
final String? logFilePath;
|
||||
}
|
||||
|
@ -76,9 +86,9 @@ class AlbumUpgraderV3 implements AlbumUpgrader {
|
|||
});
|
||||
|
||||
@override
|
||||
call(JsonObj json) {
|
||||
doJson(JsonObj json) {
|
||||
// move v3 items to v4 provider
|
||||
_log.fine("[call] Upgrade v3 Album for file: $logFilePath");
|
||||
_log.fine("[doJson] Upgrade v3 Album for file: $logFilePath");
|
||||
final result = JsonObj.from(json);
|
||||
// add the descending time sort provider
|
||||
result["sortProvider"] = <String, dynamic>{
|
||||
|
@ -90,6 +100,9 @@ class AlbumUpgraderV3 implements AlbumUpgrader {
|
|||
return result;
|
||||
}
|
||||
|
||||
@override
|
||||
sql.Album? doDb(sql.Album dbObj) => null;
|
||||
|
||||
/// File path for logging only
|
||||
final String? logFilePath;
|
||||
}
|
||||
|
@ -102,8 +115,8 @@ class AlbumUpgraderV4 implements AlbumUpgrader {
|
|||
});
|
||||
|
||||
@override
|
||||
call(JsonObj json) {
|
||||
_log.fine("[call] Upgrade v4 Album for file: $logFilePath");
|
||||
doJson(JsonObj json) {
|
||||
_log.fine("[doJson] Upgrade v4 Album for file: $logFilePath");
|
||||
final result = JsonObj.from(json);
|
||||
try {
|
||||
if (result["provider"]["type"] != "static") {
|
||||
|
@ -153,11 +166,14 @@ class AlbumUpgraderV4 implements AlbumUpgrader {
|
|||
} catch (e, stackTrace) {
|
||||
// this upgrade is not a must, if it failed then just leave it and it'll
|
||||
// be upgraded the next time the album is saved
|
||||
_log.shout("[call] Failed while upgrade", e, stackTrace);
|
||||
_log.shout("[doJson] Failed while upgrade", e, stackTrace);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@override
|
||||
sql.Album? doDb(sql.Album dbObj) => null;
|
||||
|
||||
/// File path for logging only
|
||||
final String? logFilePath;
|
||||
}
|
||||
|
@ -172,8 +188,8 @@ class AlbumUpgraderV5 implements AlbumUpgrader {
|
|||
});
|
||||
|
||||
@override
|
||||
call(JsonObj json) {
|
||||
_log.fine("[call] Upgrade v5 Album for file: $logFilePath");
|
||||
doJson(JsonObj json) {
|
||||
_log.fine("[doJson] Upgrade v5 Album for file: $logFilePath");
|
||||
final result = JsonObj.from(json);
|
||||
try {
|
||||
if (result["provider"]["type"] != "static") {
|
||||
|
@ -194,11 +210,14 @@ class AlbumUpgraderV5 implements AlbumUpgrader {
|
|||
} catch (e, stackTrace) {
|
||||
// this upgrade is not a must, if it failed then just leave it and it'll
|
||||
// be upgraded the next time the album is saved
|
||||
_log.shout("[call] Failed while upgrade", e, stackTrace);
|
||||
_log.shout("[doJson] Failed while upgrade", e, stackTrace);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@override
|
||||
sql.Album? doDb(sql.Album dbObj) => null;
|
||||
|
||||
final Account account;
|
||||
final File? albumFile;
|
||||
|
||||
|
@ -214,11 +233,14 @@ class AlbumUpgraderV6 implements AlbumUpgrader {
|
|||
});
|
||||
|
||||
@override
|
||||
call(JsonObj json) {
|
||||
_log.fine("[call] Upgrade v6 Album for file: $logFilePath");
|
||||
doJson(JsonObj json) {
|
||||
_log.fine("[doJson] Upgrade v6 Album for file: $logFilePath");
|
||||
return json;
|
||||
}
|
||||
|
||||
@override
|
||||
sql.Album? doDb(sql.Album dbObj) => null;
|
||||
|
||||
/// File path for logging only
|
||||
final String? logFilePath;
|
||||
}
|
||||
|
@ -231,11 +253,14 @@ class AlbumUpgraderV7 implements AlbumUpgrader {
|
|||
});
|
||||
|
||||
@override
|
||||
call(JsonObj json) {
|
||||
_log.fine("[call] Upgrade v7 Album for file: $logFilePath");
|
||||
doJson(JsonObj json) {
|
||||
_log.fine("[doJson] Upgrade v7 Album for file: $logFilePath");
|
||||
return json;
|
||||
}
|
||||
|
||||
@override
|
||||
sql.Album? doDb(sql.Album dbObj) => null;
|
||||
|
||||
/// File path for logging only
|
||||
final String? logFilePath;
|
||||
}
|
||||
|
@ -248,35 +273,50 @@ class AlbumUpgraderV8 implements AlbumUpgrader {
|
|||
});
|
||||
|
||||
@override
|
||||
JsonObj? call(JsonObj json) {
|
||||
_log.fine("[call] Upgrade v8 Album for file: $logFilePath");
|
||||
JsonObj? doJson(JsonObj json) {
|
||||
_log.fine("[doJson] Upgrade v8 Album for file: $logFilePath");
|
||||
final result = JsonObj.from(json);
|
||||
try {
|
||||
if (result["coverProvider"]["type"] == "manual") {
|
||||
final content = (result["coverProvider"]["content"]["coverFile"] as Map)
|
||||
.cast<String, dynamic>();
|
||||
if (result["coverProvider"]["type"] == "manual") {
|
||||
final content = (result["coverProvider"]["content"]["coverFile"] as Map)
|
||||
.cast<String, dynamic>();
|
||||
final fd = _fileJsonToFileDescriptorJson(content);
|
||||
result["coverProvider"]["content"]["coverFile"] = fd;
|
||||
} else if (result["coverProvider"]["type"] == "auto") {
|
||||
final content = (result["coverProvider"]["content"]["coverFile"] as Map?)
|
||||
?.cast<String, dynamic>();
|
||||
if (content != null) {
|
||||
final fd = _fileJsonToFileDescriptorJson(content);
|
||||
result["coverProvider"]["content"]["coverFile"] = fd;
|
||||
} else if (result["coverProvider"]["type"] == "auto") {
|
||||
final content =
|
||||
(result["coverProvider"]["content"]["coverFile"] as Map?)
|
||||
?.cast<String, dynamic>();
|
||||
if (content != null) {
|
||||
final fd = _fileJsonToFileDescriptorJson(content);
|
||||
result["coverProvider"]["content"]["coverFile"] = fd;
|
||||
}
|
||||
return result;
|
||||
} else {
|
||||
return result;
|
||||
}
|
||||
} catch (e, stackTrace) {
|
||||
// this upgrade is not a must, if it failed then just leave it and it'll
|
||||
// be upgraded the next time the album is saved
|
||||
_log.shout("[call] Failed while upgrade", e, stackTrace);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@override
|
||||
sql.Album? doDb(sql.Album dbObj) {
|
||||
_log.fine("[doDb] Upgrade v8 Album for file: $logFilePath");
|
||||
if (dbObj.coverProviderType == "manual") {
|
||||
final content = (jsonDecode(dbObj.coverProviderContent) as Map)
|
||||
.cast<String, dynamic>();
|
||||
final converted = _fileJsonToFileDescriptorJson(
|
||||
(content["coverFile"] as Map).cast<String, dynamic>());
|
||||
return dbObj.copyWith(
|
||||
coverProviderContent: jsonEncode({"coverFile": converted}),
|
||||
);
|
||||
} else if (dbObj.coverProviderType == "auto") {
|
||||
final content = (jsonDecode(dbObj.coverProviderContent) as Map)
|
||||
.cast<String, dynamic>();
|
||||
if (content["coverFile"] != null) {
|
||||
final converted = _fileJsonToFileDescriptorJson(
|
||||
(content["coverFile"] as Map).cast<String, dynamic>());
|
||||
return dbObj.copyWith(
|
||||
coverProviderContent: jsonEncode({"coverFile": converted}),
|
||||
);
|
||||
}
|
||||
}
|
||||
return dbObj;
|
||||
}
|
||||
|
||||
static JsonObj _fileJsonToFileDescriptorJson(JsonObj json) {
|
||||
return {
|
||||
"fdPath": json["path"],
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
import 'dart:convert';
|
||||
|
||||
import 'package:clock/clock.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:nc_photos/entity/album.dart';
|
||||
|
@ -8,6 +10,7 @@ import 'package:nc_photos/entity/album/sort_provider.dart';
|
|||
import 'package:nc_photos/entity/album/upgrader.dart';
|
||||
import 'package:nc_photos/entity/file.dart';
|
||||
import 'package:nc_photos/entity/file_descriptor.dart';
|
||||
import 'package:nc_photos/entity/sqlite/database.dart' as sql;
|
||||
import 'package:np_common/ci_string.dart';
|
||||
import 'package:np_common/type.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
@ -1033,7 +1036,7 @@ void main() {
|
|||
"path": "remote.php/dav/files/admin/test1.json",
|
||||
},
|
||||
};
|
||||
expect(AlbumUpgraderV1()(json), <String, dynamic>{
|
||||
expect(AlbumUpgraderV1().doJson(json), <String, dynamic>{
|
||||
"version": 1,
|
||||
"lastUpdated": "2020-01-02T03:04:05.678901Z",
|
||||
"items": [],
|
||||
|
@ -1061,7 +1064,7 @@ void main() {
|
|||
"path": "remote.php/dav/files/admin/test1.json",
|
||||
},
|
||||
};
|
||||
expect(AlbumUpgraderV2()(json), <String, dynamic>{
|
||||
expect(AlbumUpgraderV2().doJson(json), <String, dynamic>{
|
||||
"version": 2,
|
||||
"lastUpdated": "2020-01-02T03:04:05.678901Z",
|
||||
"provider": <String, dynamic>{
|
||||
|
@ -1116,7 +1119,7 @@ void main() {
|
|||
"path": "remote.php/dav/files/admin/test1.json",
|
||||
},
|
||||
};
|
||||
expect(AlbumUpgraderV3()(json), <String, dynamic>{
|
||||
expect(AlbumUpgraderV3().doJson(json), <String, dynamic>{
|
||||
"version": 3,
|
||||
"lastUpdated": "2020-01-02T03:04:05.678901Z",
|
||||
"provider": <String, dynamic>{
|
||||
|
@ -1182,7 +1185,7 @@ void main() {
|
|||
"path": "remote.php/dav/files/admin/test1.json",
|
||||
},
|
||||
};
|
||||
expect(AlbumUpgraderV4()(json), <String, dynamic>{
|
||||
expect(AlbumUpgraderV4().doJson(json), <String, dynamic>{
|
||||
"version": 4,
|
||||
"lastUpdated": "2020-01-02T03:04:05.678901Z",
|
||||
"provider": <String, dynamic>{
|
||||
|
@ -1252,7 +1255,7 @@ void main() {
|
|||
"path": "remote.php/dav/files/admin/test1.json",
|
||||
},
|
||||
};
|
||||
expect(AlbumUpgraderV4()(json), <String, dynamic>{
|
||||
expect(AlbumUpgraderV4().doJson(json), <String, dynamic>{
|
||||
"version": 4,
|
||||
"lastUpdated": "2020-01-02T03:04:05.678901Z",
|
||||
"provider": <String, dynamic>{
|
||||
|
@ -1320,7 +1323,7 @@ void main() {
|
|||
"path": "remote.php/dav/files/admin/test1.json",
|
||||
},
|
||||
};
|
||||
expect(AlbumUpgraderV4()(json), <String, dynamic>{
|
||||
expect(AlbumUpgraderV4().doJson(json), <String, dynamic>{
|
||||
"version": 4,
|
||||
"lastUpdated": "2020-01-02T03:04:05.678901Z",
|
||||
"provider": <String, dynamic>{
|
||||
|
@ -1403,7 +1406,7 @@ void main() {
|
|||
"path": "remote.php/dav/files/admin/test1.json",
|
||||
},
|
||||
};
|
||||
expect(AlbumUpgraderV4()(json), <String, dynamic>{
|
||||
expect(AlbumUpgraderV4().doJson(json), <String, dynamic>{
|
||||
"version": 4,
|
||||
"lastUpdated": "2020-01-02T03:04:05.678901Z",
|
||||
"provider": <String, dynamic>{
|
||||
|
@ -1476,7 +1479,7 @@ void main() {
|
|||
"path": "remote.php/dav/files/admin/test1.json",
|
||||
},
|
||||
};
|
||||
expect(AlbumUpgraderV4()(json), <String, dynamic>{
|
||||
expect(AlbumUpgraderV4().doJson(json), <String, dynamic>{
|
||||
"version": 4,
|
||||
"lastUpdated": "2020-01-02T03:04:05.678901Z",
|
||||
"provider": <String, dynamic>{
|
||||
|
@ -1556,7 +1559,7 @@ void main() {
|
|||
"ownerId": "admin",
|
||||
},
|
||||
};
|
||||
expect(AlbumUpgraderV5(account)(json), <String, dynamic>{
|
||||
expect(AlbumUpgraderV5(account).doJson(json), <String, dynamic>{
|
||||
"version": 5,
|
||||
"lastUpdated": "2020-01-02T03:04:05.678901Z",
|
||||
"provider": <String, dynamic>{
|
||||
|
@ -1626,7 +1629,7 @@ void main() {
|
|||
"path": "remote.php/dav/files/admin/test1.json",
|
||||
},
|
||||
};
|
||||
expect(AlbumUpgraderV5(account)(json), <String, dynamic>{
|
||||
expect(AlbumUpgraderV5(account).doJson(json), <String, dynamic>{
|
||||
"version": 5,
|
||||
"lastUpdated": "2020-01-02T03:04:05.678901Z",
|
||||
"provider": <String, dynamic>{
|
||||
|
@ -1692,7 +1695,7 @@ void main() {
|
|||
},
|
||||
},
|
||||
};
|
||||
expect(AlbumUpgraderV5(account)(json), <String, dynamic>{
|
||||
expect(AlbumUpgraderV5(account).doJson(json), <String, dynamic>{
|
||||
"version": 5,
|
||||
"lastUpdated": "2020-01-02T03:04:05.678901Z",
|
||||
"provider": <String, dynamic>{
|
||||
|
@ -1760,7 +1763,7 @@ void main() {
|
|||
ownerId: "admin".toCi(),
|
||||
);
|
||||
expect(
|
||||
AlbumUpgraderV5(account, albumFile: albumFile)(json),
|
||||
AlbumUpgraderV5(account, albumFile: albumFile).doJson(json),
|
||||
<String, dynamic>{
|
||||
"version": 5,
|
||||
"lastUpdated": "2020-01-02T03:04:05.678901Z",
|
||||
|
@ -1796,16 +1799,32 @@ void main() {
|
|||
});
|
||||
|
||||
group("AlbumUpgraderV8", () {
|
||||
test("non manual cover", _upgradeV8NonManualCover);
|
||||
group("doJson", () {
|
||||
test("non manual cover", _upgradeV8JsonNonManualCover);
|
||||
|
||||
group("manual cover", () {
|
||||
test("now", _upgradeV8ManualNow);
|
||||
test("exif time", _upgradeV8ManualExifTime);
|
||||
group("manual cover", () {
|
||||
test("now", _upgradeV8JsonManualNow);
|
||||
test("exif time", _upgradeV8JsonManualExifTime);
|
||||
});
|
||||
|
||||
group("auto cover", () {
|
||||
test("null", _upgradeV8JsonAutoNull);
|
||||
test("last modified", _upgradeV8JsonAutoLastModified);
|
||||
});
|
||||
});
|
||||
|
||||
group("auto cover", () {
|
||||
test("null", _upgradeV8AutoNull);
|
||||
test("last modified", _upgradeV8AutoLastModified);
|
||||
group("doDb", () {
|
||||
test("non manual cover", _upgradeV8DbNonManualCover);
|
||||
|
||||
group("manual cover", () {
|
||||
test("now", _upgradeV8DbManualNow);
|
||||
test("exif time", _upgradeV8DbManualExifTime);
|
||||
});
|
||||
|
||||
group("auto cover", () {
|
||||
test("null", _upgradeV8DbAutoNull);
|
||||
test("last modified", _upgradeV8DbAutoLastModified);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -1933,7 +1952,7 @@ void _toAppDbJsonShares() {
|
|||
});
|
||||
}
|
||||
|
||||
void _upgradeV8NonManualCover() {
|
||||
void _upgradeV8JsonNonManualCover() {
|
||||
final json = <String, dynamic>{
|
||||
"version": 8,
|
||||
"lastUpdated": "2020-01-02T03:04:05.678901Z",
|
||||
|
@ -1964,7 +1983,7 @@ void _upgradeV8NonManualCover() {
|
|||
"path": "remote.php/dav/files/admin/test1.json",
|
||||
},
|
||||
};
|
||||
expect(const AlbumUpgraderV8()(json), <String, dynamic>{
|
||||
expect(const AlbumUpgraderV8().doJson(json), <String, dynamic>{
|
||||
"version": 8,
|
||||
"lastUpdated": "2020-01-02T03:04:05.678901Z",
|
||||
"provider": <String, dynamic>{
|
||||
|
@ -1996,7 +2015,7 @@ void _upgradeV8NonManualCover() {
|
|||
});
|
||||
}
|
||||
|
||||
void _upgradeV8ManualNow() {
|
||||
void _upgradeV8JsonManualNow() {
|
||||
withClock(Clock.fixed(DateTime.utc(2020, 1, 2, 3, 4, 5)), () {
|
||||
final json = <String, dynamic>{
|
||||
"version": 8,
|
||||
|
@ -2024,7 +2043,7 @@ void _upgradeV8ManualNow() {
|
|||
"path": "remote.php/dav/files/admin/test1.json",
|
||||
},
|
||||
};
|
||||
expect(const AlbumUpgraderV8()(json), <String, dynamic>{
|
||||
expect(const AlbumUpgraderV8().doJson(json), <String, dynamic>{
|
||||
"version": 8,
|
||||
"lastUpdated": "2020-01-02T03:04:05.678901Z",
|
||||
"provider": <String, dynamic>{
|
||||
|
@ -2057,7 +2076,7 @@ void _upgradeV8ManualNow() {
|
|||
});
|
||||
}
|
||||
|
||||
void _upgradeV8ManualExifTime() {
|
||||
void _upgradeV8JsonManualExifTime() {
|
||||
final json = <String, dynamic>{
|
||||
"version": 8,
|
||||
"lastUpdated": "2020-01-02T03:04:05.678901Z",
|
||||
|
@ -2089,7 +2108,7 @@ void _upgradeV8ManualExifTime() {
|
|||
"path": "remote.php/dav/files/admin/test1.json",
|
||||
},
|
||||
};
|
||||
expect(const AlbumUpgraderV8()(json), <String, dynamic>{
|
||||
expect(const AlbumUpgraderV8().doJson(json), <String, dynamic>{
|
||||
"version": 8,
|
||||
"lastUpdated": "2020-01-02T03:04:05.678901Z",
|
||||
"provider": <String, dynamic>{
|
||||
|
@ -2122,7 +2141,7 @@ void _upgradeV8ManualExifTime() {
|
|||
});
|
||||
}
|
||||
|
||||
void _upgradeV8AutoNull() {
|
||||
void _upgradeV8JsonAutoNull() {
|
||||
final json = <String, dynamic>{
|
||||
"version": 8,
|
||||
"lastUpdated": "2020-01-02T03:04:05.678901Z",
|
||||
|
@ -2144,7 +2163,7 @@ void _upgradeV8AutoNull() {
|
|||
"path": "remote.php/dav/files/admin/test1.json",
|
||||
},
|
||||
};
|
||||
expect(const AlbumUpgraderV8()(json), <String, dynamic>{
|
||||
expect(const AlbumUpgraderV8().doJson(json), <String, dynamic>{
|
||||
"version": 8,
|
||||
"lastUpdated": "2020-01-02T03:04:05.678901Z",
|
||||
"provider": <String, dynamic>{
|
||||
|
@ -2167,7 +2186,7 @@ void _upgradeV8AutoNull() {
|
|||
});
|
||||
}
|
||||
|
||||
void _upgradeV8AutoLastModified() {
|
||||
void _upgradeV8JsonAutoLastModified() {
|
||||
final json = <String, dynamic>{
|
||||
"version": 8,
|
||||
"lastUpdated": "2020-01-02T03:04:05.678901Z",
|
||||
|
@ -2195,7 +2214,7 @@ void _upgradeV8AutoLastModified() {
|
|||
"path": "remote.php/dav/files/admin/test1.json",
|
||||
},
|
||||
};
|
||||
expect(const AlbumUpgraderV8()(json), <String, dynamic>{
|
||||
expect(const AlbumUpgraderV8().doJson(json), <String, dynamic>{
|
||||
"version": 8,
|
||||
"lastUpdated": "2020-01-02T03:04:05.678901Z",
|
||||
"provider": <String, dynamic>{
|
||||
|
@ -2213,7 +2232,6 @@ void _upgradeV8AutoLastModified() {
|
|||
"fdMime": null,
|
||||
"fdIsArchived": false,
|
||||
"fdIsFavorite": false,
|
||||
// dart does not provide a way to mock timezone
|
||||
"fdDateTime": "2020-01-02T03:04:05.000Z",
|
||||
},
|
||||
},
|
||||
|
@ -2228,6 +2246,250 @@ void _upgradeV8AutoLastModified() {
|
|||
});
|
||||
}
|
||||
|
||||
void _upgradeV8DbNonManualCover() {
|
||||
final dbObj = sql.Album(
|
||||
rowId: 1,
|
||||
file: 1,
|
||||
fileEtag: "8a3e0799b6f0711c23cc2d93950eceb5",
|
||||
version: 8,
|
||||
lastUpdated: DateTime.utc(2020, 1, 2, 3, 4, 5),
|
||||
name: "test1",
|
||||
providerType: "static",
|
||||
providerContent: """{"items": []}""",
|
||||
coverProviderType: "memory",
|
||||
coverProviderContent: _stripJsonString("""{
|
||||
"coverFile": {
|
||||
"fdPath": "remote.php/dav/files/admin/test1.jpg",
|
||||
"fdId": 1,
|
||||
"fdMime": null,
|
||||
"fdIsArchived": false,
|
||||
"fdIsFavorite": false,
|
||||
"fdDateTime": "2020-01-02T03:04:05.678901Z"
|
||||
}
|
||||
}"""),
|
||||
sortProviderType: "null",
|
||||
sortProviderContent: "{}",
|
||||
);
|
||||
expect(
|
||||
const AlbumUpgraderV8().doDb(dbObj),
|
||||
sql.Album(
|
||||
rowId: 1,
|
||||
file: 1,
|
||||
fileEtag: "8a3e0799b6f0711c23cc2d93950eceb5",
|
||||
version: 8,
|
||||
lastUpdated: DateTime.utc(2020, 1, 2, 3, 4, 5),
|
||||
name: "test1",
|
||||
providerType: "static",
|
||||
providerContent: """{"items": []}""",
|
||||
coverProviderType: "memory",
|
||||
coverProviderContent: _stripJsonString("""{
|
||||
"coverFile": {
|
||||
"fdPath": "remote.php/dav/files/admin/test1.jpg",
|
||||
"fdId": 1,
|
||||
"fdMime": null,
|
||||
"fdIsArchived": false,
|
||||
"fdIsFavorite": false,
|
||||
"fdDateTime": "2020-01-02T03:04:05.678901Z"
|
||||
}
|
||||
}"""),
|
||||
sortProviderType: "null",
|
||||
sortProviderContent: "{}",
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _upgradeV8DbManualNow() {
|
||||
withClock(Clock.fixed(DateTime.utc(2020, 1, 2, 3, 4, 5)), () {
|
||||
final dbObj = sql.Album(
|
||||
rowId: 1,
|
||||
file: 1,
|
||||
fileEtag: "8a3e0799b6f0711c23cc2d93950eceb5",
|
||||
version: 8,
|
||||
lastUpdated: DateTime.utc(2020, 1, 2, 3, 4, 5),
|
||||
name: "test1",
|
||||
providerType: "static",
|
||||
providerContent: """{"items": []}""",
|
||||
coverProviderType: "manual",
|
||||
coverProviderContent: _stripJsonString("""{
|
||||
"coverFile": {
|
||||
"path": "remote.php/dav/files/admin/test1.jpg",
|
||||
"fileId": 1
|
||||
}
|
||||
}"""),
|
||||
sortProviderType: "null",
|
||||
sortProviderContent: "{}",
|
||||
);
|
||||
expect(
|
||||
const AlbumUpgraderV8().doDb(dbObj),
|
||||
sql.Album(
|
||||
rowId: 1,
|
||||
file: 1,
|
||||
fileEtag: "8a3e0799b6f0711c23cc2d93950eceb5",
|
||||
version: 8,
|
||||
lastUpdated: DateTime.utc(2020, 1, 2, 3, 4, 5),
|
||||
name: "test1",
|
||||
providerType: "static",
|
||||
providerContent: """{"items": []}""",
|
||||
coverProviderType: "manual",
|
||||
coverProviderContent: _stripJsonString("""{
|
||||
"coverFile": {
|
||||
"fdPath": "remote.php/dav/files/admin/test1.jpg",
|
||||
"fdId": 1,
|
||||
"fdMime": null,
|
||||
"fdIsArchived": false,
|
||||
"fdIsFavorite": false,
|
||||
"fdDateTime": "2020-01-02T03:04:05.000Z"
|
||||
}
|
||||
}"""),
|
||||
sortProviderType: "null",
|
||||
sortProviderContent: "{}",
|
||||
),
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
void _upgradeV8DbManualExifTime() {
|
||||
final dbObj = sql.Album(
|
||||
rowId: 1,
|
||||
file: 1,
|
||||
fileEtag: "8a3e0799b6f0711c23cc2d93950eceb5",
|
||||
version: 8,
|
||||
lastUpdated: DateTime.utc(2020, 1, 2, 3, 4, 5),
|
||||
name: "test1",
|
||||
providerType: "static",
|
||||
providerContent: """{"items": []}""",
|
||||
coverProviderType: "manual",
|
||||
coverProviderContent: _stripJsonString("""{
|
||||
"coverFile": {
|
||||
"path": "remote.php/dav/files/admin/test1.jpg",
|
||||
"fileId": 1,
|
||||
"metadata": {
|
||||
"exif": {
|
||||
"DateTimeOriginal": "2020:01:02 03:04:05"
|
||||
}
|
||||
}
|
||||
}
|
||||
}"""),
|
||||
sortProviderType: "null",
|
||||
sortProviderContent: "{}",
|
||||
);
|
||||
// dart does not provide a way to mock timezone
|
||||
final dateTime = DateTime(2020, 1, 2, 3, 4, 5).toUtc().toIso8601String();
|
||||
expect(
|
||||
const AlbumUpgraderV8().doDb(dbObj),
|
||||
sql.Album(
|
||||
rowId: 1,
|
||||
file: 1,
|
||||
fileEtag: "8a3e0799b6f0711c23cc2d93950eceb5",
|
||||
version: 8,
|
||||
lastUpdated: DateTime.utc(2020, 1, 2, 3, 4, 5),
|
||||
name: "test1",
|
||||
providerType: "static",
|
||||
providerContent: """{"items": []}""",
|
||||
coverProviderType: "manual",
|
||||
coverProviderContent: _stripJsonString("""{
|
||||
"coverFile": {
|
||||
"fdPath": "remote.php/dav/files/admin/test1.jpg",
|
||||
"fdId": 1,
|
||||
"fdMime": null,
|
||||
"fdIsArchived": false,
|
||||
"fdIsFavorite": false,
|
||||
"fdDateTime": "$dateTime"
|
||||
}
|
||||
}"""),
|
||||
sortProviderType: "null",
|
||||
sortProviderContent: "{}",
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _upgradeV8DbAutoNull() {
|
||||
final dbObj = sql.Album(
|
||||
rowId: 1,
|
||||
file: 1,
|
||||
fileEtag: "8a3e0799b6f0711c23cc2d93950eceb5",
|
||||
version: 8,
|
||||
lastUpdated: DateTime.utc(2020, 1, 2, 3, 4, 5),
|
||||
name: "test1",
|
||||
providerType: "static",
|
||||
providerContent: """{"items": []}""",
|
||||
coverProviderType: "auto",
|
||||
coverProviderContent: "{}",
|
||||
sortProviderType: "null",
|
||||
sortProviderContent: "{}",
|
||||
);
|
||||
expect(
|
||||
const AlbumUpgraderV8().doDb(dbObj),
|
||||
sql.Album(
|
||||
rowId: 1,
|
||||
file: 1,
|
||||
fileEtag: "8a3e0799b6f0711c23cc2d93950eceb5",
|
||||
version: 8,
|
||||
lastUpdated: DateTime.utc(2020, 1, 2, 3, 4, 5),
|
||||
name: "test1",
|
||||
providerType: "static",
|
||||
providerContent: """{"items": []}""",
|
||||
coverProviderType: "auto",
|
||||
coverProviderContent: "{}",
|
||||
sortProviderType: "null",
|
||||
sortProviderContent: "{}",
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _upgradeV8DbAutoLastModified() {
|
||||
final dbObj = sql.Album(
|
||||
rowId: 1,
|
||||
file: 1,
|
||||
fileEtag: "8a3e0799b6f0711c23cc2d93950eceb5",
|
||||
version: 8,
|
||||
lastUpdated: DateTime.utc(2020, 1, 2, 3, 4, 5),
|
||||
name: "test1",
|
||||
providerType: "static",
|
||||
providerContent: """{"items": []}""",
|
||||
coverProviderType: "auto",
|
||||
coverProviderContent: _stripJsonString("""{
|
||||
"coverFile": {
|
||||
"path": "remote.php/dav/files/admin/test1.jpg",
|
||||
"fileId": 1,
|
||||
"lastModified": "2020-01-02T03:04:05.000Z"
|
||||
}
|
||||
}"""),
|
||||
sortProviderType: "null",
|
||||
sortProviderContent: "{}",
|
||||
);
|
||||
expect(
|
||||
const AlbumUpgraderV8().doDb(dbObj),
|
||||
sql.Album(
|
||||
rowId: 1,
|
||||
file: 1,
|
||||
fileEtag: "8a3e0799b6f0711c23cc2d93950eceb5",
|
||||
version: 8,
|
||||
lastUpdated: DateTime.utc(2020, 1, 2, 3, 4, 5),
|
||||
name: "test1",
|
||||
providerType: "static",
|
||||
providerContent: """{"items": []}""",
|
||||
coverProviderType: "auto",
|
||||
coverProviderContent: _stripJsonString("""{
|
||||
"coverFile": {
|
||||
"fdPath": "remote.php/dav/files/admin/test1.jpg",
|
||||
"fdId": 1,
|
||||
"fdMime": null,
|
||||
"fdIsArchived": false,
|
||||
"fdIsFavorite": false,
|
||||
"fdDateTime": "2020-01-02T03:04:05.000Z"
|
||||
}
|
||||
}"""),
|
||||
sortProviderType: "null",
|
||||
sortProviderContent: "{}",
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
String _stripJsonString(String str) {
|
||||
return jsonEncode(jsonDecode(str));
|
||||
}
|
||||
|
||||
class _NullAlbumUpgraderFactory extends AlbumUpgraderFactory {
|
||||
const _NullAlbumUpgraderFactory();
|
||||
|
||||
|
|
Loading…
Reference in a new issue