server: add originalFileName to SyncAssetV1

This commit is contained in:
shenlong-tanwen 2025-04-21 16:35:55 +05:30
parent b44cfe5d1c
commit 3e5a944143
7 changed files with 24 additions and 2 deletions

View File

@ -165,7 +165,7 @@ class DriftSyncStreamRepository extends DriftDatabaseRepository
_db.batch((batch) {
for (final asset in data) {
final companion = RemoteAssetEntityCompanion(
name: const Value(''), // TODO: Needed from the server
name: Value(asset.originalFileName),
type: Value(asset.type.toAssetType()),
createdAt: Value.absentIfNull(asset.fileCreatedAt),
updatedAt: Value.absentIfNull(asset.fileModifiedAt),

View File

@ -21,6 +21,7 @@ class SyncAssetV1 {
required this.isFavorite,
required this.isVisible,
required this.localDateTime,
required this.originalFileName,
required this.ownerId,
required this.thumbhash,
required this.type,
@ -42,6 +43,8 @@ class SyncAssetV1 {
DateTime? localDateTime;
String originalFileName;
String ownerId;
String? thumbhash;
@ -58,6 +61,7 @@ class SyncAssetV1 {
other.isFavorite == isFavorite &&
other.isVisible == isVisible &&
other.localDateTime == localDateTime &&
other.originalFileName == originalFileName &&
other.ownerId == ownerId &&
other.thumbhash == thumbhash &&
other.type == type;
@ -73,12 +77,13 @@ class SyncAssetV1 {
(isFavorite.hashCode) +
(isVisible.hashCode) +
(localDateTime == null ? 0 : localDateTime!.hashCode) +
(originalFileName.hashCode) +
(ownerId.hashCode) +
(thumbhash == null ? 0 : thumbhash!.hashCode) +
(type.hashCode);
@override
String toString() => 'SyncAssetV1[checksum=$checksum, deletedAt=$deletedAt, fileCreatedAt=$fileCreatedAt, fileModifiedAt=$fileModifiedAt, id=$id, isFavorite=$isFavorite, isVisible=$isVisible, localDateTime=$localDateTime, ownerId=$ownerId, thumbhash=$thumbhash, type=$type]';
String toString() => 'SyncAssetV1[checksum=$checksum, deletedAt=$deletedAt, fileCreatedAt=$fileCreatedAt, fileModifiedAt=$fileModifiedAt, id=$id, isFavorite=$isFavorite, isVisible=$isVisible, localDateTime=$localDateTime, originalFileName=$originalFileName, ownerId=$ownerId, thumbhash=$thumbhash, type=$type]';
Map<String, dynamic> toJson() {
final json = <String, dynamic>{};
@ -106,6 +111,7 @@ class SyncAssetV1 {
} else {
// json[r'localDateTime'] = null;
}
json[r'originalFileName'] = this.originalFileName;
json[r'ownerId'] = this.ownerId;
if (this.thumbhash != null) {
json[r'thumbhash'] = this.thumbhash;
@ -133,6 +139,7 @@ class SyncAssetV1 {
isFavorite: mapValueOfType<bool>(json, r'isFavorite')!,
isVisible: mapValueOfType<bool>(json, r'isVisible')!,
localDateTime: mapDateTime(json, r'localDateTime', r''),
originalFileName: mapValueOfType<String>(json, r'originalFileName')!,
ownerId: mapValueOfType<String>(json, r'ownerId')!,
thumbhash: mapValueOfType<String>(json, r'thumbhash'),
type: SyncAssetV1TypeEnum.fromJson(json[r'type'])!,
@ -191,6 +198,7 @@ class SyncAssetV1 {
'isFavorite',
'isVisible',
'localDateTime',
'originalFileName',
'ownerId',
'thumbhash',
'type',

View File

@ -12234,6 +12234,9 @@
"nullable": true,
"type": "string"
},
"originalFileName": {
"type": "string"
},
"ownerId": {
"type": "string"
},
@ -12260,6 +12263,7 @@
"isFavorite",
"isVisible",
"localDateTime",
"originalFileName",
"ownerId",
"thumbhash",
"type"

View File

@ -326,6 +326,7 @@ export const columns = {
syncAsset: [
'id',
'ownerId',
'originalFileName',
'thumbhash',
'checksum',
'fileCreatedAt',

View File

@ -59,6 +59,7 @@ export class SyncPartnerDeleteV1 {
export class SyncAssetV1 {
id!: string;
ownerId!: string;
originalFileName!: string;
thumbhash!: string | null;
checksum!: string;
fileCreatedAt!: Date | null;

View File

@ -76,6 +76,7 @@ order by
select
"id",
"ownerId",
"originalFileName",
"thumbhash",
"checksum",
"fileCreatedAt",
@ -98,6 +99,7 @@ order by
select
"id",
"ownerId",
"originalFileName",
"thumbhash",
"checksum",
"fileCreatedAt",

View File

@ -424,12 +424,14 @@ describe(SyncService.name, () => {
it('should detect and sync the first asset', async () => {
const { auth, sut, getRepository, testSync } = await setup();
const originalFileName = 'firstAsset';
const checksum = '1115vHcVkZzNp3Q9G+FEA0nu6zUbGb4Tj4UOXkN0wRA=';
const thumbhash = '2225vHcVkZzNp3Q9G+FEA0nu6zUbGb4Tj4UOXkN0wRA=';
const date = new Date().toISOString();
const assetRepo = getRepository('asset');
const asset = mediumFactory.assetInsert({
originalFileName,
ownerId: auth.user.id,
checksum: Buffer.from(checksum, 'base64'),
thumbhash: Buffer.from(thumbhash, 'base64'),
@ -449,6 +451,7 @@ describe(SyncService.name, () => {
ack: expect.any(String),
data: {
id: asset.id,
originalFileName,
ownerId: asset.ownerId,
thumbhash,
checksum,
@ -534,6 +537,7 @@ describe(SyncService.name, () => {
it('should detect and sync the first partner asset', async () => {
const { auth, sut, getRepository, testSync } = await setup();
const originalFileName = 'firstPartnerAsset';
const checksum = '1115vHcVkZzNp3Q9G+FEA0nu6zUbGb4Tj4UOXkN0wRA=';
const thumbhash = '2225vHcVkZzNp3Q9G+FEA0nu6zUbGb4Tj4UOXkN0wRA=';
const date = new Date().toISOString();
@ -545,6 +549,7 @@ describe(SyncService.name, () => {
const assetRepo = getRepository('asset');
const asset = mediumFactory.assetInsert({
ownerId: user2.id,
originalFileName,
checksum: Buffer.from(checksum, 'base64'),
thumbhash: Buffer.from(thumbhash, 'base64'),
fileCreatedAt: date,
@ -567,6 +572,7 @@ describe(SyncService.name, () => {
data: {
id: asset.id,
ownerId: asset.ownerId,
originalFileName,
thumbhash,
checksum,
deletedAt: null,