Add script to serve single archive
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
8fb59ada9c
commit
137ae1b712
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,4 +1,5 @@
|
|||
cache
|
||||
__pycache__
|
||||
|
||||
node_modules
|
||||
/frontend/dist
|
||||
|
|
50
local_reader.py
Executable file
50
local_reader.py
Executable file
|
@ -0,0 +1,50 @@
|
|||
#!/usr/bin/env python3
|
||||
from flask import Flask, jsonify, render_template, Response
|
||||
from mimetypes import types_map as mimetypes
|
||||
from zipfile import ZipFile
|
||||
import logging
|
||||
import os
|
||||
import sys
|
||||
import webbrowser
|
||||
import werkzeug.exceptions as exceptions
|
||||
|
||||
# disable access log
|
||||
log = logging.getLogger('werkzeug')
|
||||
log.setLevel(logging.ERROR)
|
||||
# disable flask startup message
|
||||
os.environ['WERKZEUG_RUN_MAIN'] = 'true'
|
||||
|
||||
mimetypes['.webp'] = 'image/webp'
|
||||
archive = ZipFile(sys.argv[1], 'r')
|
||||
app = Flask(__name__, static_folder='frontend/dist/static', template_folder='frontend/dist')
|
||||
|
||||
# kind of redundant, but avoids returning 200 if page does not exist
|
||||
@app.route('/')
|
||||
@app.route('/series/0')
|
||||
@app.route('/volume/0')
|
||||
def serve_app(**kwargs):
|
||||
return render_template('index.html')
|
||||
|
||||
|
||||
@app.route('/api/volume/0')
|
||||
def get_volume_info():
|
||||
return jsonify({
|
||||
'pages': len(archive.filelist),
|
||||
'series': 0,
|
||||
'title': 'local'
|
||||
})
|
||||
|
||||
|
||||
@app.route('/api/volume/0/page/<int:page_number>')
|
||||
def get_volume_page(page_number):
|
||||
try:
|
||||
page = archive.filelist[page_number - 1]
|
||||
except IndexError:
|
||||
raise exceptions.NotFound() from None
|
||||
mimetype = mimetypes[os.path.splitext(page.filename)[1]]
|
||||
return Response(archive.read(page.filename), mimetype=mimetype)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
webbrowser.open('http://localhost:5051/volume/0')
|
||||
app.run(host='127.0.0.1', port=5051)
|
Reference in a new issue