Newer
Older
# Copyright (C) 2018-2020 jbs
#
# This program 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.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
import utils
from database import Database
import json
import time
VERSION = "v2.0"
print("shortnex " + VERSION + "\nmade by jbs")
config = {"port": data["port"], "database": data["database"], "url": data["url"], "rEnabled": data["ratelimit"]["enabled"]}
print("shortnex | Done...")
print("shortnex | Loading ratelimit service...")
ratelimits = Ratelimit()
if config["rEnabled"]:
try:
ratelimits.loop()
print("shortnex | Done.")
except Exception:
print("shortnex | Failed loading ratelimit service, you could report this issue on git... Exiting..")
exit(0)
else:
print("Ratelimit service is disabled...")
print("shortnex | Loading flask...")
@app.route('/')
def index():
return render_template("index.html")
# curl --header "Content-Type: application/json, charset=utf-8" --request POST --data '{"url":"https://example.org"}' http://localhost:5000/shorten
if not ratelimits.check(request.remote_addr):
return {"success": "false", "error": "You are being ratelimited."}
if request.method != "POST":
return {"success": "false", "error": "This route is POST only."}
content = request.get_json()
if not "url" in content:
return {"success": False, "error": "The parameter 'url' does not exist.", "code": 1}
if utils.checkIfProperURL(content.get("url")) is None:
return {"success": False, "error": "That is not a proper url.", "code": 1}
url = utils.returnProperURL(content.get("url"))
return {"success": False, "error": "Error has occurred while shortening. Please contact an administrator."}