-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Set file size upload and download limits
- Loading branch information
Showing
16 changed files
with
723 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
|
||
|
18 changes: 18 additions & 0 deletions
18
app/views/curation_concerns/file_sets/media_display/_audio.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 %> |
15 changes: 15 additions & 0 deletions
15
app/views/curation_concerns/file_sets/media_display/_default.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
app/views/curation_concerns/file_sets/media_display/_office_document.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
26
app/views/curation_concerns/file_sets/media_display/_pdf.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 %> |
18 changes: 18 additions & 0 deletions
18
app/views/curation_concerns/file_sets/media_display/_video.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.