mirror of
https://github.com/hkalexling/Mango.git
synced 2025-08-03 03:15:31 -04:00
Show unreadable archives in web interface (#49)
This commit is contained in:
parent
1b244c68b8
commit
bdba7bdd13
@ -97,3 +97,7 @@ td>.uk-dropdown {
|
||||
.item .uk-card-title {
|
||||
font-size: 1rem;
|
||||
}
|
||||
|
||||
.grayscale {
|
||||
filter: grayscale(100%);
|
||||
}
|
||||
|
@ -1,20 +1,14 @@
|
||||
class Entry
|
||||
property zip_path : String, book : Title, title : String,
|
||||
size : String, pages : Int32, id : String, title_id : String,
|
||||
encoded_path : String, encoded_title : String, mtime : Time
|
||||
encoded_path : String, encoded_title : String, mtime : Time,
|
||||
err_msg : String?
|
||||
|
||||
def initialize(path, @book, @title_id, storage)
|
||||
@zip_path = path
|
||||
@encoded_path = URI.encode path
|
||||
@title = File.basename path, File.extname path
|
||||
def initialize(@zip_path, @book, @title_id, storage)
|
||||
@encoded_path = URI.encode @zip_path
|
||||
@title = File.basename @zip_path, File.extname @zip_path
|
||||
@encoded_title = URI.encode @title
|
||||
@size = (File.size path).humanize_bytes
|
||||
file = ArchiveFile.new path
|
||||
@pages = file.entries.count do |e|
|
||||
SUPPORTED_IMG_TYPES.includes? \
|
||||
MIME.from_filename? e.filename
|
||||
end
|
||||
file.close
|
||||
@size = (File.size @zip_path).humanize_bytes
|
||||
id = storage.get_id @zip_path, false
|
||||
if id.nil?
|
||||
id = random_str
|
||||
@ -26,6 +20,28 @@ class Entry
|
||||
end
|
||||
@id = id
|
||||
@mtime = File.info(@zip_path).modification_time
|
||||
|
||||
unless File.readable? @zip_path
|
||||
@err_msg = "File #{@zip_path} is not readable."
|
||||
Logger.warn "#{@err_msg} Please make sure the " \
|
||||
"file permission is configured correctly."
|
||||
return
|
||||
end
|
||||
|
||||
archive_exception = validate_archive @zip_path
|
||||
unless archive_exception.nil?
|
||||
@err_msg = "Archive error: #{archive_exception}"
|
||||
Logger.warn "Unable to extract archive #{@zip_path}. " \
|
||||
"Ignoring it. #{@err_msg}"
|
||||
return
|
||||
end
|
||||
|
||||
file = ArchiveFile.new @zip_path
|
||||
@pages = file.entries.count do |e|
|
||||
SUPPORTED_IMG_TYPES.includes? \
|
||||
MIME.from_filename? e.filename
|
||||
end
|
||||
file.close
|
||||
end
|
||||
|
||||
def to_json(json : JSON::Builder)
|
||||
@ -50,6 +66,7 @@ class Entry
|
||||
end
|
||||
|
||||
def cover_url
|
||||
return "#{Config.current.base_url}img/icon.png" if @err_msg
|
||||
url = "#{Config.current.base_url}api/page/#{@title_id}/#{@id}/1"
|
||||
TitleInfo.new @book.dir do |info|
|
||||
info_url = info.entry_cover_url[@title]?
|
||||
@ -61,6 +78,7 @@ class Entry
|
||||
end
|
||||
|
||||
def read_page(page_num)
|
||||
raise "Unreadble archive. #{@err_msg}" if @err_msg
|
||||
img = nil
|
||||
ArchiveFile.open @zip_path do |file|
|
||||
page = file.entries
|
||||
|
@ -34,19 +34,8 @@ class Title
|
||||
next
|
||||
end
|
||||
if [".zip", ".cbz", ".rar", ".cbr"].includes? File.extname path
|
||||
unless File.readable? path
|
||||
Logger.warn "File #{path} is not readable. Please make sure the " \
|
||||
"file permission is configured correctly."
|
||||
next
|
||||
end
|
||||
archive_exception = validate_archive path
|
||||
unless archive_exception.nil?
|
||||
Logger.warn "Unable to extract archive #{path}. Ignoring it. " \
|
||||
"Archive error: #{archive_exception}"
|
||||
next
|
||||
end
|
||||
entry = Entry.new path, self, @id, storage
|
||||
@entries << entry if entry.pages > 0
|
||||
@entries << entry if entry.pages > 0 || entry.err_msg
|
||||
end
|
||||
end
|
||||
|
||||
@ -166,8 +155,9 @@ class Title
|
||||
|
||||
def cover_url
|
||||
url = "#{Config.current.base_url}img/icon.png"
|
||||
if @entries.size > 0
|
||||
url = @entries[0].cover_url
|
||||
readable_entries = @entries.select &.err_msg.nil?
|
||||
if readable_entries.size > 0
|
||||
url = readable_entries[0].cover_url
|
||||
end
|
||||
TitleInfo.new @dir do |info|
|
||||
info_url = info.cover_url
|
||||
|
@ -4,11 +4,14 @@ class ReaderRouter < Router
|
||||
def initialize
|
||||
get "/reader/:title/:entry" do |env|
|
||||
begin
|
||||
username = get_username env
|
||||
|
||||
title = (@context.library.get_title env.params.url["title"]).not_nil!
|
||||
entry = (title.get_entry env.params.url["entry"]).not_nil!
|
||||
|
||||
next layout "reader-error" if entry.err_msg
|
||||
|
||||
# load progress
|
||||
username = get_username env
|
||||
page = entry.load_progress username
|
||||
# we go back 2 * `IMGS_PER_PAGE` pages. the infinite scroll
|
||||
# library perloads a few pages in advance, and the user
|
||||
|
@ -15,11 +15,14 @@
|
||||
<% end %>>
|
||||
|
||||
<div class="acard
|
||||
<% if item.is_a? Entry %>
|
||||
<% if item.is_a? Entry && item.err_msg.nil? %>
|
||||
<%= "is_entry" %>
|
||||
<% end %>
|
||||
"
|
||||
<% if item.is_a? Entry %>
|
||||
<% if item.err_msg %>
|
||||
onclick="location='<%= base_url %>reader/<%= item.book.id %>/<%= item.id %>'"
|
||||
<% else %>
|
||||
data-encoded-path="<%= item.encoded_path %>"
|
||||
data-pages="<%= item.pages %>"
|
||||
data-progress="<%= (progress * 100).round(1) %>"
|
||||
@ -27,17 +30,21 @@
|
||||
data-encoded-title="<%= item.encoded_display_name %>"
|
||||
data-book-id="<%= item.book.id %>"
|
||||
data-id="<%= item.id %>"
|
||||
<% end %>
|
||||
<% else %>
|
||||
onclick="location='<%= base_url %>book/<%= item.id %>'"
|
||||
<% end %>>
|
||||
|
||||
<div class="uk-card uk-card-default">
|
||||
<div class="uk-card-media-top">
|
||||
<img data-src="<%= item.cover_url %>" data-width data-height alt="" uk-img>
|
||||
<img data-src="<%= item.cover_url %>" data-width data-height alt="" uk-img
|
||||
<% if item.is_a? Entry && item.err_msg %>
|
||||
class="grayscale"
|
||||
<% end %>>
|
||||
</div>
|
||||
|
||||
<div class="uk-card-body">
|
||||
<% unless progress < 0 || progress > 100 %>
|
||||
<% unless progress < 0 || progress > 100 || progress.nan? %>
|
||||
<div class="uk-card-badge label"><%= (progress * 100).round(1) %>%</div>
|
||||
<% end %>
|
||||
|
||||
@ -51,8 +58,13 @@
|
||||
<a class="uk-card-title break-word uk-margin-remove-top uk-text-meta uk-display-inline-block no-modal" data-title="<%= HTML.escape(item.book.display_name) %>" href="<%= base_url %>book/<%= item.book.id %>"><%= HTML.escape(item.book.display_name) %></a>
|
||||
<% end %>
|
||||
<% if item.is_a? Entry %>
|
||||
<% if item.err_msg %>
|
||||
<p class="uk-text-meta uk-margin-remove-bottom">Error <span uk-icon="info"></span></p>
|
||||
<div uk-dropdown><%= item.err_msg %></div>
|
||||
<% else %>
|
||||
<p class="uk-text-meta"><%= item.pages %> pages</p>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<% if item.is_a? Title %>
|
||||
<% if grouped_count == 1 %>
|
||||
<p class="uk-text-meta"><%= item.size %> entries</p>
|
||||
|
31
src/views/reader-error.html.ecr
Normal file
31
src/views/reader-error.html.ecr
Normal file
@ -0,0 +1,31 @@
|
||||
<div id="modal" class="uk-flex-top" uk-modal>
|
||||
<div class="uk-modal-dialog uk-margin-auto-vertical">
|
||||
<button class="uk-modal-close-default" type="button" uk-close></button>
|
||||
<div class="uk-modal-header">
|
||||
<div>
|
||||
<h3 class="uk-modal-title uk-margin-remove-top">Error</h3>
|
||||
</div>
|
||||
<p class="uk-text-meta uk-margin-remove-bottom"><%= entry.zip_path %></p>
|
||||
<p class="uk-text-meta uk-margin-remove-top"><%= entry.err_msg %></p>
|
||||
</div>
|
||||
<div class="uk-modal-body">
|
||||
<p uk-margin>
|
||||
<% if next_entry = entry.next_entry username %>
|
||||
<a class="uk-button uk-button-default" href="<%= base_url %>reader/<%= entry.book.id %>/<%= next_entry.id %>">Next Entry</a>
|
||||
<% end %>
|
||||
<a class="uk-button uk-button-primary" href="<%= base_url %>book/<%= entry.book.id %>">Return to Title</a>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<% content_for "script" do %>
|
||||
<script>
|
||||
UIkit.modal('#modal').show().then(function() {
|
||||
styleModal();
|
||||
});
|
||||
UIkit.util.on('#modal', 'hide', function() {
|
||||
location.href = "<%= base_url %>book/<%= entry.book.id %>";
|
||||
});
|
||||
</script>
|
||||
<% end %>
|
Loading…
x
Reference in New Issue
Block a user