From de85220fd87bf56b3d0811cfa39a94972782ca04 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Thu, 15 Aug 2019 15:28:08 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B5=84=E6=BA=90=E4=B8=8B=E8=BD=BD=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0is=5Fpdf=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/files_controller.rb | 7 ++++++- app/views/files/histories.json.jbuilder | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/app/controllers/files_controller.rb b/app/controllers/files_controller.rb index 2cfa61cc9..bcfed25dd 100644 --- a/app/controllers/files_controller.rb +++ b/app/controllers/files_controller.rb @@ -260,7 +260,12 @@ class FilesController < ApplicationController return normal_status(-2, "该课程下没有id为 #{params[:id]}的资源") if @file.nil? return normal_status(403, "您没有权限进行该操作") if @user != @file.author && !@user.teacher_of_course?(@course) && !@file.public? - + @is_pdf = false + file_content_type = @file.content_type + file_ext_type = File.extname(@file.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 @attachment_histories = @file.attachment_histories end diff --git a/app/views/files/histories.json.jbuilder b/app/views/files/histories.json.jbuilder index f30cf6b1b..9dfec4fd4 100644 --- a/app/views/files/histories.json.jbuilder +++ b/app/views/files/histories.json.jbuilder @@ -1,2 +1,3 @@ +json.is_pdf @is_pdf json.partial! 'attachments/attachment_small', attachment: @file json.partial! "attachment_histories/list", attachment_histories: @attachment_histories