1
0
mirror of https://git.ikl.sh/132ikl/liteshort.git synced 2023-08-10 21:13:04 +03:00

Reorganize into package

This commit is contained in:
132ikl 2020-04-04 23:14:10 -04:00
parent ae1a05c83d
commit f465ee2b76
10 changed files with 22 additions and 39 deletions

View File

@ -1,4 +1,4 @@
Copyright 2020 Steven Spangler
Copyright 2020 132ikl
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

View File

@ -25,10 +25,9 @@ Start in the directory you wish to install to and modify to fit your installatio
```sh
git clone https://github.com/132ikl/liteshort
python3 -m venv virtualenv
source virtualenv/bin/activate
pip install wheel
pip install bcrypt flask pyyaml uwsgi
python3 -m venv venv
source venv/bin/activate
pip3 install -r requirements.txt uwsgi
```
Edit `liteshort.ini` and `liteshort.service` as seen fit. Then edit `config.yml` according to the [Configuration](#configuration) section.

View File

@ -1,5 +1,5 @@
[uwsgi]
module = wsgi:app
module = liteshort.wsgi:app
master = true
processes = 2
@ -9,4 +9,3 @@ chmod-socket = 666
vacuum = true
die-on-term = true

0
liteshort/__init__.py Normal file
View File

View File

@ -1,36 +1,21 @@
# Copyright (c) 2020 Steven Spangler <132@ikl.sh>
# This file is part of liteshort by 132ikl
# This software is license under the MIT license. It should be included in your copy of this software.
# A copy of the MIT license can be obtained at https://mit-license.org/
#!/usr/bin/env python3
import os
import random
import sqlite3
import time
import urllib
import bcrypt
import yaml
from flask import (
Flask,
current_app,
flash,
g,
jsonify,
make_response,
redirect,
render_template,
request,
send_from_directory,
url_for,
)
import flask
from bcrypt import checkpw
from flask import current_app, g, redirect, render_template, request, url_for
from yaml import safe_load
app = Flask(__name__)
app = flask.Flask(__name__)
def load_config():
with open("config.yml") as config:
configYaml = yaml.safe_load(config)
configYaml = safe_load(config)
config = {
k.lower(): v for k, v in configYaml.items()
} # Make config keys case insensitive
@ -137,7 +122,7 @@ def linking_to_blocklist(long):
def check_password(password, pass_config):
if pass_config["password_hashed"]:
return bcrypt.checkpw(
return checkpw(
password.encode("utf-8"),
pass_config["admin_hashed_password"].encode("utf-8"),
)
@ -220,15 +205,15 @@ def response(rq, result, error_msg="Error: Unknown error"):
if rq.form.get("api"):
if rq.accept_mimetypes.accept_json:
if result:
return jsonify(success=bool(result), result=result)
return jsonify(success=bool(result), message=error_msg)
return flask.jsonify(success=bool(result), result=result)
return flask.jsonify(success=bool(result), message=error_msg)
else:
return "Format type HTML (default) not supported for API" # Future-proof for non-json return types
else:
if result and result is not True:
flash(result, "success")
flask.flash(result, "success")
elif not result:
flash(error_msg, "error")
flask.flash(error_msg, "error")
return render_template("main.html")
@ -302,7 +287,7 @@ app.config["SERVER_NAME"] = app.config["site_domain"]
@app.route("/favicon.ico", subdomain=app.config["subdomain"])
def favicon():
return send_from_directory(
return flask.send_from_directory(
os.path.join(app.root_path, "static"),
"favicon.ico",
mimetype="image/vnd.microsoft.icon",
@ -318,10 +303,10 @@ def main():
def main_redir(url):
long = get_long(url)
if long:
resp = make_response(redirect(long, 301))
resp = flask.make_response(flask.redirect(long, 301))
else:
flash('Short URL "' + url + "\" doesn't exist", "error")
resp = make_response(redirect(url_for("main")))
flask.flash('Short URL "' + url + "\" doesn't exist", "error")
resp = flask.make_response(flask.redirect(url_for("main")))
resp.headers.set("Cache-Control", "no-store, must-revalidate")
return resp

View File

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 1.4 KiB

View File

Before

Width:  |  Height:  |  Size: 15 KiB

After

Width:  |  Height:  |  Size: 15 KiB

View File

@ -1,4 +1,4 @@
from liteshort import app
from .main import app
if __name__ == "__main__":
app.run()