Skip to content

Commit

Permalink
Set file size upload and download limits
Browse files Browse the repository at this point in the history
  • Loading branch information
hortongn committed Apr 10, 2017
1 parent e52398b commit 8d3110f
Show file tree
Hide file tree
Showing 16 changed files with 723 additions and 13 deletions.
71 changes: 71 additions & 0 deletions app/assets/javascripts/sufia/uploader.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
//= require fileupload/tmpl
//= require fileupload/jquery.iframe-transport
//= require fileupload/jquery.fileupload.js
//= require fileupload/jquery.fileupload-process.js
//= require fileupload/jquery.fileupload-validate.js
//= require fileupload/jquery.fileupload-ui.js
//
/*
* jQuery File Upload Plugin JS Example
* https://github.com/blueimp/jQuery-File-Upload
*
* Copyright 2010, Sebastian Tschan
* https://blueimp.net
*
* Licensed under the MIT license:
* http://www.opensource.org/licenses/MIT
*/

(function( $ ){
'use strict';

$.fn.extend({
sufiaUploader: function( options ) {
// Initialize our jQuery File Upload widget.
// TODO: get these values from configuration.
this.fileupload($.extend({
// xhrFields: {withCredentials: true}, // to send cross-domain cookies
// acceptFileTypes: /(\.|\/)(png|mov|jpe?g|pdf)$/i, // not a strong check, just a regex on the filename
// limitMultiFileUploadSize: 500000000, // bytes
limitConcurrentUploads: 6,
maxNumberOfFiles: 100,
maxFileSize: 3221225472, // Limit uploads to 3 GB per file
autoUpload: true,
url: '/uploads/',
type: 'POST',
dropZone: $(this).find('.dropzone')
}, options))
.bind('fileuploadadded', function (e, data) {
$(e.currentTarget).find('button.cancel').removeClass('hidden');
});

$(document).bind('dragover', function(e) {
var dropZone = $('.dropzone'),
timeout = window.dropZoneTimeout;
if (!timeout) {
dropZone.addClass('in');
} else {
clearTimeout(timeout);
}
var found = false,
node = e.target;
do {
if (node === dropZone[0]) {
found = true;
break;
}
node = node.parentNode;
} while (node !== null);
if (found) {
dropZone.addClass('hover');
} else {
dropZone.removeClass('hover');
}
window.dropZoneTimeout = setTimeout(function () {
window.dropZoneTimeout = null;
dropZone.removeClass('in hover');
}, 100);
});
}
});
})(jQuery);
31 changes: 31 additions & 0 deletions app/helpers/file_set_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# frozen_string_literal: true
module FileSetHelper
def present_terms(presenter, terms = :all, &block)
terms = presenter.terms if terms == :all
Sufia::PresenterRenderer.new(presenter, self).fields(terms, &block)
end

def show_request_file_button(file, text)
link_to "#{sufia.contact_path}?#{subject_and_message}#{main_app.root_url}#{main_app.download_path(file)}",
target: :_blank,
data: { turbolinks: false },
class: "btn btn-default" do
text
end
end

def show_request_file_action(file, text)
link_to text,
"#{sufia.contact_path}?#{subject_and_message}#{main_app.root_url}#{main_app.download_path(file)}",
title: "Download #{file.to_s.inspect}"
end

def subject_and_message
URI.encode("subject=Scholar@UC file request&message=Please contact me about obtaining a copy of the file at ")
end

def file_is_too_large_to_download(file)
max_file_size = 3_221_225_472 # 3 GB
file.respond_to?(:solr_document) && file.solr_document._source[:file_size_is].to_i > max_file_size
end
end
7 changes: 5 additions & 2 deletions app/views/contact_form/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
<% em = '' %>
<% end %>
<% subject = params['subject'] || '' %>
<% message = params['message'] || '' %>
<%= form_for @contact_form, url: sufia.contact_form_index_path,
html: { class: 'form-horizontal' } do |f| %>
<%= f.text_field :contact_method, class: 'hide' %>
Expand All @@ -24,12 +27,12 @@

<div class="form-group">
<%= f.label :subject, 'Subject', class: "col-sm-2 control-label" %>
<div class="col-sm-10"><%= f.text_field :subject, class: 'form-control', required: true %></div>
<div class="col-sm-10"><%= f.text_field :subject, value: subject, class: 'form-control', required: true %></div>
</div>

