aboutsummaryrefslogtreecommitdiff
path: root/libdino/src/service/avatar_storage.vala
diff options
context:
space:
mode:
authorfiaxh <git@lightrise.org>2019-04-19 21:42:40 +0200
committerfiaxh <git@lightrise.org>2019-04-24 23:44:00 +0200
commitb6799e59bb9cc2ea511b0f19aab88a83c244dda8 (patch)
tree5eb981539bd97e6e5a46d47b4869fb51cf561dc6 /libdino/src/service/avatar_storage.vala
parentcbe0ff2c1d6eb86520fdba05183f33cd4f262bcd (diff)
downloaddino-b6799e59bb9cc2ea511b0f19aab88a83c244dda8.tar.gz
dino-b6799e59bb9cc2ea511b0f19aab88a83c244dda8.zip
Remove avatars with missmatch between supposed and actual sha1 hash on load, make loading async
Diffstat (limited to 'libdino/src/service/avatar_storage.vala')
-rw-r--r--libdino/src/service/avatar_storage.vala19
1 files changed, 17 insertions, 2 deletions
diff --git a/libdino/src/service/avatar_storage.vala b/libdino/src/service/avatar_storage.vala
index b924ca27..a307fe66 100644
--- a/libdino/src/service/avatar_storage.vala
+++ b/libdino/src/service/avatar_storage.vala
@@ -28,9 +28,24 @@ public class AvatarStorage : Xep.PixbufStorage, Object {
return file.query_exists();
}
- public Pixbuf? get_image(string id) {
+ public async Pixbuf? get_image(string id) {
try {
- return new Pixbuf.from_file(Path.build_filename(folder, id));
+ File file = File.new_for_path(Path.build_filename(folder, id));
+ FileInputStream stream = yield file.read_async();
+
+ uint8 fbuf[100];
+ size_t size;
+
+ Checksum checksum = new Checksum (ChecksumType.SHA1);
+ while ((size = yield stream.read_async(fbuf)) > 0) {
+ checksum.update(fbuf, size);
+ }
+
+ if (checksum.get_string() != id) {
+ FileUtils.remove(file.get_path());
+ }
+ stream.seek(0, SeekType.SET);
+ return yield new Pixbuf.from_stream_async(stream);
} catch (Error e) {
return null;
}