From 609907e9de477426818366628b39187560639a42 Mon Sep 17 00:00:00 2001 From: Felix Eckhofer <felix@eckhofer.com> Date: Thu, 26 Dec 2024 14:05:31 +0100 Subject: [PATCH] Only download files when they don't exist yet --- app/models/filedrop_file.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/models/filedrop_file.rb b/app/models/filedrop_file.rb index 235a5b1..5000ae2 100644 --- a/app/models/filedrop_file.rb +++ b/app/models/filedrop_file.rb @@ -17,7 +17,11 @@ class FiledropFile < ApplicationRecord end def download(url) - # TBD: only download if orig_created is newer than actual file change time + if File.exist?(local_path) + local_sha1 = Digest::SHA1.file(local_path).hexdigest + return if local_sha1 == checksum + end + response = HTTParty.get(url) if response.success? File.open(local_path, 'wb') do |file| -- GitLab