Add script to serve single archive
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Simon Bruder 2019-12-06 23:08:27 +00:00
parent 8fb59ada9c
commit 137ae1b712
No known key found for this signature in database
GPG key ID: 6F03E0000CC5B62F
2 changed files with 51 additions and 0 deletions

1
.gitignore vendored
View file

@ -1,4 +1,5 @@
cache cache
__pycache__
node_modules node_modules
/frontend/dist /frontend/dist

50
local_reader.py Executable file
View 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)