Skip to content

Error with image URL #101

@ghost

Description

So I've got an error like that

.../node_modules/epub-gen/lib/index.js:169
            mediaType = mime.getType(url.replace(/\?.*/, ""));
                                         ^
TypeError: Cannot read properties of undefined (reading 'replace')

which I fixed by adding if

if (url) { // 162
    if (image = self.options.images.find(function(element) {
      return element.url === url;
    })) {
      id = image.id;
      extension = image.extension;
    } else {
      id = uuid();
      mediaType = mime.getType(url.replace(/\?.*/, ""));
      extension = mime.getExtension(mediaType);
      dir = content.dir;
      self.options.images.push({id, url, dir, mediaType, extension});
    }
    return $(elem).attr("src", `images/${id}.${extension}`);
}

I don't know if there is more to that - maybe an image wasn't downloaded properly - it fixed error and gave valid epub so...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions