From 653fb5191d595711dbc9fc8b8deedf532f43bf00 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Fri, 16 Aug 2019 16:09:32 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=88=A4=E6=96=ADpdf?= =?UTF-8?q?=E7=9A=84=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/attachment_history.rb | 10 ++++++++++ .../_attachment_history.json.jbuilder | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/app/models/attachment_history.rb b/app/models/attachment_history.rb index 220f92535..c19146b95 100644 --- a/app/models/attachment_history.rb +++ b/app/models/attachment_history.rb @@ -20,4 +20,14 @@ class AttachmentHistory < ApplicationRecord is_public == 1 end + def is_history_pdf? + is_pdf = false + file_content_type = content_type + file_ext_type = File.extname(filename).strip.downcase[1..-1] + if (file_content_type.present? && file_content_type.downcase.include?("pdf")) || (file_ext_type.present? && file_ext_type.include?("pdf")) + is_pdf = true + end + is_pdf + end + end diff --git a/app/views/attachment_histories/_attachment_history.json.jbuilder b/app/views/attachment_histories/_attachment_history.json.jbuilder index 65ca1e887..8930e1b2d 100644 --- a/app/views/attachment_histories/_attachment_history.json.jbuilder +++ b/app/views/attachment_histories/_attachment_history.json.jbuilder @@ -7,4 +7,4 @@ json.quotes attachment.quotes_count json.downloads_count attachment.downloads_count json.created_on attachment.created_on json.url attachment_path(attachment, type: 'history') -json.is_pdf attachment.is_pdf? +json.is_pdf attachment.is_history_pdf?