Skip to content

Commit db68d1a

Browse files
feat(server): add duration to SyncAssetV1 (#19196)
add duration to SyncAssetV1 Co-authored-by: shenlong-tanwen <[email protected]>
1 parent 864fe3d commit db68d1a

File tree

8 files changed

+44
-4
lines changed

8 files changed

+44
-4
lines changed

mobile/lib/infrastructure/repositories/sync_stream.repository.dart

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,8 @@ class DriftSyncStreamRepository extends DriftDatabaseRepository
169169
type: Value(asset.type.toAssetType()),
170170
createdAt: Value.absentIfNull(asset.fileCreatedAt),
171171
updatedAt: Value.absentIfNull(asset.fileModifiedAt),
172-
durationInSeconds: const Value(0),
172+
durationInSeconds:
173+
Value(asset.duration?.toDuration()?.inSeconds ?? 0),
173174
checksum: Value(asset.checksum),
174175
isFavorite: Value(asset.isFavorite),
175176
ownerId: Value(asset.ownerId),
@@ -251,3 +252,17 @@ extension on api.AssetVisibility {
251252
_ => throw Exception('Unknown AssetVisibility value: $this'),
252253
};
253254
}
255+
256+
extension on String {
257+
Duration? toDuration() {
258+
try {
259+
final parts = split(':')
260+
.map((e) => double.parse(e).toInt())
261+
.toList(growable: false);
262+
263+
return Duration(hours: parts[0], minutes: parts[1], seconds: parts[2]);
264+
} catch (_) {
265+
return null;
266+
}
267+
}
268+
}

mobile/openapi/lib/model/sync_asset_v1.dart

Lines changed: 13 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

open-api/immich-openapi-specs.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13622,6 +13622,10 @@
1362213622
"nullable": true,
1362313623
"type": "string"
1362413624
},
13625+
"duration": {
13626+
"nullable": true,
13627+
"type": "string"
13628+
},
1362513629
"fileCreatedAt": {
1362613630
"format": "date-time",
1362713631
"nullable": true,
@@ -13671,6 +13675,7 @@
1367113675
"required": [
1367213676
"checksum",
1367313677
"deletedAt",
13678+
"duration",
1367413679
"fileCreatedAt",
1367513680
"fileModifiedAt",
1367613681
"id",

server/src/database.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,7 @@ export const columns = {
352352
'isFavorite',
353353
'visibility',
354354
'updateId',
355+
'duration',
355356
],
356357
stack: ['stack.id', 'stack.primaryAssetId', 'ownerId'],
357358
syncAssetExif: [

server/src/dtos/sync.dto.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ export class SyncAssetV1 {
6565
fileCreatedAt!: Date | null;
6666
fileModifiedAt!: Date | null;
6767
localDateTime!: Date | null;
68+
duration!: string | null;
6869
@ApiProperty({ enumName: 'AssetTypeEnum', enum: AssetType })
6970
type!: AssetType;
7071
deletedAt!: Date | null;

server/src/queries/sync.repository.sql

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ select
8686
"deletedAt",
8787
"isFavorite",
8888
"visibility",
89-
"updateId"
89+
"updateId",
90+
"duration"
9091
from
9192
"assets"
9293
where
@@ -109,7 +110,8 @@ select
109110
"deletedAt",
110111
"isFavorite",
111112
"visibility",
112-
"updateId"
113+
"updateId",
114+
"duration"
113115
from
114116
"assets"
115117
where

server/test/medium/specs/sync/sync-asset.spec.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ describe.concurrent(SyncEntityType.AssetV1, () => {
3838
fileModifiedAt: date,
3939
localDateTime: date,
4040
deletedAt: null,
41+
duration: '0:10:00.00000',
4142
});
4243
await assetRepo.create(asset);
4344

@@ -61,6 +62,7 @@ describe.concurrent(SyncEntityType.AssetV1, () => {
6162
localDateTime: asset.localDateTime,
6263
type: asset.type,
6364
visibility: asset.visibility,
65+
duration: asset.duration,
6466
},
6567
type: 'AssetV1',
6668
},

server/test/medium/specs/sync/sync-partner-asset.spec.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ describe.concurrent(SyncRequestType.PartnerAssetsV1, () => {
4242
fileModifiedAt: date,
4343
localDateTime: date,
4444
deletedAt: null,
45+
duration: '0:10:00.00000',
4546
});
4647
await assetRepo.create(asset);
4748

@@ -68,6 +69,7 @@ describe.concurrent(SyncRequestType.PartnerAssetsV1, () => {
6869
localDateTime: date,
6970
type: asset.type,
7071
visibility: asset.visibility,
72+
duration: asset.duration,
7173
},
7274
type: SyncEntityType.PartnerAssetV1,
7375
},

0 commit comments

Comments
 (0)