mirror of
https://github.com/samsonjs/immich.git
synced 2026-04-27 15:07:45 +00:00
feat(mobile): sync local asset width & height from platform (#18994)
* add width and height to sqlite entities * sync width & height from platform --------- Co-authored-by: shenlong-tanwen <139912620+shalong-tanwen@users.noreply.github.com>
This commit is contained in:
parent
e376366b7b
commit
75c24f0023
12 changed files with 47 additions and 8 deletions
|
|
@ -85,6 +85,8 @@ data class PlatformAsset (
|
||||||
val type: Long,
|
val type: Long,
|
||||||
val createdAt: Long? = null,
|
val createdAt: Long? = null,
|
||||||
val updatedAt: Long? = null,
|
val updatedAt: Long? = null,
|
||||||
|
val width: Long? = null,
|
||||||
|
val height: Long? = null,
|
||||||
val durationInSeconds: Long
|
val durationInSeconds: Long
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
|
|
@ -95,8 +97,10 @@ data class PlatformAsset (
|
||||||
val type = pigeonVar_list[2] as Long
|
val type = pigeonVar_list[2] as Long
|
||||||
val createdAt = pigeonVar_list[3] as Long?
|
val createdAt = pigeonVar_list[3] as Long?
|
||||||
val updatedAt = pigeonVar_list[4] as Long?
|
val updatedAt = pigeonVar_list[4] as Long?
|
||||||
val durationInSeconds = pigeonVar_list[5] as Long
|
val width = pigeonVar_list[5] as Long?
|
||||||
return PlatformAsset(id, name, type, createdAt, updatedAt, durationInSeconds)
|
val height = pigeonVar_list[6] as Long?
|
||||||
|
val durationInSeconds = pigeonVar_list[7] as Long
|
||||||
|
return PlatformAsset(id, name, type, createdAt, updatedAt, width, height, durationInSeconds)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fun toList(): List<Any?> {
|
fun toList(): List<Any?> {
|
||||||
|
|
@ -106,6 +110,8 @@ data class PlatformAsset (
|
||||||
type,
|
type,
|
||||||
createdAt,
|
createdAt,
|
||||||
updatedAt,
|
updatedAt,
|
||||||
|
width,
|
||||||
|
height,
|
||||||
durationInSeconds,
|
durationInSeconds,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -37,6 +37,8 @@ open class NativeSyncApiImplBase(context: Context) {
|
||||||
MediaStore.MediaColumns.DATE_MODIFIED,
|
MediaStore.MediaColumns.DATE_MODIFIED,
|
||||||
MediaStore.Files.FileColumns.MEDIA_TYPE,
|
MediaStore.Files.FileColumns.MEDIA_TYPE,
|
||||||
MediaStore.MediaColumns.BUCKET_ID,
|
MediaStore.MediaColumns.BUCKET_ID,
|
||||||
|
MediaStore.MediaColumns.WIDTH,
|
||||||
|
MediaStore.MediaColumns.HEIGHT,
|
||||||
MediaStore.MediaColumns.DURATION
|
MediaStore.MediaColumns.DURATION
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -68,6 +70,8 @@ open class NativeSyncApiImplBase(context: Context) {
|
||||||
val dateModifiedColumn = c.getColumnIndexOrThrow(MediaStore.MediaColumns.DATE_MODIFIED)
|
val dateModifiedColumn = c.getColumnIndexOrThrow(MediaStore.MediaColumns.DATE_MODIFIED)
|
||||||
val mediaTypeColumn = c.getColumnIndexOrThrow(MediaStore.Files.FileColumns.MEDIA_TYPE)
|
val mediaTypeColumn = c.getColumnIndexOrThrow(MediaStore.Files.FileColumns.MEDIA_TYPE)
|
||||||
val bucketIdColumn = c.getColumnIndexOrThrow(MediaStore.MediaColumns.BUCKET_ID)
|
val bucketIdColumn = c.getColumnIndexOrThrow(MediaStore.MediaColumns.BUCKET_ID)
|
||||||
|
val widthColumn = c.getColumnIndexOrThrow(MediaStore.MediaColumns.WIDTH)
|
||||||
|
val heightColumn = c.getColumnIndexOrThrow(MediaStore.MediaColumns.HEIGHT)
|
||||||
val durationColumn = c.getColumnIndexOrThrow(MediaStore.MediaColumns.DURATION)
|
val durationColumn = c.getColumnIndexOrThrow(MediaStore.MediaColumns.DURATION)
|
||||||
|
|
||||||
while (c.moveToNext()) {
|
while (c.moveToNext()) {
|
||||||
|
|
@ -86,12 +90,23 @@ open class NativeSyncApiImplBase(context: Context) {
|
||||||
?: c.getLong(dateAddedColumn)
|
?: c.getLong(dateAddedColumn)
|
||||||
// Date modified is seconds since epoch
|
// Date modified is seconds since epoch
|
||||||
val modifiedAt = c.getLong(dateModifiedColumn)
|
val modifiedAt = c.getLong(dateModifiedColumn)
|
||||||
|
val width = c.getInt(widthColumn).toLong()
|
||||||
|
val height = c.getInt(heightColumn).toLong()
|
||||||
// Duration is milliseconds
|
// Duration is milliseconds
|
||||||
val duration = if (mediaType == MediaStore.Files.FileColumns.MEDIA_TYPE_IMAGE) 0
|
val duration = if (mediaType == MediaStore.Files.FileColumns.MEDIA_TYPE_IMAGE) 0
|
||||||
else c.getLong(durationColumn) / 1000
|
else c.getLong(durationColumn) / 1000
|
||||||
val bucketId = c.getString(bucketIdColumn)
|
val bucketId = c.getString(bucketIdColumn)
|
||||||
|
|
||||||
val asset = PlatformAsset(id, name, mediaType.toLong(), createdAt, modifiedAt, duration)
|
val asset = PlatformAsset(
|
||||||
|
id,
|
||||||
|
name,
|
||||||
|
mediaType.toLong(),
|
||||||
|
createdAt,
|
||||||
|
modifiedAt,
|
||||||
|
width,
|
||||||
|
height,
|
||||||
|
duration
|
||||||
|
)
|
||||||
yield(AssetResult.ValidAsset(asset, bucketId))
|
yield(AssetResult.ValidAsset(asset, bucketId))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
BIN
mobile/drift_schemas/main/drift_schema_v1.json
generated
BIN
mobile/drift_schemas/main/drift_schema_v1.json
generated
Binary file not shown.
|
|
@ -135,6 +135,8 @@ struct PlatformAsset: Hashable {
|
||||||
var type: Int64
|
var type: Int64
|
||||||
var createdAt: Int64? = nil
|
var createdAt: Int64? = nil
|
||||||
var updatedAt: Int64? = nil
|
var updatedAt: Int64? = nil
|
||||||
|
var width: Int64? = nil
|
||||||
|
var height: Int64? = nil
|
||||||
var durationInSeconds: Int64
|
var durationInSeconds: Int64
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -145,7 +147,9 @@ struct PlatformAsset: Hashable {
|
||||||
let type = pigeonVar_list[2] as! Int64
|
let type = pigeonVar_list[2] as! Int64
|
||||||
let createdAt: Int64? = nilOrValue(pigeonVar_list[3])
|
let createdAt: Int64? = nilOrValue(pigeonVar_list[3])
|
||||||
let updatedAt: Int64? = nilOrValue(pigeonVar_list[4])
|
let updatedAt: Int64? = nilOrValue(pigeonVar_list[4])
|
||||||
let durationInSeconds = pigeonVar_list[5] as! Int64
|
let width: Int64? = nilOrValue(pigeonVar_list[5])
|
||||||
|
let height: Int64? = nilOrValue(pigeonVar_list[6])
|
||||||
|
let durationInSeconds = pigeonVar_list[7] as! Int64
|
||||||
|
|
||||||
return PlatformAsset(
|
return PlatformAsset(
|
||||||
id: id,
|
id: id,
|
||||||
|
|
@ -153,6 +157,8 @@ struct PlatformAsset: Hashable {
|
||||||
type: type,
|
type: type,
|
||||||
createdAt: createdAt,
|
createdAt: createdAt,
|
||||||
updatedAt: updatedAt,
|
updatedAt: updatedAt,
|
||||||
|
width: width,
|
||||||
|
height: height,
|
||||||
durationInSeconds: durationInSeconds
|
durationInSeconds: durationInSeconds
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
@ -163,6 +169,8 @@ struct PlatformAsset: Hashable {
|
||||||
type,
|
type,
|
||||||
createdAt,
|
createdAt,
|
||||||
updatedAt,
|
updatedAt,
|
||||||
|
width,
|
||||||
|
height,
|
||||||
durationInSeconds,
|
durationInSeconds,
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,9 @@ extension PHAsset {
|
||||||
type: Int64(mediaType.rawValue),
|
type: Int64(mediaType.rawValue),
|
||||||
createdAt: creationDate.map { Int64($0.timeIntervalSince1970) },
|
createdAt: creationDate.map { Int64($0.timeIntervalSince1970) },
|
||||||
updatedAt: modificationDate.map { Int64($0.timeIntervalSince1970) },
|
updatedAt: modificationDate.map { Int64($0.timeIntervalSince1970) },
|
||||||
durationInSeconds: Int64(duration)
|
width: Int64(pixelWidth),
|
||||||
|
height: Int64(pixelHeight),
|
||||||
|
durationInSeconds: Int64(duration),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -156,8 +158,6 @@ class NativeSyncApiImpl: NativeSyncApi {
|
||||||
id: asset.localIdentifier,
|
id: asset.localIdentifier,
|
||||||
name: "",
|
name: "",
|
||||||
type: 0,
|
type: 0,
|
||||||
createdAt: nil,
|
|
||||||
updatedAt: nil,
|
|
||||||
durationInSeconds: 0
|
durationInSeconds: 0
|
||||||
)
|
)
|
||||||
if (updatedAssets.contains(AssetWrapper(with: predicate))) {
|
if (updatedAssets.contains(AssetWrapper(with: predicate))) {
|
||||||
|
|
|
||||||
|
|
@ -373,6 +373,8 @@ extension on Iterable<PlatformAsset> {
|
||||||
updatedAt: e.updatedAt == null
|
updatedAt: e.updatedAt == null
|
||||||
? DateTime.now()
|
? DateTime.now()
|
||||||
: DateTime.fromMillisecondsSinceEpoch(e.updatedAt! * 1000),
|
: DateTime.fromMillisecondsSinceEpoch(e.updatedAt! * 1000),
|
||||||
|
width: e.width,
|
||||||
|
height: e.height,
|
||||||
durationInSeconds: e.durationInSeconds,
|
durationInSeconds: e.durationInSeconds,
|
||||||
),
|
),
|
||||||
).toList();
|
).toList();
|
||||||
|
|
|
||||||
Binary file not shown.
Binary file not shown.
|
|
@ -272,7 +272,9 @@ class DriftLocalAlbumRepository extends DriftDatabaseRepository
|
||||||
type: asset.type,
|
type: asset.type,
|
||||||
createdAt: Value(asset.createdAt),
|
createdAt: Value(asset.createdAt),
|
||||||
updatedAt: Value(asset.updatedAt),
|
updatedAt: Value(asset.updatedAt),
|
||||||
durationInSeconds: Value.absentIfNull(asset.durationInSeconds),
|
width: Value(asset.width),
|
||||||
|
height: Value(asset.height),
|
||||||
|
durationInSeconds: Value(asset.durationInSeconds),
|
||||||
id: asset.id,
|
id: asset.id,
|
||||||
checksum: const Value(null),
|
checksum: const Value(null),
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -6,5 +6,7 @@ mixin AssetEntityMixin on Table {
|
||||||
IntColumn get type => intEnum<AssetType>()();
|
IntColumn get type => intEnum<AssetType>()();
|
||||||
DateTimeColumn get createdAt => dateTime().withDefault(currentDateAndTime)();
|
DateTimeColumn get createdAt => dateTime().withDefault(currentDateAndTime)();
|
||||||
DateTimeColumn get updatedAt => dateTime().withDefault(currentDateAndTime)();
|
DateTimeColumn get updatedAt => dateTime().withDefault(currentDateAndTime)();
|
||||||
|
IntColumn get width => integer().nullable()();
|
||||||
|
IntColumn get height => integer().nullable()();
|
||||||
IntColumn get durationInSeconds => integer().nullable()();
|
IntColumn get durationInSeconds => integer().nullable()();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
BIN
mobile/lib/platform/native_sync_api.g.dart
generated
BIN
mobile/lib/platform/native_sync_api.g.dart
generated
Binary file not shown.
|
|
@ -20,6 +20,8 @@ class PlatformAsset {
|
||||||
// Seconds since epoch
|
// Seconds since epoch
|
||||||
final int? createdAt;
|
final int? createdAt;
|
||||||
final int? updatedAt;
|
final int? updatedAt;
|
||||||
|
final int? width;
|
||||||
|
final int? height;
|
||||||
final int durationInSeconds;
|
final int durationInSeconds;
|
||||||
|
|
||||||
const PlatformAsset({
|
const PlatformAsset({
|
||||||
|
|
@ -28,6 +30,8 @@ class PlatformAsset {
|
||||||
required this.type,
|
required this.type,
|
||||||
this.createdAt,
|
this.createdAt,
|
||||||
this.updatedAt,
|
this.updatedAt,
|
||||||
|
this.width,
|
||||||
|
this.height,
|
||||||
this.durationInSeconds = 0,
|
this.durationInSeconds = 0,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue