2020-03-28 13:56:06 +00:00
|
|
|
import 'dart:io';
|
|
|
|
|
|
|
|
import 'package:crypto/crypto.dart';
|
|
|
|
import 'package:photo_manager/photo_manager.dart';
|
|
|
|
|
2020-03-27 16:07:55 +00:00
|
|
|
class Photo {
|
2020-04-12 12:38:49 +00:00
|
|
|
int uploadedFileId;
|
2020-04-11 21:29:07 +00:00
|
|
|
String localId;
|
2020-04-09 19:03:11 +00:00
|
|
|
String path;
|
2020-03-27 16:07:55 +00:00
|
|
|
String localPath;
|
2020-03-30 10:57:04 +00:00
|
|
|
String thumbnailPath;
|
2020-03-27 16:07:55 +00:00
|
|
|
String hash;
|
2020-04-13 11:28:01 +00:00
|
|
|
int createTimestamp;
|
2020-03-27 16:07:55 +00:00
|
|
|
int syncTimestamp;
|
|
|
|
|
2020-03-28 13:56:06 +00:00
|
|
|
Photo();
|
|
|
|
|
2020-03-27 16:07:55 +00:00
|
|
|
Photo.fromJson(Map<String, dynamic> json)
|
2020-04-12 12:38:49 +00:00
|
|
|
: uploadedFileId = json["fileId"],
|
|
|
|
path = json["path"],
|
2020-03-28 13:56:06 +00:00
|
|
|
hash = json["hash"],
|
2020-04-11 11:15:27 +00:00
|
|
|
thumbnailPath = json["thumbnailPath"],
|
2020-04-13 11:28:01 +00:00
|
|
|
createTimestamp = json["createTimestamp"],
|
2020-03-27 16:07:55 +00:00
|
|
|
syncTimestamp = json["syncTimestamp"];
|
|
|
|
|
2020-03-28 13:56:06 +00:00
|
|
|
static Future<Photo> fromAsset(AssetEntity asset) async {
|
|
|
|
Photo photo = Photo();
|
|
|
|
var file = (await asset.originFile);
|
2020-04-12 12:38:49 +00:00
|
|
|
photo.uploadedFileId = -1;
|
2020-04-11 21:29:07 +00:00
|
|
|
photo.localId = asset.id;
|
2020-03-28 13:56:06 +00:00
|
|
|
photo.localPath = file.path;
|
|
|
|
photo.hash = getHash(file);
|
2020-04-11 11:15:27 +00:00
|
|
|
photo.thumbnailPath = file.path;
|
2020-04-13 11:28:01 +00:00
|
|
|
photo.createTimestamp = asset.createDateTime.microsecondsSinceEpoch;
|
2020-04-11 11:15:27 +00:00
|
|
|
return photo;
|
2020-03-30 15:08:50 +00:00
|
|
|
}
|
|
|
|
|
2020-03-28 13:56:06 +00:00
|
|
|
static String getHash(File file) {
|
|
|
|
return sha256.convert(file.readAsBytesSync()).toString();
|
|
|
|
}
|
2020-03-30 14:28:46 +00:00
|
|
|
}
|