<div class="form-group">
<%= f.label :message, 'Message', class: "col-sm-2 control-label" %>
<div class="col-sm-10"><%= f.text_area :message, rows: 4, class: 'form-control', required: true %></div>
<div class="col-sm-10"><%= f.text_area :message, value: message, rows: 4, class: 'form-control', required: true %></div>
</div>

<% if current_user.blank? %>
Expand Down
45 changes: 45 additions & 0 deletions app/views/curation_concerns/file_sets/_actions.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<div class="btn-group">

<button class="btn btn-default dropdown-toggle" data-toggle="dropdown" type="button" id="dropdownMenu_<%= file_set.id %>" aria-haspopup="true">
<span class="sr-only">Press to </span>
Select an action
<span class="caret" aria-hidden="true"></span>
</button>

<ul role="menu" class="dropdown-menu dropdown-menu-right" aria-labelledby="dropdownMenu_<%= file_set.id %>">

<% if can?(:edit, file_set.id) %>
<li role="menuitem" tabindex="-1">
<%= link_to 'Edit', edit_polymorphic_path([main_app, file_set]),
{ title: "Edit #{file_set}" } %>
</li>

<li role="menuitem" tabindex="-1">
<%= link_to 'Versions', edit_polymorphic_path([main_app, file_set], anchor: 'versioning_display'),
{ title: "Display previous versions" } %>
</li>
<% end %>
<% if can?(:destroy, file_set.id) %>
<li role="menuitem" tabindex="-1">
<%= link_to 'Delete', polymorphic_path([main_app, file_set]),
method: :delete, title: "Delete #{file_set}",
data: {confirm: "Deleting #{file_set} from #{application_name} is permanent. Click OK to delete this from #{application_name}, or Cancel to cancel this operation"} %>
</li>
<% end %>
<% if can?(:read, file_set.id) %>
<li role="menuitem" tabindex="-1">
<% if file_is_too_large_to_download(file_set) %>
<%= show_request_file_action(file_set, t('curation_concerns.show.requestable_content.action_link')) %>
<% else %>
<%= link_to 'Download', main_app.download_path(file_set),
title: "Download #{file_set.to_s.inspect}", target: "_blank" %>
<% end %>
</li>
<% end %>

</ul>
</div>


Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<audio controls="controls" class="audiojs" preload="auto">
<source src="<%= main_app.download_path(file_set, file: 'ogg') %>" type="audio/ogg" />
<source src="<%= main_app.download_path(file_set, file: 'mp3') %>" type="audio/mpeg" />
Your browser does not support the audio tag.
</audio>

