aboutsummaryrefslogtreecommitdiffstats
path: root/main.py
blob: af7d1cb3593c4ebbccf812a7520300962296dde3 (plain) (blame)
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
import os
import requests
from flask import request, Flask, render_template

from dotenv import load_dotenv
from flask_cors import CORS

from steam import add_steam_game
app = Flask(__name__)
load_dotenv()
CORS(app)

POCKETBASE_URL = os.getenv("POCKETBASE_URL", "http://127.0.0.1:8090")
GAME_ADD_PASSWORD = os.getenv("GAME_ADD_PASSWORD")


def get_games():
    resp = requests.get(
        f"{POCKETBASE_URL}/api/collections/list/records?perPage=50",
        headers={
        },
        timeout=10,
    )

    resp.raise_for_status()
    return resp.json()["items"]


@app.route("/")
def index():
    games = get_games()
    return render_template("index.html", games=games)


@app.route("/api/games")
def api_games():
    return jsonify(get_games())

@app.route("/add")
def add_page():
    return render_template("add.html")

@app.route("/api/steam/<int:steam_id>", methods=["POST"])
def add_game(steam_id):

    provided_password = request.json.get("password") if request.is_json else request.form.get("password")

    if not GAME_ADD_PASSWORD or not provided_password or provided_password != GAME_ADD_PASSWORD:
        return jsonify({"error": "Unauthorized"}), 401

    game = add_steam_game(steam_id)
    return {"ok": "200"}

if __name__ == "__main__":
    app.run(debug=True)
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage