2022-02-13 13:00:10 +09:00
|
|
|
import secrets
|
|
|
|
import toml
|
|
|
|
from collections import OrderedDict
|
|
|
|
|
|
|
|
from quart import Quart
|
|
|
|
from werkzeug.security import generate_password_hash
|
|
|
|
|
2022-02-14 19:16:09 +09:00
|
|
|
from anonstream.utils.users import generate_token
|
2022-02-13 18:25:02 +09:00
|
|
|
from anonstream.segments import DirectoryCache
|
2022-02-13 13:00:10 +09:00
|
|
|
|
|
|
|
async def create_app():
|
|
|
|
with open('config.toml') as fp:
|
|
|
|
config = toml.load(fp)
|
|
|
|
|
|
|
|
auth_password = secrets.token_urlsafe(6)
|
|
|
|
auth_pwhash = generate_password_hash(auth_password)
|
2022-02-15 19:11:53 +09:00
|
|
|
print('Broadcaster username:', config['auth']['username'])
|
2022-02-13 13:00:10 +09:00
|
|
|
print('Broadcaster password:', auth_password)
|
|
|
|
|
|
|
|
app = Quart('anonstream')
|
2022-02-13 18:25:02 +09:00
|
|
|
app.config['SECRET_KEY'] = config['secret_key'].encode()
|
2022-02-15 19:11:53 +09:00
|
|
|
app.config['AUTH_USERNAME'] = config['auth']['username']
|
2022-02-13 13:00:10 +09:00
|
|
|
app.config['AUTH_PWHASH'] = auth_pwhash
|
|
|
|
app.config['AUTH_TOKEN'] = generate_token()
|
2022-02-15 19:11:53 +09:00
|
|
|
app.config['DEFAULT_HOST_NAME'] = config['names']['broadcaster']
|
|
|
|
app.config['DEFAULT_ANON_NAME'] = config['names']['anonymous']
|
|
|
|
app.config['LIMIT_NOTICES'] = config['limits']['notices']
|
2022-02-13 13:00:10 +09:00
|
|
|
app.chat = OrderedDict()
|
2022-02-14 19:16:09 +09:00
|
|
|
app.users = {}
|
|
|
|
app.websockets = set()
|
2022-02-15 19:11:53 +09:00
|
|
|
app.segments_directory_cache = DirectoryCache(config['stream']['segments_dir'])
|
2022-02-13 13:00:10 +09:00
|
|
|
|
|
|
|
async with app.app_context():
|
|
|
|
import anonstream.routes
|
|
|
|
|
|
|
|
return app
|