1
0
Fork 0
forked from mia/0x0

Support instance config

This commit is contained in:
Mia Herkt 2020-12-29 04:05:34 +01:00
parent a4da58f3f3
commit 5db62c2dbf
No known key found for this signature in database
GPG key ID: 72E154B8622EC191
2 changed files with 40 additions and 36 deletions

1
.gitignore vendored
View file

@ -1,2 +1,3 @@
__pycache__/ __pycache__/
.py[cod] .py[cod]
instance/

View file

@ -32,17 +32,17 @@ import requests
from short_url import UrlEncoder from short_url import UrlEncoder
from validators import url as url_valid from validators import url as url_valid
app = Flask(__name__) app = Flask(__name__, instance_relative_config=True)
app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False app.config.update(
SQLALCHEMY_TRACK_MODIFICATIONS = False,
app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///db.sqlite" # "postgresql://0x0@/0x0" PREFERRED_URL_SCHEME = "https", # nginx users: make sure to have 'uwsgi_param UWSGI_SCHEME $scheme;' in your config
app.config["PREFERRED_URL_SCHEME"] = "https" # nginx users: make sure to have 'uwsgi_param UWSGI_SCHEME $scheme;' in your config MAX_CONTENT_LENGTH = 256 * 1024 * 1024,
app.config["MAX_CONTENT_LENGTH"] = 256 * 1024 * 1024 MAX_URL_LENGTH = 4096,
app.config["MAX_URL_LENGTH"] = 4096 USE_X_SENDFILE = False,
app.config["FHOST_STORAGE_PATH"] = "up" FHOST_USE_X_ACCEL_REDIRECT = True, # expect nginx by default
app.config["FHOST_USE_X_ACCEL_REDIRECT"] = True # expect nginx by default FHOST_STORAGE_PATH = "up",
app.config["USE_X_SENDFILE"] = False FHOST_MAX_EXT_LENGTH = 9,
app.config["FHOST_EXT_OVERRIDE"] = { FHOST_EXT_OVERRIDE = {
"audio/flac" : ".flac", "audio/flac" : ".flac",
"image/gif" : ".gif", "image/gif" : ".gif",
"image/jpeg" : ".jpg", "image/jpeg" : ".jpg",
@ -54,19 +54,22 @@ app.config["FHOST_EXT_OVERRIDE"] = {
"text/plain" : ".log", "text/plain" : ".log",
"text/plain" : ".txt", "text/plain" : ".txt",
"text/x-diff" : ".diff", "text/x-diff" : ".diff",
} },
FHOST_MIME_BLACKLIST = [
# default blacklist to avoid AV mafia extortion
app.config["FHOST_MIME_BLACKLIST"] = [
"application/x-dosexec", "application/x-dosexec",
"application/java-archive", "application/java-archive",
"application/java-vm" "application/java-vm"
] ],
FHOST_UPLOAD_BLACKLIST = None,
NSFW_DETECT = False,
NSFW_THRESHOLD = 0.608,
URL_ALPHABET = "DEQhd2uFteibPwq0SWBInTpA_jcZL5GKz3YCR14Ulk87Jors9vNHgfaOmMXy6Vx-",
)
app.config["FHOST_UPLOAD_BLACKLIST"] = "tornodes.txt" app.config.from_pyfile("config.py")
app.config["NSFW_DETECT"] = False if app.config["DEBUG"]:
app.config["NSFW_THRESHOLD"] = 0.608 app.config["FHOST_USE_X_ACCEL_REDIRECT"] = False
if app.config["NSFW_DETECT"]: if app.config["NSFW_DETECT"]:
from nsfw_detect import NSFWDetector from nsfw_detect import NSFWDetector
@ -88,7 +91,7 @@ migrate = Migrate(app, db)
manager = Manager(app) manager = Manager(app)
manager.add_command("db", MigrateCommand) manager.add_command("db", MigrateCommand)
su = UrlEncoder(alphabet='DEQhd2uFteibPwq0SWBInTpA_jcZL5GKz3YCR14Ulk87Jors9vNHgfaOmMXy6Vx-', block_size=16) su = UrlEncoder(alphabet=app.config["URL_ALPHABET"], block_size=16)
class URL(db.Model): class URL(db.Model):
id = db.Column(db.Integer, primary_key = True) id = db.Column(db.Integer, primary_key = True)
@ -169,8 +172,8 @@ def shorten(url):
return u.geturl() return u.geturl()
def in_upload_bl(addr): def in_upload_bl(addr):
if os.path.isfile(app.config["FHOST_UPLOAD_BLACKLIST"]): if app.config["FHOST_UPLOAD_BLACKLIST"]:
with open(app.config["FHOST_UPLOAD_BLACKLIST"], "r") as bl: with app.open_instance_resource(app.config["FHOST_UPLOAD_BLACKLIST"]) as bl:
check = addr.lstrip("::ffff:") check = addr.lstrip("::ffff:")
for l in bl.readlines(): for l in bl.readlines():
if not l.startswith("#"): if not l.startswith("#"):