-
Notifications
You must be signed in to change notification settings - Fork 62
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
652: added Document (file) media type #668
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -127,6 +127,7 @@ def media_type | |
when "image", "annotated_image", "sketch", "signature" then "image/*" | ||
when "audio" then "audio/*" | ||
when "video" then "video/*" | ||
when "document" then "document/*" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Has this been tested in ODK Collect? What does it do? I know that image, audio, and video have specific meanings in Collect but I haven't heard of "document" in that context. If it's not supported by ODK then we should not be rendering this question type when rendering for Collect, and this deliberate omission should be tested in the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi @smoyth. Yes, we've tested in ODK collect and also in Nemo web interface. I've tested by uploading a document (pdf, odt, doc) in the collect, the answer was saved and after I could download/preview that document in the answer screen. This also worked in the web interface. |
||
end | ||
end | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,9 +6,20 @@ module Mediable | |
extend ActiveSupport::Concern | ||
|
||
# video/ogg is needed for audio OGG files for some weird reason. | ||
# application/x-ole-storage is needed sometimes due to issue: https://github.com/minad/mimemagic/issues/50 | ||
ODK_MEDIA_MIME_TYPES = %w[audio/mpeg audio/ogg audio/wave audio/wav audio/x-wav audio/x-pn-wav | ||
audio/flac video/ogg application/ogg video/mp4 image/png image/jpeg].freeze | ||
ODK_MEDIA_EXTS = {audio: %w[mp3 ogg wav flac], video: %w[mp4], image: %w[png jpg jpeg]}.freeze | ||
audio/flac video/ogg application/ogg video/mp4 image/png image/jpeg | ||
application/msword application/vnd.oasis.opendocument.spreadsheet | ||
application/vnd.ms-excel | ||
application/vnd.openxmlformats-officedocument.spreadsheetml.sheet | ||
application/vnd.openxmlformats-officedocument.wordprocessingml.document | ||
application/vnd.openxmlformats-officedocument.presentationml.presentation | ||
application/vnd.oasis.opendocument.text application/pdf | ||
application/vnd.ms-powerpoint text/csv application/rtf text/plain | ||
application/vnd.oasis.opendocument.presentation | ||
application/x-ole-storage].freeze | ||
ODK_MEDIA_EXTS = {audio: %w[mp3 ogg wav flac], video: %w[mp4], image: %w[png jpg jpeg], | ||
document: %w[pdf xls xlsx ods doc docx odt rtf ppt pptx odp csv txt]}.freeze | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If ODK doesn't support the document type then all of this can be removed, yes? |
||
|
||
class_methods do | ||
def odk_media_attachment(col_name) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# frozen_string_literal: true | ||
|
||
# rubocop:disable Metrics/LineLength | ||
# == Schema Information | ||
# | ||
# Table name: media_objects | ||
# | ||
# id :uuid not null, primary key | ||
# item_content_type :string(255) not null | ||
# item_file_name :string(255) not null | ||
# item_file_size :integer not null | ||
# item_updated_at :datetime not null | ||
# type :string(255) not null | ||
# created_at :datetime not null | ||
# updated_at :datetime not null | ||
# answer_id :uuid | ||
# | ||
# Indexes | ||
# | ||
# index_media_objects_on_answer_id (answer_id) | ||
# | ||
# Foreign Keys | ||
# | ||
# media_objects_answer_id_fkey (answer_id => answers.id) ON DELETE => restrict ON UPDATE => restrict | ||
# | ||
# rubocop:enable Metrics/LineLength | ||
|
||
module Media | ||
# Document-type Answer attachment. | ||
class Document < ::Media::Object | ||
# A note on validation: | ||
# We no longer validate file extensions because we can't anticipate what extensions folks | ||
# will be sending from ODK Collect (since the platform changes over time) | ||
# and there is no easy way to allow the user to correct behavior on validation fail-we just have to | ||
# discard the file. So for that we reason we limit to mime type validation only since that still | ||
# provides some security but is less restrictive and less superficial. | ||
validates_attachment_content_type :item, content_type: [ | ||
"text/csv", "text/plain", "application/pdf", "application/rtf", | ||
viniciuscb marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"application/msword", "application/vnd.ms-excel", "application/vnd.ms-powerpoint", | ||
"application/vnd.oasis.opendocument.spreadsheet", "application/vnd.oasis.opendocument.text", | ||
"application/vnd.oasis.opendocument.presentation", | ||
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", | ||
"application/vnd.openxmlformats-officedocument.wordprocessingml.document", | ||
"application/vnd.openxmlformats-officedocument.presentationml.presentation", | ||
viniciuscb marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# sometimes mimemagic returns x-ole-storage for msoffice files: https://github.com/minad/mimemagic/issues/50 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the comment! |
||
"application/x-ole-storage" | ||
] | ||
|
||
def static_thumb_path | ||
"media/document.png" | ||
end | ||
|
||
def kind | ||
"document" | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -75,6 +75,10 @@ class QuestionType | |
name: "video", | ||
odk_name: "binary", | ||
properties: %w[multimedia] | ||
}, { | ||
name: "document", | ||
odk_name: "binary", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe don't need this? |
||
properties: %w[multimedia] | ||
}] | ||
|
||
# looks up a question type by name | ||
|
@@ -124,7 +128,7 @@ def human_name | |
def media_type | ||
case name | ||
when "image", "annotated_image", "signature", "sketch" then "image" | ||
when "audio", "video" then name | ||
when "audio", "video", "document" then name | ||
end | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If ODK document media prompts aren't supported then this should be removed too.