mirror of
https://github.com/hkalexling/Mango.git
synced 2025-08-02 19:05:32 -04:00
- make the page parameter in reader the actual page number instead of
index
This commit is contained in:
parent
d36aed3595
commit
87255e8996
@ -57,12 +57,12 @@ $('#page-select').change(function(){
|
|||||||
jumpTo(parseInt($('#page-select').val()));
|
jumpTo(parseInt($('#page-select').val()));
|
||||||
});
|
});
|
||||||
function showControl(idx) {
|
function showControl(idx) {
|
||||||
$('#page-select').val(idx + 1);
|
$('#page-select').val(idx);
|
||||||
UIkit.modal($('#modal-sections')).show();
|
UIkit.modal($('#modal-sections')).show();
|
||||||
}
|
}
|
||||||
function jumpTo(page) {
|
function jumpTo(page) {
|
||||||
var ary = window.location.pathname.split('/');
|
var ary = window.location.pathname.split('/');
|
||||||
ary[ary.length - 1] = page - 1;
|
ary[ary.length - 1] = page;
|
||||||
ary.shift(); // remove leading `/`
|
ary.shift(); // remove leading `/`
|
||||||
ary.unshift(window.location.origin);
|
ary.unshift(window.location.origin);
|
||||||
window.location.replace(ary.join('/'));
|
window.location.replace(ary.join('/'));
|
||||||
|
@ -32,7 +32,7 @@ class Entry
|
|||||||
MIME.from_filename? e.filename
|
MIME.from_filename? e.filename
|
||||||
}
|
}
|
||||||
.size
|
.size
|
||||||
@cover_url = "/api/page/#{@book_title}/#{title}/0"
|
@cover_url = "/api/page/#{@book_title}/#{title}/1"
|
||||||
end
|
end
|
||||||
def read_page(page_num)
|
def read_page(page_num)
|
||||||
Zip::File.open @zip_path do |file|
|
Zip::File.open @zip_path do |file|
|
||||||
@ -42,7 +42,7 @@ class Entry
|
|||||||
MIME.from_filename? e.filename
|
MIME.from_filename? e.filename
|
||||||
}
|
}
|
||||||
.sort { |a, b| a.filename <=> b.filename }
|
.sort { |a, b| a.filename <=> b.filename }
|
||||||
.[page_num]
|
.[page_num - 1]
|
||||||
page.open do |io|
|
page.open do |io|
|
||||||
slice = Bytes.new page.uncompressed_size
|
slice = Bytes.new page.uncompressed_size
|
||||||
bytes_read = io.read_fully? slice
|
bytes_read = io.read_fully? slice
|
||||||
|
12
src/mango.cr
12
src/mango.cr
@ -163,11 +163,11 @@ get "/reader/:title/:entry" do |env|
|
|||||||
|
|
||||||
# load progress
|
# load progress
|
||||||
username = get_username env
|
username = get_username env
|
||||||
page = (title.load_progress username, entry.title) - 1
|
page = title.load_progress username, entry.title
|
||||||
# we go back 2 * `IMGS_PER_PAGE` pages. the infinite scroll library
|
# we go back 2 * `IMGS_PER_PAGE` pages. the infinite scroll library
|
||||||
# perloads a few pages in advance, and the user might not have actually
|
# perloads a few pages in advance, and the user might not have actually
|
||||||
# read them
|
# read them
|
||||||
page = [page - 2 * IMGS_PER_PAGE, 0].max
|
page = [page - 2 * IMGS_PER_PAGE, 1].max
|
||||||
|
|
||||||
env.redirect "/reader/#{title.title}/#{entry.title}/#{page}"
|
env.redirect "/reader/#{title.title}/#{entry.title}/#{page}"
|
||||||
rescue
|
rescue
|
||||||
@ -180,19 +180,19 @@ get "/reader/:title/:entry/:page" do |env|
|
|||||||
title = (library.get_title env.params.url["title"]).not_nil!
|
title = (library.get_title env.params.url["title"]).not_nil!
|
||||||
entry = (title.get_entry env.params.url["entry"]).not_nil!
|
entry = (title.get_entry env.params.url["entry"]).not_nil!
|
||||||
page = env.params.url["page"].to_i
|
page = env.params.url["page"].to_i
|
||||||
raise "" if page >= entry.pages
|
raise "" if page > entry.pages
|
||||||
|
|
||||||
# save progress
|
# save progress
|
||||||
username = get_username env
|
username = get_username env
|
||||||
title.save_progress username, entry.title, page + 1
|
title.save_progress username, entry.title, page
|
||||||
|
|
||||||
pages = (page...[entry.pages, page + IMGS_PER_PAGE].min)
|
pages = (page...[entry.pages + 1, page + IMGS_PER_PAGE].min)
|
||||||
urls = pages.map { |idx|
|
urls = pages.map { |idx|
|
||||||
"/api/page/#{title.title}/#{entry.title}/#{idx}" }
|
"/api/page/#{title.title}/#{entry.title}/#{idx}" }
|
||||||
reader_urls = pages.map { |idx|
|
reader_urls = pages.map { |idx|
|
||||||
"/reader/#{title.title}/#{entry.title}/#{idx}" }
|
"/reader/#{title.title}/#{entry.title}/#{idx}" }
|
||||||
next_page = page + IMGS_PER_PAGE
|
next_page = page + IMGS_PER_PAGE
|
||||||
next_url = next_page >= entry.pages ? nil :
|
next_url = next_page > entry.pages ? nil :
|
||||||
"/reader/#{title.title}/#{entry.title}/#{next_page}"
|
"/reader/#{title.title}/#{entry.title}/#{next_page}"
|
||||||
exit_url = "/book/#{title.title}"
|
exit_url = "/book/#{title.title}"
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user