mirror of
https://github.com/KevinMidboe/immich.git
synced 2026-01-17 22:56:37 +00:00
refactor(server): calculate asset type server side (#3200)
* refactor(server): calculate asset type server-side * chore: open api * chore: remove comments * fix: linting * update * Revert "update" This reverts commit dc58702923250b9385d22468a7afe77dc9972a03. * fix: upload LivePhotos * chore: remove unused request fields for upload * remove unused method * mobile-fix: livePhoto filename * fix: revert check for livephotos filename and extension --------- Co-authored-by: Alex Tran <alex.tran1502@gmail.com>
This commit is contained in:
@@ -14,15 +14,13 @@ import 'package:immich_mobile/shared/models/store.dart';
|
||||
import 'package:immich_mobile/shared/providers/api.provider.dart';
|
||||
import 'package:immich_mobile/shared/providers/db.provider.dart';
|
||||
import 'package:immich_mobile/shared/services/api.service.dart';
|
||||
import 'package:immich_mobile/utils/files_helper.dart';
|
||||
import 'package:isar/isar.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
import 'package:openapi/api.dart';
|
||||
import 'package:permission_handler/permission_handler.dart';
|
||||
import 'package:photo_manager/photo_manager.dart';
|
||||
import 'package:http_parser/http_parser.dart';
|
||||
import 'package:path/path.dart' as p;
|
||||
import 'package:cancellation_token_http/http.dart' as http;
|
||||
import 'package:path/path.dart' as p;
|
||||
|
||||
final backupServiceProvider = Provider(
|
||||
(ref) => BackupService(
|
||||
@@ -230,18 +228,12 @@ class BackupService {
|
||||
|
||||
if (file != null) {
|
||||
String originalFileName = await entity.titleAsync;
|
||||
var fileExtension = p.extension(file.path);
|
||||
var mimeType = FileHelper.getMimeType(file.path);
|
||||
var fileStream = file.openRead();
|
||||
var assetRawUploadData = http.MultipartFile(
|
||||
"assetData",
|
||||
fileStream,
|
||||
file.lengthSync(),
|
||||
filename: originalFileName,
|
||||
contentType: MediaType(
|
||||
mimeType["type"],
|
||||
mimeType["subType"],
|
||||
),
|
||||
);
|
||||
|
||||
var req = MultipartRequest(
|
||||
@@ -256,12 +248,10 @@ class BackupService {
|
||||
|
||||
req.fields['deviceAssetId'] = entity.id;
|
||||
req.fields['deviceId'] = deviceId;
|
||||
req.fields['assetType'] = _getAssetType(entity.type);
|
||||
req.fields['fileCreatedAt'] = entity.createDateTime.toIso8601String();
|
||||
req.fields['fileModifiedAt'] =
|
||||
entity.modifiedDateTime.toIso8601String();
|
||||
req.fields['isFavorite'] = entity.isFavorite.toString();
|
||||
req.fields['fileExtension'] = fileExtension;
|
||||
req.fields['duration'] = entity.videoDuration.toString();
|
||||
|
||||
req.files.add(assetRawUploadData);
|
||||
@@ -342,18 +332,12 @@ class BackupService {
|
||||
var validPath = motionFilePath.replaceAll('file://', '');
|
||||
var motionFile = File(validPath);
|
||||
var fileStream = motionFile.openRead();
|
||||
String originalFileName = await entity.titleAsync;
|
||||
var mimeType = FileHelper.getMimeType(validPath);
|
||||
|
||||
String fileName = p.basename(motionFile.path);
|
||||
return http.MultipartFile(
|
||||
"livePhotoData",
|
||||
fileStream,
|
||||
motionFile.lengthSync(),
|
||||
filename: originalFileName,
|
||||
contentType: MediaType(
|
||||
mimeType["type"],
|
||||
mimeType["subType"],
|
||||
),
|
||||
filename: fileName,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import 'package:collection/collection.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
import 'package:http/http.dart';
|
||||
import 'package:http_parser/http_parser.dart';
|
||||
import 'package:image_picker/image_picker.dart';
|
||||
import 'package:immich_mobile/modules/partner/services/partner.service.dart';
|
||||
import 'package:immich_mobile/shared/models/store.dart';
|
||||
@@ -11,7 +10,6 @@ import 'package:immich_mobile/shared/providers/db.provider.dart';
|
||||
import 'package:immich_mobile/shared/services/api.service.dart';
|
||||
import 'package:immich_mobile/shared/services/sync.service.dart';
|
||||
import 'package:immich_mobile/utils/diff.dart';
|
||||
import 'package:immich_mobile/utils/files_helper.dart';
|
||||
import 'package:isar/isar.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
import 'package:openapi/api.dart';
|
||||
@@ -59,17 +57,11 @@ class UserService {
|
||||
|
||||
Future<CreateProfileImageResponseDto?> uploadProfileImage(XFile image) async {
|
||||
try {
|
||||
var mimeType = FileHelper.getMimeType(image.path);
|
||||
|
||||
return await _apiService.userApi.createProfileImage(
|
||||
MultipartFile.fromBytes(
|
||||
'file',
|
||||
await image.readAsBytes(),
|
||||
filename: image.name,
|
||||
contentType: MediaType(
|
||||
mimeType["type"],
|
||||
mimeType["subType"],
|
||||
),
|
||||
),
|
||||
);
|
||||
} catch (e) {
|
||||
|
||||
@@ -1,150 +0,0 @@
|
||||
import 'package:path/path.dart' as p;
|
||||
|
||||
class FileHelper {
|
||||
static getMimeType(String filePath) {
|
||||
var fileExtension = p.extension(filePath).split(".")[1];
|
||||
|
||||
switch (fileExtension.toLowerCase()) {
|
||||
case 'gif':
|
||||
return {"type": "image", "subType": "gif"};
|
||||
|
||||
case 'jpeg':
|
||||
return {"type": "image", "subType": "jpeg"};
|
||||
|
||||
case 'jpg':
|
||||
return {"type": "image", "subType": "jpeg"};
|
||||
|
||||
case 'png':
|
||||
return {"type": "image", "subType": "png"};
|
||||
|
||||
case 'tif':
|
||||
return {"type": "image", "subType": "tiff"};
|
||||
|
||||
case 'mov':
|
||||
return {"type": "video", "subType": "quicktime"};
|
||||
|
||||
case 'mp4':
|
||||
return {"type": "video", "subType": "mp4"};
|
||||
|
||||
case 'avi':
|
||||
return {"type": "video", "subType": "x-msvideo"};
|
||||
|
||||
case 'heic':
|
||||
return {"type": "image", "subType": "heic"};
|
||||
|
||||
case 'heif':
|
||||
return {"type": "image", "subType": "heif"};
|
||||
|
||||
case 'dng':
|
||||
return {"type": "image", "subType": "dng"};
|
||||
|
||||
case 'webp':
|
||||
return {"type": "image", "subType": "webp"};
|
||||
|
||||
case '3gp':
|
||||
return {"type": "video", "subType": "3gpp"};
|
||||
|
||||
case 'webm':
|
||||
return {"type": "video", "subType": "webm"};
|
||||
|
||||
case 'avif':
|
||||
return {"type": "image", "subType": "avif"};
|
||||
|
||||
case 'insp':
|
||||
return {"type": "image", "subType": "jpeg"};
|
||||
|
||||
case 'insv':
|
||||
return {"type": "video", "subType": "mp4"};
|
||||
|
||||
case 'arw':
|
||||
return {"type": "image", "subType": "x-sony-arw"};
|
||||
|
||||
case 'raf':
|
||||
return {"type": "image", "subType": "x-fuji-raf"};
|
||||
|
||||
case 'nef':
|
||||
return {"type": "image", "subType": "x-nikon-nef"};
|
||||
|
||||
case 'srw':
|
||||
return {"type": "image", "subType": "x-samsung-srw"};
|
||||
|
||||
case 'crw':
|
||||
return {"type": "image", "subType": "x-canon-crw"};
|
||||
|
||||
case 'cr2':
|
||||
return {"type": "image", "subType": "x-canon-cr2"};
|
||||
|
||||
case 'cr3':
|
||||
return {"type": "image", "subType": "x-canon-cr3"};
|
||||
|
||||
case 'erf':
|
||||
return {"type": "image", "subType": "x-epson-erf"};
|
||||
|
||||
case 'dcr':
|
||||
return {"type": "image", "subType": "x-kodak-dcr"};
|
||||
|
||||
case 'k25':
|
||||
return {"type": "image", "subType": "x-kodak-k25"};
|
||||
|
||||
case 'kdc':
|
||||
return {"type": "image", "subType": "x-kodak-kdc"};
|
||||
|
||||
case 'mrw':
|
||||
return {"type": "image", "subType": "x-minolta-mrw"};
|
||||
|
||||
case 'orf':
|
||||
return {"type": "image", "subType": "x-olympus-orf"};
|
||||
|
||||
case 'raw':
|
||||
return {"type": "image", "subType": "x-panasonic-raw"};
|
||||
|
||||
case 'pef':
|
||||
return {"type": "image", "subType": "x-panasonic-pef"};
|
||||
|
||||
case 'x3f':
|
||||
return {"type": "image", "subType": "x-sigma-x3f"};
|
||||
|
||||
case 'srf':
|
||||
return {"type": "image", "subType": "x-sony-srf"};
|
||||
|
||||
case 'sr2':
|
||||
return {"type": "image", "subType": "x-sony-sr2"};
|
||||
|
||||
case '3fr':
|
||||
return {"type": "image", "subType": "x-hasselblad-3fr"};
|
||||
|
||||
case 'fff':
|
||||
return {"type": "image", "subType": "x-hasselblad-fff"};
|
||||
|
||||
case 'rwl':
|
||||
return {"type": "image", "subType": "x-leica-rwl"};
|
||||
|
||||
case 'ori':
|
||||
return {"type": "image", "subType": "x-olympus-ori"};
|
||||
|
||||
case 'iiq':
|
||||
return {"type": "image", "subType": "x-phaseone-iiq"};
|
||||
|
||||
case 'ari':
|
||||
return {"type": "image", "subType": "x-arriflex-ari"};
|
||||
|
||||
case 'cap':
|
||||
return {"type": "image", "subType": "x-phaseone-cap"};
|
||||
|
||||
case 'cin':
|
||||
return {"type": "image", "subType": "x-phantom-cin"};
|
||||
|
||||
case 'jxl':
|
||||
return {"type": "image", "subType": "jxl"};
|
||||
|
||||
case 'mts':
|
||||
return {"type": "video", "subType": "mp2t"};
|
||||
|
||||
case 'm2ts':
|
||||
return {"type": "video", "subType": "mp2t"};
|
||||
|
||||
default:
|
||||
return {"type": "unsupport", "subType": "unsupport"};
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user