about summary refs log tree commit diff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/paperclip/gif_transcoder.rb21
-rw-r--r--lib/paperclip/video_transcoder.rb14
-rw-r--r--lib/tasks/mastodon.rake11
3 files changed, 45 insertions, 1 deletions
diff --git a/lib/paperclip/gif_transcoder.rb b/lib/paperclip/gif_transcoder.rb
new file mode 100644
index 000000000..8337448b2
--- /dev/null
+++ b/lib/paperclip/gif_transcoder.rb
@@ -0,0 +1,21 @@
+# frozen_string_literal: true
+
+module Paperclip
+  # This transcoder is only to be used for the MediaAttachment model
+  # to convert animated gifs to webm
+  class GifTranscoder < Paperclip::Processor
+    def make
+      num_frames = identify('-format %n :file', file: file.path).to_i
+
+      return file unless options[:style] == :original && num_frames > 1
+
+      final_file = Paperclip::Transcoder.make(file, options, attachment)
+
+      attachment.instance.file_file_name    = 'media.mp4'
+      attachment.instance.file_content_type = 'video/mp4'
+      attachment.instance.type              = MediaAttachment.types[:gifv]
+
+      final_file
+    end
+  end
+end
diff --git a/lib/paperclip/video_transcoder.rb b/lib/paperclip/video_transcoder.rb
new file mode 100644
index 000000000..c3504c17c
--- /dev/null
+++ b/lib/paperclip/video_transcoder.rb
@@ -0,0 +1,14 @@
+# frozen_string_literal: true
+
+module Paperclip
+  # This transcoder is only to be used for the MediaAttachment model
+  # to check when uploaded videos are actually gifv's
+  class VideoTranscoder < Paperclip::Processor
+    def make
+      meta = ::Av.cli.identify(@file.path)
+      attachment.instance.type = MediaAttachment.types[:gifv] unless meta[:audio_encode]
+
+      Paperclip::Transcoder.make(file, options, attachment)
+    end
+  end
+end
diff --git a/lib/tasks/mastodon.rake b/lib/tasks/mastodon.rake
index 8482d4124..bb10410b5 100644
--- a/lib/tasks/mastodon.rake
+++ b/lib/tasks/mastodon.rake
@@ -43,7 +43,7 @@ namespace :mastodon do
   namespace :feeds do
     desc 'Clear timelines of inactive users'
     task clear: :environment do
-      User.where('current_sign_in_at < ?', 14.days.ago).find_each do |user|
+      User.confirmed.where('current_sign_in_at < ?', 14.days.ago).find_each do |user|
         Redis.current.del(FeedManager.instance.key(:home, user.account_id))
       end
     end
@@ -53,4 +53,13 @@ namespace :mastodon do
       Redis.current.keys('feed:*').each { |key| Redis.current.del(key) }
     end
   end
+
+  namespace :emails do
+    desc 'Send out digest e-mails'
+    task digest: :environment do
+      User.confirmed.joins(:account).where(accounts: { silenced: false, suspended: false }).where('current_sign_in_at < ?', 20.days.ago).find_each do |user|
+        DigestMailerWorker.perform_async(user.id)
+      end
+    end
+  end
 end