forked from pyload/pyload
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebinterface.py
More file actions
100 lines (76 loc) · 2.52 KB
/
webinterface.py
File metadata and controls
100 lines (76 loc) · 2.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/usr/bin/env python
# -*- coding: utf-8 -*-
###############################################################################
# Copyright(c) 2008-2013 pyLoad Team
# http://www.pyload.org
#
# This file is part of pyLoad.
# pyLoad is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# Subjected to the terms and conditions in LICENSE
#
# @author: RaNaN
###############################################################################
import sys
from os.path import join, abspath, dirname, exists
PROJECT_DIR = abspath(dirname(__file__))
PYLOAD_DIR = abspath(join(PROJECT_DIR, "..", ".."))
import bottle
from bottle import run, app
from middlewares import StripPathMiddleware, PrefixMiddleware
SETUP = None
PYLOAD = None
import ServerThread
if not ServerThread.core:
if ServerThread.setup:
SETUP = ServerThread.setup
config = SETUP.config
else:
raise Exception("Could not access pyLoad Core")
else:
PYLOAD = ServerThread.core.api
config = ServerThread.core.config
from pyload.utils.JsEngine import JsEngine
JS = JsEngine()
TEMPLATE = config.get('webUI', 'template')
DL_ROOT = config.get('general', 'download_folder')
PREFIX = config.get('webUI', 'prefix')
if PREFIX:
PREFIX = PREFIX.rstrip("/")
if PREFIX and not PREFIX.startswith("/"):
PREFIX = "/" + PREFIX
APP_PATH = "app"
UNAVAILALBE = True
# webUI build is available
if exists(join(PROJECT_DIR, "app", "components")) and exists(join(PROJECT_DIR, ".tmp")) and config.get('webUI', 'develop'):
UNAVAILALBE = False
elif exists(join(PROJECT_DIR, "dist", "index.html")):
APP_PATH = "dist"
UNAVAILALBE = False
DEBUG = config.get("general", "debug_mode") or "-d" in sys.argv or "--debug" in sys.argv
bottle.debug(DEBUG)
# Middlewares
from beaker.middleware import SessionMiddleware
session_opts = {
'session.type': 'file',
'session.cookie_expires': False,
'session.data_dir': './tmp',
'session.auto': False
}
session = SessionMiddleware(app(), session_opts)
web = StripPathMiddleware(session)
if PREFIX:
web = PrefixMiddleware(web, prefix=PREFIX)
import api_app
import cnl_app
import setup_app
# Last routes to register,
import pyload_app
# Server Adapter
def run_server(host, port, server):
run(app=web, host=host, port=port, quiet=True, server=server)
if __name__ == "__main__":
run(app=web, port=8001)