<% if CurationConcerns.config.display_media_download_link %>
<% if file_is_too_large_to_download(file_set) %>
<%= show_request_file_button(file_set, t('curation_concerns.show.requestable_content.audio_link')) %>
<% else %>
<%= link_to main_app.download_path(file_set),
target: :_blank,
data: { turbolinks: false },
class: "btn btn-default" do %>
<%= t('curation_concerns.show.downloadable_content.audio_link') %>
<% end %>
<% end %>
<% end %>
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<div class="no-preview">
<%= t('sufia.works.show.no_preview') %>
<% if CurationConcerns.config.display_media_download_link %>
<% if file_is_too_large_to_download(file_set) %>
<%= show_request_file_button(file_set, t('curation_concerns.show.requestable_content.default_link')) %>
<% else %>
<%= link_to main_app.download_path(file_set),
target: :_blank,
data: { turbolinks: false },
class: "btn btn-default" do %>
<%= t('curation_concerns.show.downloadable_content.default_link') %>
<% end %>
<% end %>
<% end %>
</div>
28 changes: 18 additions & 10 deletions app/views/curation_concerns/file_sets/media_display/_image.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,15 @@
class: "representative-media",
alt: "",
role: "presentation" %>
<%= link_to main_app.download_path(file_set),
target: :_blank,
data: { turbolinks: false },
class: "btn btn-default" do %>
<%= t('curation_concerns.show.downloadable_content.image_link') %>
<% if file_is_too_large_to_download(file_set) %>
<%= show_request_file_button(file_set, t('curation_concerns.show.requestable_content.image_link')) %>
<% else %>
<%= link_to main_app.download_path(file_set),
target: :_blank,
data: { turbolinks: false },
class: "btn btn-default" do %>
<%= t('curation_concerns.show.downloadable_content.image_link') %>
<% end %>
<% end %>
Expand All @@ -21,11 +25,15 @@
class: "representative-media",
alt: "",
role: "presentation" %>
<%= link_to main_app.download_path(file_set),
target: :_blank,
data: { turbolinks: false },
class: "btn btn-default" do %>
<%= t('curation_concerns.show.downloadable_content.image_link') %>
<% if file_is_too_large_to_download(file_set) %>
<%= show_request_file_button(file_set, t('curation_concerns.show.requestable_content.image_link')) %>
<% else %>
<%= link_to main_app.download_path(file_set),
target: :_blank,
data: { turbolinks: false },
class: "btn btn-default" do %>
<%= t('curation_concerns.show.downloadable_content.image_link') %>
<% end %>
<% end %>
<% else %>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<% if CurationConcerns.config.display_media_download_link %>
<div>
<h2 class="sr-only"><%= t('curation_concerns.show.downloadable_content.heading') %></h2>
<%= image_tag thumbnail_url(file_set),
class: "representative-media",
alt: "",
role: "presentation" %>
<% if file_is_too_large_to_download(file_set) %>
<%= show_request_file_button(file_set, t('curation_concerns.show.requestable_content.office_link')) %>
<% else %>
<%= link_to main_app.download_path(file_set),
data: { turbolinks: false },
target: :_blank,
class: "btn btn-default" do %>
<%= t('curation_concerns.show.downloadable_content.office_link') %>
<% end %>
<% end %>
</div>
<% else %>
<div>
<%= image_tag thumbnail_url(file_set),
class: "representative-media",
alt: "",
role: "presentation" %>
</div>
<% end %>
26 changes: 26 additions & 0 deletions app/views/curation_concerns/file_sets/media_display/_pdf.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<% if CurationConcerns.config.display_media_download_link %>
<div>
<h2 class="sr-only"><%= t('curation_concerns.show.downloadable_content.heading') %></h2>
<%= image_tag thumbnail_url(file_set),
class: "representative-media",
alt: "",
role: "presentation" %>
<% if file_is_too_large_to_download(file_set) %>
<%= show_request_file_button(file_set, t('curation_concerns.show.requestable_content.pdf_link')) %>
<% else %>
<%= link_to main_app.download_path(file_set),
target: :_blank,
data: { turbolinks: false },
class: "btn btn-default" do %>
<%= t('curation_concerns.show.downloadable_content.pdf_link') %>
<% end %>
<% end %>
</div>
<% else %>
<div>
<%= image_tag thumbnail_url(file_set),
class: "representative-media",
alt: "",
role: "presentation" %>
</div>
<% end %>
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<video controls="controls" class="video-js vjs-default-skin" data-setup="{}" preload="auto">
<source src="<%= main_app.download_path(file_set, file: 'webm') %>" type="video/webm" />
<source src="<%= main_app.download_path(file_set, file: 'mp4') %>" type="video/mp4" />
Your browser does not support the video tag.
</video>

<% if CurationConcerns.config.display_media_download_link %>
<% if file_is_too_large_to_download(file_set) %>
<%= show_request_file_button(file_set, t('curation_concerns.show.requestable_content.video_link')) %>
<% else %>
<%= link_to main_app.download_path(file_set),
target: :_blank,
data: { turbolinks: false },
class: "btn btn-default" do %>
<%= t('curation_concerns.show.downloadable_content.video_link') %>
<% end %>
<% end %>
<% end %>
21 changes: 20 additions & 1 deletion config/locales/sufia.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,27 @@ en:
terms_of_use_html: "<a class=\"a\" href=\"/terms\">Scholar@UC Terms of Use</a>"
non_discrimination_notice_html: "<a href=\"http://uc.edu/about/policies/non-discrimination.html\">Notice of Non-Discrimination</a>"
share_button: "Contribute"

curation_concerns:
base:
metadata:
header: Attributes
upload:
cloud_timeout_message_html: "If you have files on cloud storage sites such as Box, Dropbox, Google Drive, or Kaltura, you can click the \"Browse cloud files\" button to select and upload those files directly to Scholar@UC.<br /><br />Please note that if you upload a large number of files within a short period of time, the cloud provider may not be able to accommodate your request. If you experience any errors uploading from the cloud, let us know via the %{contact_href}."

curation_concerns:
base:
form_files:
external_upload: "Add Files from Cloud Providers"
show:
downloadable_content:
audio_link: 'Download audio file'
video_link: 'Download video'
requestable_content:
action_link: 'Request this file'
default_link: 'Request a copy of this file'
image_link: 'Request a copy of this image'
office_link: 'Request a copy of this file'
pdf_link: 'Request a copy of this PDF'
audio_link: 'Request a copy of this audio file'
video_link: 'Request a copy of this video'

0 comments on commit 8d3110f

Please sign in to comment.