Skip to content

Instantly share code, notes, and snippets.

@mankind
Last active January 30, 2019 09:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mankind/5af3a69b04a1ca0123551a13c43582fc to your computer and use it in GitHub Desktop.
Save mankind/5af3a69b04a1ca0123551a13c43582fc to your computer and use it in GitHub Desktop.
general-notes
#app/services/ubiquity/add_file.rb
#this works as it is called whilr creating hte file, however all efforts to set the file_size field failed
module Ubiquity
module AddFile
#private
=begin
def attach_attributes(file)
puts "lagos"
::Ubiquity::DetermineFileSize.call(file)
current_file.content = file
current_file.original_name = DetermineOriginalName.call(file)
current_file.mime_type = DetermineMimeType.call(file, current_file.original_name)
end
=end
def create_content(file, relation = :original_file, from_url: false)
puts "bali #{file.file.size.inspect}"
puts "sam #{file_set.file_size.inspect}"
puts "bad #{file.try(:file).try(:size)}"
# If the file set doesn't have a title or label assigned, set a default.
file_set.label ||= label_for(file)
file_set.title = [file_set.label] if file_set.title.blank?
file_set.file_size << file.file.size
puts "kpomo #{file_set.file_size.inspect}"
return false unless file_set.save # Need to save to get an id
if from_url
# If ingesting from URL, don't spawn an IngestJob; instead
# reach into the FileActor and run the ingest with the file instance in
# hand. Do this because we don't have the underlying UploadedFile instance
file_actor = build_file_actor(relation)
file_actor.ingest_file(wrapper!(file: file, relation: relation))
# Copy visibility and permissions from parent (work) to
# FileSets even if they come in from BrowseEverything
VisibilityCopyJob.perform_later(file_set.parent)
InheritPermissionsJob.perform_later(file_set.parent)
else
IngestJob.perform_later(wrapper!(file: file, relation: relation))
end
end
end
end
###### config/application.rb
config.to_prepare do
#Hydra::Works::AddFileToFileSet.prepend(::Ubiquity::AddFile)
Hyrax::Actors::FileSetActor.prepend(::Ubiquity::AddFile)
end
#### app/services/ubiquity/determine_file_size.rb
#this did not work
#module Hydra::Works
module Ubiquity
class DetermineFileSize
# Determines the original name for a given file
# @param [IO, File, Rack::Multipart::UploadedFile] file
# @return [String]
def self.call(file)
puts "mona #{file.inspect}"
puts "mero #{file.methods - Object.methods}"
=begin
return file.original_name if file.respond_to?(:original_name)
return file.original_filename if file.respond_to?(:original_filename)
return ::File.basename(file.path) if file.respond_to?(:path)
''
=end
end
end
end
https://medium.com/@vhbueno/rails-5-turbolinks-and-google-tag-manager-b3c4c30c3fb7
https://gorails.com/forum/how-do-i-install-google-tag-manager-in-a-rails-5-app
http://labs.wrprojects.com/how-to-use-google-tag-manager-with-rails-and-turbolinks/
https://www.netguru.com/codestories/5-things-i-learned-about-google-tag-manager
*https://github.com/koic/gtm_rails
https://github.com/rcs/google-tag-manager-rails
https://blog.codeship.com/creating-configuration-objects-in-ruby/
https://blog.arkency.com/custom-application-configuration-variables-in-rails-4-and-5/
https://github.com/ubiquitypress/hyku/blob/test/app/views/shared/ubiquity/search_display/_show_array_hash.html.erb
more-thumbnails-and-embargo-file-search-display
https://launchschool.com/books/ruby/read/flow_control
https://mensfeld.pl/2017/06/sidekiq-unique-jobs-dont-waste-your-time-waiting-reschedule-if-busy/
render shared/ubiquity/search_display/show_array_hash
https://github.com/samvera/hydra-head/wiki/Lesson:-make-blacklight-return-search-results
http://samvera.github.io/building-searches.html
http://lucene.apache.org/solr/guide/7_6/solr-tutorial.html
https://github.com/projectblacklight/blacklight/wiki/Quickstart
Replace themed admin dashboard with standard bootstrap controls
https://github.com/samvera/sufia/commit/743ae5d39292147fe4f992f70bdd71ec268a37be
https://github.com/samvera/sufia/commit/16c01d83abc2681aedb8c5de94a3f4e3d9b6f6dd
Thumbnails should be generated consistently based on your view #2867
https://github.com/samvera/sufia/issues/2867
implementing a custom template layout in sufia/hyrax
https://groups.google.com/forum/#!topic/samvera-tech/M9nee0IsXtI
creator_search metadield
search sidebar is now able to display and search data from creator js…
https://github.com/ubiquitypress/hyku/pull/109
https://github.com/samvera/sufia/wiki/Sufia-Management-Guide#analytics-and-usage-statistics
####
How to integrate Hyrax's Google Analytics user stats into your Rails app
https://github.com/samvera/hyrax/wiki/How-to-integrate-Hyrax's-Google-Analytics-user-stats-into-your-Rails-app
git clone git@github.com:ubiquitypress/hyku.git
when you navigate to a work and click of the file name it opens a page eg https://bl.oar.bl.uk/concern/parent/b4ec6e34-f83d-40c7-8135-3542dba4c050/file_sets/58e93709-bcf3-48b6-b496-d58c005d81d6
from where you can download or delete or edit the file
https://github.com/samvera/hyrax/blob/master/app/views/hyrax/file_sets/show.html.erb
https://github.com/samvera/hyrax/blob/master/app/views/hyrax/file_sets/_show_actions.html.erb
https://github.com/samvera/hyrax/blob/master/app/views/hyrax/file_sets/_show_details.html.erb
https://github.com/samvera/hyrax/blob/master/app/helpers/hyrax/file_set_helper.rb#L13
report the issue via the <%= link_to 'Contact Form', hyrax.contact_form_index_path %>.
https://github.com/samvera/hyrax/blob/5a9d1be16ee1a9150646384471992b03aab527a5/app/views/hyrax/static/mendeley.html.erb
https://github.com/samvera/hyrax/blob/5a9d1be16ee1a9150646384471992b03aab527a5/app/views/hyrax/contact_mailer/contact.html.erb
https://github.com/samvera/hyrax/search?q=Contact+Form&unscoped_q=Contact+Form
https://github.com/samvera/hyrax/blob/master/app/controllers/hyrax/contact_form_controller.rb
hyku file upload limit from frontend
https://github.com/samvera/hyrax/blob/5a9d1be16ee1a9150646384471992b03aab527a5/vendor/assets/javascripts/fileupload/jquery.fileupload.js#L125
hyrax file upload limit from the backend
https://github.com/samvera/hyrax/blob/fa8f81bfbbea81b9fa7338f7e98c2586d6aec0ad/lib/hyrax/configuration.rb#L525-L528
m = (f.size.to_f/(1000 * 1000)).round(2)
m = (f.size.to_f/(1024 * 1024)).round(2)
AttachFilesToWorkJob
CreateDirevativeJobs
IngestJob
CharacterizeJob
https://fontawesome.com/v4.7.0/examples/
http://mitrev.net/ruby/2015/11/13/the-operator-in-ruby/
https://web.stanford.edu/~ouster/cgi-bin/cs142-winter15/classEval.php
http://leohetsch.com/include-vs-prepend-vs-extend/
https://www.jimmycuadra.com/posts/metaprogramming-ruby-class-eval-and-instance-eval/
#########
zip-thumbnail-homepage
width:100px;
http://railsapps.github.io/rails-environment-variables.html
https://tecadmin.net/install-google-chrome-in-ubuntu/
https://trello.com/c/EyUvCmWJ/425-01-use-default-icon-where-there-is-a-file-but-no-thumbnail-created-yet
https://trello.com/c/wBa3vjeS/431-01-default-icon-for-doc-docx-where-thumbnail-has-not-been-generated
fix display of json on search result page. That is the main content
https://github.com/ubiquitypress/hyku/commit/37905a3d5e079a69b08a5f4a2e807f045cc55bf9#diff-36bf2f01a3336115100e02aed50687aa
To adjust tthumbnails touch
modified: app/helpers/multiple_metadata_fields_helper.rb
modified: app/views/shared/ubiquity/_thumbnail_icons.html.erb
modified: app/views/shared/ubiquity/_thumbnail_icons_with_restrictions.html.erb
modified: app/views/shared/ubiquity/file_sets/_restricted_media.html.erb
modified: app/views/shared/ubiquity/search_display/_search_thumbnail.html.erb
modified: app/views/shared/ubiquity/works/_member.html.erb
For now the following has been implemented with regards to thumbnail and on sandbox:
1. If a word document doesn't have thumbnail, we will display a word file icon.
2. For pdf files without icons, we will display a pdf file icon
3. Any file that has an archive format eg .zip etc, we will display a zip file icon.
4. For all other file formats not covered above, we will display a normal file icon.
5. Finally for files under embargo/lease irrespective of whether they have thumbnails or not, they will display a file icon for anyone who is not the owner or an admin.
require 'sidekiq'
require 'sidekiq/web'
Sidekiq::Web.use(Rack::Auth::Basic) do |user, password|
[user, password] == [ENV["SIDEKIQ_USERNAME"], ENV["SIDEKIQ_PASSWORD"]]
end
use Rack::Auth::Basic, "Protected Area" do |username, password|
# Protect against timing attacks:
# - See https://codahale.com/a-lesson-in-timing-attacks/
# - See https://thisdata.com/blog/timing-attacks-against-string-comparison/
# - Use & (do not use &&) so that it doesn't short circuit.
# - Use digests to stop length information leaking
Rack::Utils.secure_compare(::Digest::SHA256.hexdigest(username), ::Digest::SHA256.hexdigest(ENV["SIDEKIQ_USERNAME"])) &
Rack::Utils.secure_compare(::Digest::SHA256.hexdigest(password), ::Digest::SHA256.hexdigest(ENV["SIDEKIQ_PASSWORD"]))
end
https://github.com/carrierwaveuploader/carrierwave/wiki/How-to%3A-Validate-image-file-size
https://www.rubydoc.info/gems/hydra-pcdm
#fileset.original_file returns a hydra-pcdm object
fileset.original_file.size
docker-compose -f docker/docker-compose.yml -f docker/docker-compose.dev.yml up
# called from the app/models/concerns/ubiquity/all_models_virtual_fields.rb but results in duplicate multiple jobs
class UbiquitySetFileSizeJob < ActiveJob::Base
def perform(work_id)
w = ActiveFedora::Base.find(work_id)
puts "ford #{w.inspect}"
puts "jeep #{w.thumbnail}"
puts "some #{w.thumbnail.try(:file_size)}"
if w.thumbnail.present? && !w.thumbnail.try(:file_size).empty?
s = w.thumbnail.file_size << w.thumbnail.original_file.size
puts "gmail #{s.inspect}"
puts "suliya #{w.thumbnail.file_size.inspect}"
w.thumbnail.save
else w.thumbnail.present? && w.thumbnail.try(:file_size).present? && w.thumbnail.file_size != w.thumbnail.original_file.size
puts "file_size etc"
w.thumbnail.file_size << w.thumbnail.original_file.size
w.thumbnail.save
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment