Ticket #987 (closed Defect: fixed)

Opened 5 years ago

Last modified 5 years ago

DM4 Images throws if file has no media type

Reported by: jri Owned by:
Priority: Major Milestone:
Component: 3rd Party Plugins Version:
Keywords: Cc: dgf, Malte, JuergeN
Complexity: 3 Area:
Module:

Description

When clicking a File topic whose Media Type is not set (= unknown, e.g. for .md files) the DM4 Images throws a client-side error:

TypeError: undefined is not an object (evaluating 'topic.childs["dm4.files.media_type"].value')

As a consequence the File topic's context menu is not available.

Change History

comment:1 Changed 5 years ago by Malte

  • Status changed from new to closed
  • Resolution set to fixed

The following commit fixes this issue and as a result the context menu of the dm4-webclient should appear normally again - also for files with an "unknown" Media Type.

https://github.com/mukil/dm4-images/commit/6e7e513cb9fc0460c2379b7321eb3f54b15e2bc8

Thanks for trying the new version and reporting this issue.

comment:2 Changed 5 years ago by jri

Thanks for fixing!

Just a tiny hint: instead of

if (topic.childs.hasOwnProperty("dm4.files.media_type")) {
    if (topic.childs["dm4.files.media_type"].value === "image/jpeg" ||
        topic.childs["dm4.files.media_type"].value === "image/png") {

you might write:

var media_type = topic.childs["dm4.files.media_type"]
if (media_type) {
    if (media_type.value == "image/jpeg" ||
        media_type.value == "image/png") {

This is better to read and reduces property lookups.

You might also want respect all image types by just testing the primary media type ("image/").

comment:3 Changed 5 years ago by Malte

Thanks for your comment, i applied your suggestion.

Regarding support for all image types (see here a list of possibilities) - to not include others (specifically those i could not test) was my deliberate decision. Do you have any specific formats you use or generally in mind i should test this resize operation with?

The implementation around the Java2D wrapper i use here (at least according to its docs) currently produces "good results" only with JPEGs and PNGs. For more details on it see also for example the Working with GIFs section here.

Thanks for sharing your thoughts!

comment:4 Changed 5 years ago by jri

OK, thanks for the info!
I'm fine with PNG and JPEG.

Note: See TracTickets for help on using tickets.