Fix compatibility with very old album

This commit is contained in:
Ming Ming 2023-04-29 12:07:46 +08:00
parent 9fb8ff6cfc
commit aa49624517
4 changed files with 649 additions and 543 deletions

View file

@ -91,7 +91,7 @@ class AlbumAutoCoverProvider extends AlbumCoverProvider {
@override
FileDescriptor? getCover(Album album) {
if (coverFile == null) {
if (coverFile == null && album.provider is AlbumStaticProvider) {
// use the latest file as cover
return getCoverByItems(AlbumStaticProvider.of(album).items);
} else {

View file

@ -281,16 +281,20 @@ class AlbumUpgraderV8 implements AlbumUpgrader {
.cast<String, dynamic>();
final fd = _fileJsonToFileDescriptorJson(content);
// some very old album file may contain files w/o id
if (fd["fdId"] == null) {
if (fd["fdId"] != null) {
result["coverProvider"]["content"]["coverFile"] = fd;
} else {
result["coverProvider"]["content"] = {};
}
} else if (result["coverProvider"]["type"] == "auto") {
final content = (result["coverProvider"]["content"]["coverFile"] as Map?)
?.cast<String, dynamic>();
if (content != null) {
final fd = _fileJsonToFileDescriptorJson(content);
if (fd["fdId"] == null) {
if (fd["fdId"] != null) {
result["coverProvider"]["content"]["coverFile"] = fd;
} else {
result["coverProvider"]["content"] = {};
}
}
}
@ -305,18 +309,26 @@ class AlbumUpgraderV8 implements AlbumUpgrader {
.cast<String, dynamic>();
final converted = _fileJsonToFileDescriptorJson(
(content["coverFile"] as Map).cast<String, dynamic>());
return dbObj.copyWith(
coverProviderContent: jsonEncode({"coverFile": converted}),
);
if (converted["fdId"] != null) {
return dbObj.copyWith(
coverProviderContent: jsonEncode({"coverFile": converted}),
);
} else {
return dbObj.copyWith(coverProviderContent: "{}");
}
} 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}),
);
if (converted["fdId"] != null) {
return dbObj.copyWith(
coverProviderContent: jsonEncode({"coverFile": converted}),
);
} else {
return dbObj.copyWith(coverProviderContent: "{}");
}
}
}
return dbObj;

View file

@ -17,6 +17,8 @@ import 'package:test/test.dart';
import '../test_util.dart' as util;
part 'album_test/album_upgrader_v8.dart';
void main() {
group("Album", () {
group("fromJson", () {
@ -1810,6 +1812,7 @@ void main() {
group("auto cover", () {
test("null", _upgradeV8JsonAutoNull);
test("last modified", _upgradeV8JsonAutoLastModified);
test("no file id", _upgradeV8JsonAutoNoFileId);
});
});
@ -1824,6 +1827,7 @@ void main() {
group("auto cover", () {
test("null", _upgradeV8DbAutoNull);
test("last modified", _upgradeV8DbAutoLastModified);
test("no file id", _upgradeV8DbAutoNoFileId);
});
});
});
@ -1952,540 +1956,6 @@ void _toAppDbJsonShares() {
});
}
void _upgradeV8JsonNonManualCover() {
final json = <String, dynamic>{
"version": 8,
"lastUpdated": "2020-01-02T03:04:05.678901Z",
"provider": <String, dynamic>{
"type": "static",
"content": <String, dynamic>{
"items": [],
},
},
"coverProvider": <String, dynamic>{
"type": "memory",
"content": <String, dynamic>{
"coverFile": <String, dynamic>{
"fdPath": "remote.php/dav/files/admin/test1.jpg",
"fdId": 1,
"fdMime": null,
"fdIsArchived": false,
"fdIsFavorite": false,
"fdDateTime": "2020-01-02T03:04:05.678901Z",
},
},
},
"sortProvider": <String, dynamic>{
"type": "null",
"content": <String, dynamic>{},
},
"albumFile": <String, dynamic>{
"path": "remote.php/dav/files/admin/test1.json",
},
};
expect(const AlbumUpgraderV8().doJson(json), <String, dynamic>{
"version": 8,
"lastUpdated": "2020-01-02T03:04:05.678901Z",
"provider": <String, dynamic>{
"type": "static",
"content": <String, dynamic>{
"items": [],
},
},
"coverProvider": <String, dynamic>{
"type": "memory",
"content": <String, dynamic>{
"coverFile": <String, dynamic>{
"fdPath": "remote.php/dav/files/admin/test1.jpg",
"fdId": 1,
"fdMime": null,
"fdIsArchived": false,
"fdIsFavorite": false,
"fdDateTime": "2020-01-02T03:04:05.678901Z",
},
},
},
"sortProvider": <String, dynamic>{
"type": "null",
"content": <String, dynamic>{},
},
"albumFile": <String, dynamic>{
"path": "remote.php/dav/files/admin/test1.json",
},
});
}
void _upgradeV8JsonManualNow() {
withClock(Clock.fixed(DateTime.utc(2020, 1, 2, 3, 4, 5)), () {
final json = <String, dynamic>{
"version": 8,
"lastUpdated": "2020-01-02T03:04:05.678901Z",
"provider": <String, dynamic>{
"type": "static",
"content": <String, dynamic>{
"items": [],
},
},
"coverProvider": <String, dynamic>{
"type": "manual",
"content": <String, dynamic>{
"coverFile": <String, dynamic>{
"path": "remote.php/dav/files/admin/test1.jpg",
"fileId": 1,
},
},
},
"sortProvider": <String, dynamic>{
"type": "null",
"content": <String, dynamic>{},
},
"albumFile": <String, dynamic>{
"path": "remote.php/dav/files/admin/test1.json",
},
};
expect(const AlbumUpgraderV8().doJson(json), <String, dynamic>{
"version": 8,
"lastUpdated": "2020-01-02T03:04:05.678901Z",
"provider": <String, dynamic>{
"type": "static",
"content": <String, dynamic>{
"items": [],
},
},
"coverProvider": <String, dynamic>{
"type": "manual",
"content": <String, dynamic>{
"coverFile": <String, dynamic>{
"fdPath": "remote.php/dav/files/admin/test1.jpg",
"fdId": 1,
"fdMime": null,
"fdIsArchived": false,
"fdIsFavorite": false,
"fdDateTime": "2020-01-02T03:04:05.000Z",
},
},
},
"sortProvider": <String, dynamic>{
"type": "null",
"content": <String, dynamic>{},
},
"albumFile": <String, dynamic>{
"path": "remote.php/dav/files/admin/test1.json",
},
});
});
}
void _upgradeV8JsonManualExifTime() {
final json = <String, dynamic>{
"version": 8,
"lastUpdated": "2020-01-02T03:04:05.678901Z",
"provider": <String, dynamic>{
"type": "static",
"content": <String, dynamic>{
"items": [],
},
},
"coverProvider": <String, dynamic>{
"type": "manual",
"content": <String, dynamic>{
"coverFile": <String, dynamic>{
"path": "remote.php/dav/files/admin/test1.jpg",
"fileId": 1,
"metadata": <String, dynamic>{
"exif": <String, dynamic>{
"DateTimeOriginal": "2020:01:02 03:04:05",
},
},
},
},
},
"sortProvider": <String, dynamic>{
"type": "null",
"content": <String, dynamic>{},
},
"albumFile": <String, dynamic>{
"path": "remote.php/dav/files/admin/test1.json",
},
};
expect(const AlbumUpgraderV8().doJson(json), <String, dynamic>{
"version": 8,
"lastUpdated": "2020-01-02T03:04:05.678901Z",
"provider": <String, dynamic>{
"type": "static",
"content": <String, dynamic>{
"items": [],
},
},
"coverProvider": <String, dynamic>{
"type": "manual",
"content": <String, dynamic>{
"coverFile": <String, dynamic>{
"fdPath": "remote.php/dav/files/admin/test1.jpg",
"fdId": 1,
"fdMime": null,
"fdIsArchived": false,
"fdIsFavorite": false,
// dart does not provide a way to mock timezone
"fdDateTime": DateTime(2020, 1, 2, 3, 4, 5).toUtc().toIso8601String(),
},
},
},
"sortProvider": <String, dynamic>{
"type": "null",
"content": <String, dynamic>{},
},
"albumFile": <String, dynamic>{
"path": "remote.php/dav/files/admin/test1.json",
},
});
}
void _upgradeV8JsonAutoNull() {
final json = <String, dynamic>{
"version": 8,
"lastUpdated": "2020-01-02T03:04:05.678901Z",
"provider": <String, dynamic>{
"type": "static",
"content": <String, dynamic>{
"items": [],
},
},
"coverProvider": <String, dynamic>{
"type": "auto",
"content": <String, dynamic>{},
},
"sortProvider": <String, dynamic>{
"type": "null",
"content": <String, dynamic>{},
},
"albumFile": <String, dynamic>{
"path": "remote.php/dav/files/admin/test1.json",
},
};
expect(const AlbumUpgraderV8().doJson(json), <String, dynamic>{
"version": 8,
"lastUpdated": "2020-01-02T03:04:05.678901Z",
"provider": <String, dynamic>{
"type": "static",
"content": <String, dynamic>{
"items": [],
},
},
"coverProvider": <String, dynamic>{
"type": "auto",
"content": <String, dynamic>{},
},
"sortProvider": <String, dynamic>{
"type": "null",
"content": <String, dynamic>{},
},
"albumFile": <String, dynamic>{
"path": "remote.php/dav/files/admin/test1.json",
},
});
}
void _upgradeV8JsonAutoLastModified() {
final json = <String, dynamic>{
"version": 8,
"lastUpdated": "2020-01-02T03:04:05.678901Z",
"provider": <String, dynamic>{
"type": "static",
"content": <String, dynamic>{
"items": [],
},
},
"coverProvider": <String, dynamic>{
"type": "auto",
"content": <String, dynamic>{
"coverFile": <String, dynamic>{
"path": "remote.php/dav/files/admin/test1.jpg",
"fileId": 1,
"lastModified": "2020-01-02T03:04:05.000Z",
},
},
},
"sortProvider": <String, dynamic>{
"type": "null",
"content": <String, dynamic>{},
},
"albumFile": <String, dynamic>{
"path": "remote.php/dav/files/admin/test1.json",
},
};
expect(const AlbumUpgraderV8().doJson(json), <String, dynamic>{
"version": 8,
"lastUpdated": "2020-01-02T03:04:05.678901Z",
"provider": <String, dynamic>{
"type": "static",
"content": <String, dynamic>{
"items": [],
},
},
"coverProvider": <String, dynamic>{
"type": "auto",
"content": <String, dynamic>{
"coverFile": <String, dynamic>{
"fdPath": "remote.php/dav/files/admin/test1.jpg",
"fdId": 1,
"fdMime": null,
"fdIsArchived": false,
"fdIsFavorite": false,
"fdDateTime": "2020-01-02T03:04:05.000Z",
},
},
},
"sortProvider": <String, dynamic>{
"type": "null",
"content": <String, dynamic>{},
},
"albumFile": <String, dynamic>{
"path": "remote.php/dav/files/admin/test1.json",
},
});
}
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));
}

