mirror of
https://github.com/hkalexling/Mango.git
synced 2025-08-03 11:25:29 -04:00
Support webp (#69, nice)
This commit is contained in:
parent
4c2cf64f53
commit
dc084aff7c
@ -4,6 +4,8 @@ require "uri"
|
|||||||
require "./util"
|
require "./util"
|
||||||
require "./archive"
|
require "./archive"
|
||||||
|
|
||||||
|
SUPPORTED_IMG_TYPES = ["image/jpeg", "image/png", "image/webp"]
|
||||||
|
|
||||||
struct Image
|
struct Image
|
||||||
property data : Bytes
|
property data : Bytes
|
||||||
property mime : String
|
property mime : String
|
||||||
@ -27,7 +29,7 @@ class Entry
|
|||||||
@size = (File.size path).humanize_bytes
|
@size = (File.size path).humanize_bytes
|
||||||
file = ArchiveFile.new path
|
file = ArchiveFile.new path
|
||||||
@pages = file.entries.count do |e|
|
@pages = file.entries.count do |e|
|
||||||
["image/jpeg", "image/png"].includes? \
|
SUPPORTED_IMG_TYPES.includes? \
|
||||||
MIME.from_filename? e.filename
|
MIME.from_filename? e.filename
|
||||||
end
|
end
|
||||||
file.close
|
file.close
|
||||||
@ -72,7 +74,7 @@ class Entry
|
|||||||
ArchiveFile.open @zip_path do |file|
|
ArchiveFile.open @zip_path do |file|
|
||||||
page = file.entries
|
page = file.entries
|
||||||
.select { |e|
|
.select { |e|
|
||||||
["image/jpeg", "image/png"].includes? \
|
SUPPORTED_IMG_TYPES.includes? \
|
||||||
MIME.from_filename? e.filename
|
MIME.from_filename? e.filename
|
||||||
}
|
}
|
||||||
.sort { |a, b|
|
.sort { |a, b|
|
||||||
|
@ -224,7 +224,7 @@ class APIRouter < Router
|
|||||||
entry_id = env.params.query["entry"]?
|
entry_id = env.params.query["entry"]?
|
||||||
title = @context.library.get_title(title_id).not_nil!
|
title = @context.library.get_title(title_id).not_nil!
|
||||||
|
|
||||||
unless ["image/jpeg", "image/png"].includes? \
|
unless SUPPORTED_IMG_TYPES.includes? \
|
||||||
MIME.from_filename? filename
|
MIME.from_filename? filename
|
||||||
raise "The uploaded image must be either JPEG or PNG"
|
raise "The uploaded image must be either JPEG or PNG"
|
||||||
end
|
end
|
||||||
|
@ -72,7 +72,7 @@
|
|||||||
<span uk-icon="icon: cloud-upload"></span>
|
<span uk-icon="icon: cloud-upload"></span>
|
||||||
<span class="uk-text-middle">Upload a cover image by dropping it here or</span>
|
<span class="uk-text-middle">Upload a cover image by dropping it here or</span>
|
||||||
<div uk-form-custom>
|
<div uk-form-custom>
|
||||||
<input type="file" accept="image/jpeg, image/png">
|
<input type="file" accept="<%= SUPPORTED_IMG_TYPES.join ", " %>">
|
||||||
<span class="uk-link">selecting one</span>
|
<span class="uk-link">selecting one</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user