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-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;
|
|
|
|
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-09 19:03:11 +00:00
|
|
|
: 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-03-27 16:07:55 +00:00
|
|
|
syncTimestamp = json["syncTimestamp"];
|
|
|
|
|
|
|
|
Photo.fromRow(Map<String, dynamic> row)
|
2020-04-11 21:29:07 +00:00
|
|
|
: localId = row["local_id"],
|
|
|
|
localPath = row["local_path"],
|
2020-03-30 10:57:04 +00:00
|
|
|
thumbnailPath = row["thumbnail_path"],
|
2020-04-09 19:03:11 +00:00
|
|
|
path = row["path"],
|
2020-03-27 16:07:55 +00:00
|
|
|
hash = row["hash"],
|
2020-03-28 13:56:06 +00:00
|
|
|
syncTimestamp = row["sync_timestamp"] == null
|
|
|
|
? -1
|
|
|
|
: int.parse(row["sync_timestamp"]);
|
|
|
|
|
|
|
|
static Future<Photo> fromAsset(AssetEntity asset) async {
|
|
|
|
Photo photo = Photo();
|
|
|
|
var file = (await asset.originFile);
|
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;
|
|
|
|
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
|
|
|
}
|