From 3efc733d4a52779e1fbc5ed30ce59a2ca676f65d Mon Sep 17 00:00:00 2001 From: suricata Date: Sun, 18 Jan 2026 19:28:24 +0000 Subject: [PATCH] sqlite is supported and now default --- docker-compose.yaml | 29 ++++---- server/py/fastapi_server/database.db | Bin 0 -> 8192 bytes server/py/fastapi_server/main.py | 65 +++++++++++++----- .../py/fastapi_server/requirements_prod.txt | 1 + 4 files changed, 60 insertions(+), 35 deletions(-) create mode 100644 server/py/fastapi_server/database.db diff --git a/docker-compose.yaml b/docker-compose.yaml index cda4758..a025b31 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -2,14 +2,14 @@ volumes: music_downloads: {} # These 2 are just for "nuxtjs-launcher" # If you use a normal nodejs build image, you don't need them - nuxt_internal: {} - nuxt_server: {} + #nuxt_internal: {} + #nuxt_server: {} networks: api_nuxt: driver: "bridge" - bridge: - external: true # Allow LAN access + #bridge: + # external: true # Allow LAN access services: fastapi: build: @@ -17,20 +17,17 @@ services: dockerfile: Dockerfile.fastapi networks: - api_nuxt - - bridge # allow external access + #- bridge # allow external access volumes: - music_downloads:/tmp/downloads environment: - - MYSQL_HOST=172.17.0.1 - - MYSQL_USER=yt2mp3_nuxt - - MYSQL_DB=yt2mp3_nuxt - - MYSQL_PASSWORD=JJ7ZEyDm!XAGFb_z + - DB_MODE=sqlite nuxt: - #build: - # context: . - # dockerfile: Dockerfile.nuxt - image: nuxtjs-launcher + build: + context: . + dockerfile: Dockerfile.nuxt + #image: nuxtjs-launcher networks: - api_nuxt ports: @@ -43,8 +40,8 @@ services: volumes: - music_downloads:/tmp/downloads # These 3 are just for "nuxtjs-launcher" - - ./:/app - - nuxt_server:/server - - nuxt_internal:/internal + # - ./:/app + #- nuxt_server:/server + #- nuxt_internal:/internal \ No newline at end of file diff --git a/server/py/fastapi_server/database.db b/server/py/fastapi_server/database.db new file mode 100644 index 0000000000000000000000000000000000000000..514fc6576454473c34517feed30f6992606adf74 GIT binary patch literal 8192 zcmeI#PjA{V6aa7sb*ez>pBw7!9XPa7OC1CI(_P4Drd0&kAW-c@3>X#_C&)GhdfU`X zKSn=GKfu1yLc}(8n$$~sdryw-STBC|@0QLNFEj$iv69?CiR=^0B2@rFNM`dSLmF1n zZ*Au5Vg3G8WJvM)ZYRmIc7KwjVW0pCpa2S>01BW03ZMWApa2S>z;g)vC|cY3eBQc! zZ}?y;=2|G7c9~k+b$l0m=Y!`$kgf%Am;(sHQ2=3NpxN@F+4a2R_2M{G+VmqXMF7`a z4Zm@9$SOyVlcxOX93go){kw-v=|7vyxYmnUC5QN3$6gnDTxqBTH)7Q1CIAykp$(U_ zKPhnTessE?54CQ)?Kb_sf6;I|zSH=e-eo=;{qN)Cs=1@|-+b?uBn<-vPyhu`00mG0 z1yBG5Pyhu`00mIs1qE)bZ1&*b-S<}|;>YsgUUzt8Vr^o{byd$*IOHabCR!JltD6EF z6l_*l$Re%ROT8;LSvie~?R;vzp`td^mCLxbq;xgBl)Y%|s*A6aa`*Hqrj56fQTF str: ydl_opts = { @@ -132,11 +151,15 @@ async def create_user(req: Request): # Auto exceptions give more verbose to Nuxt. body["password"] = bcrypt.hashpw(body["password"].encode(), bcrypt.gensalt()).decode() - async with db.pool.acquire() as conn: - async with conn.cursor() as cur: - await cur.execute("INSERT INTO users (`first_name`,`last_name`,`email`,`password`) VALUES (%s,%s,%s,%s)", (body.first_name, body.last_name, body.email, body.password)) - await conn.commit() - + if db.mode == "mysql": + async with db.pool.acquire() as conn: + async with conn.cursor() as cur: + await cur.execute("INSERT INTO users (`first_name`,`last_name`,`email`,`password`) VALUES (%s,%s,%s,%s)", (body.first_name, body.last_name, body.email, body.password)) + await conn.commit() + elif db.mode == "sqlite": + async with aiosqlite.connect(db.file) as conn: + await conn.execute("INSERT INTO users (`first_name`,`last_name`,`email`,`password`) VALUES (?, ?, ?, ?)", (body.first_name, body.last_name, body.email, body.password)) + await conn.commit() @app.post("/login") @@ -153,7 +176,7 @@ async def login_endpoint(req: Request): if (bcrypt.checkpw(body["password"].encode(), user_data.get("password").encode())): return user_data else: - raise HTTPException(status_code=401) + raise HTTPException(status_code=401, detail="Wrong password") except KeyError: raise HTTPException(status_code=400) #except ValidationError: @@ -168,9 +191,13 @@ async def me_get_endpoint(req: Request): Trusts Nuxt's backend to allow it or not. """ args = dict(req.query_params) - #print(args) + me = None try: - me = await fetch_user_info(args["email"]) + # Prefer id over e-mail + if "id" in args.keys(): me = fetch_user_info(args["id"], "id") + elif "email" in args.keys(): me = fetch_user_info(args["email"], "email") + else: raise HTTPException(400, "Provide either email or user id") + #print(args) if (me is None): raise HTTPException(404, "User doesn't exist") else: return me diff --git a/server/py/fastapi_server/requirements_prod.txt b/server/py/fastapi_server/requirements_prod.txt index 12fe893..574f9ee 100644 --- a/server/py/fastapi_server/requirements_prod.txt +++ b/server/py/fastapi_server/requirements_prod.txt @@ -1,4 +1,5 @@ aiomysql==0.3.2 +aiosqlite==0.22.1 annotated-doc==0.0.4 annotated-types==0.7.0 anyio==4.12.1