View file

@ -0,0 +1,624 @@
part of '../album_test.dart';
void _upgradeV8JsonNonManualCover() {
final json = <String, dynamic>{
"version": 8,
"lastUpdated": "2020-01-02T03:04:05.678901Z",
"provider": <String, dynamic>{
"type": "static",
"content": <String, dynamic>{
"items": [],
},
},
"coverProvider": <String, dynamic>{
"type": "memory",
"content": <String, dynamic>{
"coverFile": <String, dynamic>{
"fdPath": "remote.php/dav/files/admin/test1.jpg",
"fdId": 1,
"fdMime": null,
"fdIsArchived": false,
"fdIsFavorite": false,
"fdDateTime": "2020-01-02T03:04:05.678901Z",
},
},
},
"sortProvider": <String, dynamic>{
"type": "null",
"content": <String, dynamic>{},
},
"albumFile": <String, dynamic>{
"path": "remote.php/dav/files/admin/test1.json",
},
};
expect(const AlbumUpgraderV8().doJson(json), <String, dynamic>{
"version": 8,
"lastUpdated": "2020-01-02T03:04:05.678901Z",
"provider": <String, dynamic>{
"type": "static",
"content": <String, dynamic>{
"items": [],
},
},
"coverProvider": <String, dynamic>{
"type": "memory",
"content": <String, dynamic>{
"coverFile": <String, dynamic>{
"fdPath": "remote.php/dav/files/admin/test1.jpg",
"fdId": 1,
"fdMime": null,
"fdIsArchived": false,
"fdIsFavorite": false,
"fdDateTime": "2020-01-02T03:04:05.678901Z",
},
},
},
"sortProvider": <String, dynamic>{
"type": "null",
"content": <String, dynamic>{},
},
"albumFile": <String, dynamic>{
"path": "remote.php/dav/files/admin/test1.json",
},
});
}
void _upgradeV8JsonManualNow() {
withClock(Clock.fixed(DateTime.utc(2020, 1, 2, 3, 4, 5)), () {
final json = <String, dynamic>{
"version": 8,
"lastUpdated": "2020-01-02T03:04:05.678901Z",
"provider": <String, dynamic>{
"type": "static",
"content": <String, dynamic>{
"items": [],
},
},
"coverProvider": <String, dynamic>{
"type": "manual",
"content": <String, dynamic>{
"coverFile": <String, dynamic>{
"path": "remote.php/dav/files/admin/test1.jpg",
"fileId": 1,
},
},
},
"sortProvider": <String, dynamic>{
"type": "null",
"content": <String, dynamic>{},
},
"albumFile": <String, dynamic>{
"path": "remote.php/dav/files/admin/test1.json",
},
};
expect(const AlbumUpgraderV8().doJson(json), <String, dynamic>{
"version": 8,
"lastUpdated": "2020-01-02T03:04:05.678901Z",
"provider": <String, dynamic>{
"type": "static",
"content": <String, dynamic>{
"items": [],
},
},
"coverProvider": <String, dynamic>{
"type": "manual",
"content": <String, dynamic>{
"coverFile": <String, dynamic>{
"fdPath": "remote.php/dav/files/admin/test1.jpg",
"fdId": 1,
"fdMime": null,
"fdIsArchived": false,
"fdIsFavorite": false,
"fdDateTime": "2020-01-02T03:04:05.000Z",
},
},
},
"sortProvider": <String, dynamic>{
"type": "null",
"content": <String, dynamic>{},
},
"albumFile": <String, dynamic>{
"path": "remote.php/dav/files/admin/test1.json",
},
});
});
}
void _upgradeV8JsonManualExifTime() {
final json = <String, dynamic>{
"version": 8,
"lastUpdated": "2020-01-02T03:04:05.678901Z",
"provider": <String, dynamic>{
"type": "static",
"content": <String, dynamic>{
"items": [],
},
},
"coverProvider": <String, dynamic>{
"type": "manual",
"content": <String, dynamic>{
"coverFile": <String, dynamic>{
"path": "remote.php/dav/files/admin/test1.jpg",
"fileId": 1,
"metadata": <String, dynamic>{
"exif": <String, dynamic>{
"DateTimeOriginal": "2020:01:02 03:04:05",
},
},
},
},
},
"sortProvider": <String, dynamic>{
"type": "null",
"content": <String, dynamic>{},
},
"albumFile": <String, dynamic>{
"path": "remote.php/dav/files/admin/test1.json",
},
};
expect(const AlbumUpgraderV8().doJson(json), <String, dynamic>{
"version": 8,
"lastUpdated": "2020-01-02T03:04:05.678901Z",
"provider": <String, dynamic>{
"type": "static",
"content": <String, dynamic>{
"items": [],
},
},
"coverProvider": <String, dynamic>{
"type": "manual",
"content": <String, dynamic>{
"coverFile": <String, dynamic>{
"fdPath": "remote.php/dav/files/admin/test1.jpg",
"fdId": 1,
"fdMime": null,
"fdIsArchived": false,
"fdIsFavorite": false,
// dart does not provide a way to mock timezone
"fdDateTime": DateTime(2020, 1, 2, 3, 4, 5).toUtc().toIso8601String(),
},
},
},
"sortProvider": <String, dynamic>{
"type": "null",
"content": <String, dynamic>{},
},
"albumFile": <String, dynamic>{
"path": "remote.php/dav/files/admin/test1.json",
},
});
}
void _upgradeV8JsonAutoNull() {
final json = <String, dynamic>{
"version": 8,
"lastUpdated": "2020-01-02T03:04:05.678901Z",
"provider": <String, dynamic>{
"type": "static",
"content": <String, dynamic>{
"items": [],
},
},
"coverProvider": <String, dynamic>{
"type": "auto",
"content": <String, dynamic>{},
},
"sortProvider": <String, dynamic>{
"type": "null",
"content": <String, dynamic>{},
},
"albumFile": <String, dynamic>{
"path": "remote.php/dav/files/admin/test1.json",
},
};
expect(const AlbumUpgraderV8().doJson(json), <String, dynamic>{
"version": 8,
"lastUpdated": "2020-01-02T03:04:05.678901Z",
"provider": <String, dynamic>{
"type": "static",
"content": <String, dynamic>{
"items": [],
},
},
"coverProvider": <String, dynamic>{
"type": "auto",
"content": <String, dynamic>{},
},
"sortProvider": <String, dynamic>{
"type": "null",
"content": <String, dynamic>{},
},
"albumFile": <String, dynamic>{
"path": "remote.php/dav/files/admin/test1.json",
},
});
}
void _upgradeV8JsonAutoLastModified() {
final json = <String, dynamic>{
"version": 8,
"lastUpdated": "2020-01-02T03:04:05.678901Z",
"provider": <String, dynamic>{
"type": "static",
"content": <String, dynamic>{
"items": [],
},
},
"coverProvider": <String, dynamic>{
"type": "auto",
"content": <String, dynamic>{
"coverFile": <String, dynamic>{
"path": "remote.php/dav/files/admin/test1.jpg",
"fileId": 1,
"lastModified": "2020-01-02T03:04:05.000Z",
},
},
},
"sortProvider": <String, dynamic>{
"type": "null",
"content": <String, dynamic>{},
},
"albumFile": <String, dynamic>{
"path": "remote.php/dav/files/admin/test1.json",
},
};
expect(const AlbumUpgraderV8().doJson(json), <String, dynamic>{
"version": 8,
"lastUpdated": "2020-01-02T03:04:05.678901Z",
"provider": <String, dynamic>{
"type": "static",
"content": <String, dynamic>{
"items": [],
},
},
"coverProvider": <String, dynamic>{
"type": "auto",
"content": <String, dynamic>{
"coverFile": <String, dynamic>{
"fdPath": "remote.php/dav/files/admin/test1.jpg",
"fdId": 1,
"fdMime": null,
"fdIsArchived": false,
"fdIsFavorite": false,
"fdDateTime": "2020-01-02T03:04:05.000Z",
},
},
},
"sortProvider": <String, dynamic>{
"type": "null",
"content": <String, dynamic>{},
},
"albumFile": <String, dynamic>{
"path": "remote.php/dav/files/admin/test1.json",
},
});
}
void _upgradeV8JsonAutoNoFileId() {
final json = <String, dynamic>{
"version": 8,
"lastUpdated": "2020-01-02T03:04:05.678901Z",
"provider": <String, dynamic>{
"type": "static",
"content": <String, dynamic>{
"items": [],
},
},
"coverProvider": <String, dynamic>{
"type": "auto",
"content": <String, dynamic>{
"coverFile": <String, dynamic>{
"path": "remote.php/dav/files/admin/test1.jpg",
"lastModified": "2020-01-02T03:04:05.000Z",
},
},
},
"sortProvider": <String, dynamic>{
"type": "null",
"content": <String, dynamic>{},
},
"albumFile": <String, dynamic>{
"path": "remote.php/dav/files/admin/test1.json",
},
};
expect(const AlbumUpgraderV8().doJson(json), <String, dynamic>{
"version": 8,
"lastUpdated": "2020-01-02T03:04:05.678901Z",
"provider": <String, dynamic>{
"type": "static",
"content": <String, dynamic>{
"items": [],
},
},
"coverProvider": <String, dynamic>{
"type": "auto",
"content": <String, dynamic>{},
},
"sortProvider": <String, dynamic>{
"type": "null",
"content": <String, dynamic>{},
},
"albumFile": <String, dynamic>{
"path": "remote.php/dav/files/admin/test1.json",
},
});
}
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: "{}",
),
);
}
void _upgradeV8DbAutoNoFileId() {
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",
"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: "{}",
sortProviderType: "null",
sortProviderContent: "{}",
),
);
}