From 000e73c56b8fe9d6b0da4db64f122639dd9467b4 Mon Sep 17 00:00:00 2001 From: Donovan Daniels Date: Wed, 8 May 2024 21:33:45 -0500 Subject: [PATCH] force create shorturl after image creation --- app/models/api_image.rb | 5 +++++ app/models/short_url.rb | 2 +- bin/update | 3 +++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/app/models/api_image.rb b/app/models/api_image.rb index 96de06a..c761bb6 100644 --- a/app/models/api_image.rb +++ b/app/models/api_image.rb @@ -17,6 +17,7 @@ class APIImage < ApplicationRecord after_create :invalidate_cache after_create :send_created, unless: :no_webhook_messages + after_create :initialize_short_url after_update :update_files, if: :saved_change_to_category? after_update :send_updated, unless: :no_webhook_messages after_destroy :delete_files @@ -103,6 +104,10 @@ class APIImage < ApplicationRecord ShortUrl.override(md5, url).shorturl end + def initialize_short_url + ShortUrl.override(md5, url) + end + def sources_string sources.join("\n") end diff --git a/app/models/short_url.rb b/app/models/short_url.rb index 22305b7..c3813b9 100644 --- a/app/models/short_url.rb +++ b/app/models/short_url.rb @@ -23,8 +23,8 @@ class ShortUrl < ApplicationRecord def self.override(code, url) prev = find_by(code: code) return prev if prev&.url == url && prev&.management_code.nil? - prev&.update!(code: "#{code}_#{prev.id}") CurrentUser.as_system do + prev&.update!(code: "#{code}_#{prev.id}") create!( code: code, creator_name: "YiffyAPI", diff --git a/bin/update b/bin/update index 4846532..4a54c96 100755 --- a/bin/update +++ b/bin/update @@ -1,2 +1,5 @@ #!/usr/bin/env sh +git pull docker compose -f docker-compose.prod.yml up -d --no-deps --build +docker compose -f docker-compose.prod.yml restart +nginx -t && nginx -s reload