mirror of https://github.com/immich-app/immich.git
feat(mobile) duplicated asset upload handling mechanism (#853)
parent
f1af17bf4d
commit
6159c83fd2
@ -0,0 +1,57 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:collection/collection.dart';
|
||||
import 'package:hive/hive.dart';
|
||||
|
||||
part 'hive_duplicated_assets.model.g.dart';
|
||||
|
||||
@HiveType(typeId: 2)
|
||||
class HiveDuplicatedAssets {
|
||||
@HiveField(0, defaultValue: [])
|
||||
List<String> duplicatedAssetIds;
|
||||
|
||||
HiveDuplicatedAssets({
|
||||
required this.duplicatedAssetIds,
|
||||
});
|
||||
|
||||
HiveDuplicatedAssets copyWith({
|
||||
List<String>? duplicatedAssetIds,
|
||||
}) {
|
||||
return HiveDuplicatedAssets(
|
||||
duplicatedAssetIds: duplicatedAssetIds ?? this.duplicatedAssetIds,
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toMap() {
|
||||
return {
|
||||
'duplicatedAssetIds': duplicatedAssetIds,
|
||||
};
|
||||
}
|
||||
|
||||
factory HiveDuplicatedAssets.fromMap(Map<String, dynamic> map) {
|
||||
return HiveDuplicatedAssets(
|
||||
duplicatedAssetIds: List<String>.from(map['duplicatedAssetIds']),
|
||||
);
|
||||
}
|
||||
|
||||
String toJson() => json.encode(toMap());
|
||||
|
||||
factory HiveDuplicatedAssets.fromJson(String source) =>
|
||||
HiveDuplicatedAssets.fromMap(json.decode(source));
|
||||
|
||||
@override
|
||||
String toString() =>
|
||||
'HiveDuplicatedAssets(duplicatedAssetIds: $duplicatedAssetIds)';
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
if (identical(this, other)) return true;
|
||||
final listEquals = const DeepCollectionEquality().equals;
|
||||
|
||||
return other is HiveDuplicatedAssets &&
|
||||
listEquals(other.duplicatedAssetIds, duplicatedAssetIds);
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode => duplicatedAssetIds.hashCode;
|
||||
}
|
||||
@ -0,0 +1,42 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'hive_duplicated_assets.model.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// TypeAdapterGenerator
|
||||
// **************************************************************************
|
||||
|
||||
class HiveDuplicatedAssetsAdapter extends TypeAdapter<HiveDuplicatedAssets> {
|
||||
@override
|
||||
final int typeId = 2;
|
||||
|
||||
@override
|
||||
HiveDuplicatedAssets read(BinaryReader reader) {
|
||||
final numOfFields = reader.readByte();
|
||||
final fields = <int, dynamic>{
|
||||
for (int i = 0; i < numOfFields; i++) reader.readByte(): reader.read(),
|
||||
};
|
||||
return HiveDuplicatedAssets(
|
||||
duplicatedAssetIds:
|
||||
fields[0] == null ? [] : (fields[0] as List).cast<String>(),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void write(BinaryWriter writer, HiveDuplicatedAssets obj) {
|
||||
writer
|
||||
..writeByte(1)
|
||||
..writeByte(0)
|
||||
..write(obj.duplicatedAssetIds);
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode => typeId.hashCode;
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) =>
|
||||
identical(this, other) ||
|
||||
other is HiveDuplicatedAssetsAdapter &&
|
||||
runtimeType == other.runtimeType &&
|
||||
typeId == other.typeId;
|
||||
}
|
||||
@ -0,0 +1,16 @@
|
||||
# openapi.model.CheckExistingAssetsDto
|
||||
|
||||
## Load the model package
|
||||
```dart
|
||||
import 'package:openapi/api.dart';
|
||||
```
|
||||
|
||||
## Properties
|
||||
Name | Type | Description | Notes
|
||||
------------ | ------------- | ------------- | -------------
|
||||
**deviceAssetIds** | **List<String>** | | [default to const []]
|
||||
**deviceId** | **String** | |
|
||||
|
||||
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
|
||||
|
||||
|
||||
@ -0,0 +1,15 @@
|
||||
# openapi.model.CheckExistingAssetsResponseDto
|
||||
|
||||
## Load the model package
|
||||
```dart
|
||||
import 'package:openapi/api.dart';
|
||||
```
|
||||
|
||||
## Properties
|
||||
Name | Type | Description | Notes
|
||||
------------ | ------------- | ------------- | -------------
|
||||
**existingIds** | **List<String>** | | [default to const []]
|
||||
|
||||
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
|
||||
|
||||
|
||||
@ -0,0 +1,121 @@
|
||||
//
|
||||
// AUTO-GENERATED FILE, DO NOT MODIFY!
|
||||
//
|
||||
// @dart=2.12
|
||||
|
||||
// ignore_for_file: unused_element, unused_import
|
||||
// ignore_for_file: always_put_required_named_parameters_first
|
||||
// ignore_for_file: constant_identifier_names
|
||||
// ignore_for_file: lines_longer_than_80_chars
|
||||
|
||||
part of openapi.api;
|
||||
|
||||
class CheckExistingAssetsDto {
|
||||
/// Returns a new [CheckExistingAssetsDto] instance.
|
||||
CheckExistingAssetsDto({
|
||||
this.deviceAssetIds = const [],
|
||||
required this.deviceId,
|
||||
});
|
||||
|
||||
List<String> deviceAssetIds;
|
||||
|
||||
String deviceId;
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) => identical(this, other) || other is CheckExistingAssetsDto &&
|
||||
other.deviceAssetIds == deviceAssetIds &&
|
||||
other.deviceId == deviceId;
|
||||
|
||||
@override
|
||||
int get hashCode =>
|
||||
// ignore: unnecessary_parenthesis
|
||||
(deviceAssetIds.hashCode) +
|
||||
(deviceId.hashCode);
|
||||
|
||||
@override
|
||||
String toString() => 'CheckExistingAssetsDto[deviceAssetIds=$deviceAssetIds, deviceId=$deviceId]';
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
final _json = <String, dynamic>{};
|
||||
_json[r'deviceAssetIds'] = deviceAssetIds;
|
||||
_json[r'deviceId'] = deviceId;
|
||||
return _json;
|
||||
}
|
||||
|
||||
/// Returns a new [CheckExistingAssetsDto] instance and imports its values from
|
||||
/// [value] if it's a [Map], null otherwise.
|
||||
// ignore: prefer_constructors_over_static_methods
|
||||
static CheckExistingAssetsDto? fromJson(dynamic value) {
|
||||
if (value is Map) {
|
||||
final json = value.cast<String, dynamic>();
|
||||
|
||||
// Ensure that the map contains the required keys.
|
||||
// Note 1: the values aren't checked for validity beyond being non-null.
|
||||
// Note 2: this code is stripped in release mode!
|
||||
assert(() {
|
||||
requiredKeys.forEach((key) {
|
||||
assert(json.containsKey(key), 'Required key "CheckExistingAssetsDto[$key]" is missing from JSON.');
|
||||
assert(json[key] != null, 'Required key "CheckExistingAssetsDto[$key]" has a null value in JSON.');
|
||||
});
|
||||
return true;
|
||||
}());
|
||||
|
||||
return CheckExistingAssetsDto(
|
||||
deviceAssetIds: json[r'deviceAssetIds'] is List
|
||||
? (json[r'deviceAssetIds'] as List).cast<String>()
|
||||
: const [],
|
||||
deviceId: mapValueOfType<String>(json, r'deviceId')!,
|
||||
);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
static List<CheckExistingAssetsDto>? listFromJson(dynamic json, {bool growable = false,}) {
|
||||
final result = <CheckExistingAssetsDto>[];
|
||||
if (json is List && json.isNotEmpty) {
|
||||
for (final row in json) {
|
||||
final value = CheckExistingAssetsDto.fromJson(row);
|
||||
if (value != null) {
|
||||
result.add(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
return result.toList(growable: growable);
|
||||
}
|
||||
|
||||
static Map<String, CheckExistingAssetsDto> mapFromJson(dynamic json) {
|
||||
final map = <String, CheckExistingAssetsDto>{};
|
||||
if (json is Map && json.isNotEmpty) {
|
||||
json = json.cast<String, dynamic>(); // ignore: parameter_assignments
|
||||
for (final entry in json.entries) {
|
||||
final value = CheckExistingAssetsDto.fromJson(entry.value);
|
||||
if (value != null) {
|
||||
map[entry.key] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
// maps a json object with a list of CheckExistingAssetsDto-objects as value to a dart map
|
||||
static Map<String, List<CheckExistingAssetsDto>> mapListFromJson(dynamic json, {bool growable = false,}) {
|
||||
final map = <String, List<CheckExistingAssetsDto>>{};
|
||||
if (json is Map && json.isNotEmpty) {
|
||||
json = json.cast<String, dynamic>(); // ignore: parameter_assignments
|
||||
for (final entry in json.entries) {
|
||||
final value = CheckExistingAssetsDto.listFromJson(entry.value, growable: growable,);
|
||||
if (value != null) {
|
||||
map[entry.key] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
/// The list of required keys that must be present in a JSON.
|
||||
static const requiredKeys = <String>{
|
||||
'deviceAssetIds',
|
||||
'deviceId',
|
||||
};
|
||||
}
|
||||
|
||||
@ -0,0 +1,113 @@
|
||||
//
|
||||
// AUTO-GENERATED FILE, DO NOT MODIFY!
|
||||
//
|
||||
// @dart=2.12
|
||||
|
||||
// ignore_for_file: unused_element, unused_import
|
||||
// ignore_for_file: always_put_required_named_parameters_first
|
||||
// ignore_for_file: constant_identifier_names
|
||||
// ignore_for_file: lines_longer_than_80_chars
|
||||
|
||||
part of openapi.api;
|
||||
|
||||
class CheckExistingAssetsResponseDto {
|
||||
/// Returns a new [CheckExistingAssetsResponseDto] instance.
|
||||
CheckExistingAssetsResponseDto({
|
||||
this.existingIds = const [],
|
||||
});
|
||||
|
||||
List<String> existingIds;
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) => identical(this, other) || other is CheckExistingAssetsResponseDto &&
|
||||
other.existingIds == existingIds;
|
||||
|
||||
@override
|
||||
int get hashCode =>
|
||||
// ignore: unnecessary_parenthesis
|
||||
(existingIds.hashCode);
|
||||
|
||||
@override
|
||||
String toString() => 'CheckExistingAssetsResponseDto[existingIds=$existingIds]';
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
final _json = <String, dynamic>{};
|
||||
_json[r'existingIds'] = existingIds;
|
||||
return _json;
|
||||
}
|
||||
|
||||
/// Returns a new [CheckExistingAssetsResponseDto] instance and imports its values from
|
||||
/// [value] if it's a [Map], null otherwise.
|
||||
// ignore: prefer_constructors_over_static_methods
|
||||
static CheckExistingAssetsResponseDto? fromJson(dynamic value) {
|
||||
if (value is Map) {
|
||||
final json = value.cast<String, dynamic>();
|
||||
|
||||
// Ensure that the map contains the required keys.
|
||||
// Note 1: the values aren't checked for validity beyond being non-null.
|
||||
// Note 2: this code is stripped in release mode!
|
||||
assert(() {
|
||||
requiredKeys.forEach((key) {
|
||||
assert(json.containsKey(key), 'Required key "CheckExistingAssetsResponseDto[$key]" is missing from JSON.');
|
||||
assert(json[key] != null, 'Required key "CheckExistingAssetsResponseDto[$key]" has a null value in JSON.');
|
||||
});
|
||||
return true;
|
||||
}());
|
||||
|
||||
return CheckExistingAssetsResponseDto(
|
||||
existingIds: json[r'existingIds'] is List
|
||||
? (json[r'existingIds'] as List).cast<String>()
|
||||
: const [],
|
||||
);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
static List<CheckExistingAssetsResponseDto>? listFromJson(dynamic json, {bool growable = false,}) {
|
||||
final result = <CheckExistingAssetsResponseDto>[];
|
||||
if (json is List && json.isNotEmpty) {
|
||||
for (final row in json) {
|
||||
final value = CheckExistingAssetsResponseDto.fromJson(row);
|
||||
if (value != null) {
|
||||
result.add(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
return result.toList(growable: growable);
|
||||
}
|
||||
|
||||
static Map<String, CheckExistingAssetsResponseDto> mapFromJson(dynamic json) {
|
||||
final map = <String, CheckExistingAssetsResponseDto>{};
|
||||
if (json is Map && json.isNotEmpty) {
|
||||
json = json.cast<String, dynamic>(); // ignore: parameter_assignments
|
||||
for (final entry in json.entries) {
|
||||
final value = CheckExistingAssetsResponseDto.fromJson(entry.value);
|
||||
if (value != null) {
|
||||
map[entry.key] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
// maps a json object with a list of CheckExistingAssetsResponseDto-objects as value to a dart map
|
||||
static Map<String, List<CheckExistingAssetsResponseDto>> mapListFromJson(dynamic json, {bool growable = false,}) {
|
||||
final map = <String, List<CheckExistingAssetsResponseDto>>{};
|
||||
if (json is Map && json.isNotEmpty) {
|
||||
json = json.cast<String, dynamic>(); // ignore: parameter_assignments
|
||||
for (final entry in json.entries) {
|
||||
final value = CheckExistingAssetsResponseDto.listFromJson(entry.value, growable: growable,);
|
||||
if (value != null) {
|
||||
map[entry.key] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
/// The list of required keys that must be present in a JSON.
|
||||
static const requiredKeys = <String>{
|
||||
'existingIds',
|
||||
};
|
||||
}
|
||||
|
||||
@ -0,0 +1,32 @@
|
||||
//
|
||||
// AUTO-GENERATED FILE, DO NOT MODIFY!
|
||||
//
|
||||
// @dart=2.12
|
||||
|
||||
// ignore_for_file: unused_element, unused_import
|
||||
// ignore_for_file: always_put_required_named_parameters_first
|
||||
// ignore_for_file: constant_identifier_names
|
||||
// ignore_for_file: lines_longer_than_80_chars
|
||||
|
||||
import 'package:openapi/api.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
// tests for CheckExistingAssetsDto
|
||||
void main() {
|
||||
// final instance = CheckExistingAssetsDto();
|
||||
|
||||
group('test CheckExistingAssetsDto', () {
|
||||
// List<String> deviceAssetIds (default value: const [])
|
||||
test('to test the property `deviceAssetIds`', () async {
|
||||
// TODO
|
||||
});
|
||||
|
||||
// String deviceId
|
||||
test('to test the property `deviceId`', () async {
|
||||
// TODO
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
@ -0,0 +1,27 @@
|
||||
//
|
||||
// AUTO-GENERATED FILE, DO NOT MODIFY!
|
||||
//
|
||||
// @dart=2.12
|
||||
|
||||
// ignore_for_file: unused_element, unused_import
|
||||
// ignore_for_file: always_put_required_named_parameters_first
|
||||
// ignore_for_file: constant_identifier_names
|
||||
// ignore_for_file: lines_longer_than_80_chars
|
||||
|
||||
import 'package:openapi/api.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
// tests for CheckExistingAssetsResponseDto
|
||||
void main() {
|
||||
// final instance = CheckExistingAssetsResponseDto();
|
||||
|
||||
group('test CheckExistingAssetsResponseDto', () {
|
||||
// List<String> existingIds (default value: const [])
|
||||
test('to test the property `existingIds`', () async {
|
||||
// TODO
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
@ -0,0 +1,9 @@
|
||||
import { IsNotEmpty } from 'class-validator';
|
||||
|
||||
export class CheckExistingAssetsDto {
|
||||
@IsNotEmpty()
|
||||
deviceAssetIds!: string[];
|
||||
|
||||
@IsNotEmpty()
|
||||
deviceId!: string;
|
||||
}
|
||||
@ -0,0 +1,7 @@
|
||||
export class CheckExistingAssetsResponseDto {
|
||||
constructor(existingIds: string[]) {
|
||||
this.existingIds = existingIds;
|
||||
}
|
||||
existingIds: string[];
|
||||
}
|
||||
|
||||
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue