diff --git a/app.py b/app.py index 3a87318..26fd98e 100644 --- a/app.py +++ b/app.py @@ -1,8 +1,9 @@ from flask import Flask, session, request, redirect, Response import os, requests, time from hashlib import sha256 -from supaclient import supaClient +from supaclient import supaClient, logger from dotenv import load_dotenv +from supabase import Client load_dotenv() URL = os.getenv("SUPABASE_IP") + "/" @@ -32,6 +33,9 @@ def proxy(path): headers = request.headers json_ctx = request.get_json() + # flags + logger_args = [] + # process if path == "rest/v1/niming_posts": # niming post # hash @@ -40,6 +44,10 @@ def proxy(path): # ig posting igid = None + # set logger + logger_args.append("newpost") + logger_args.append(hash) + # edit payload json_ctx["hash"] = hash json_ctx["igid"] = igid @@ -50,6 +58,9 @@ def proxy(path): headers = [(name, value) for (name, value) in resp.raw.headers.items() if name.lower() not in excluded_headers] response = Response(resp.content, resp.status_code, headers) + # logger + logger_res = logger(app.shared_resource.client, logger_args) + return response # run diff --git a/supaclient.py b/supaclient.py index dd183d9..4d6c483 100644 --- a/supaclient.py +++ b/supaclient.py @@ -4,10 +4,26 @@ import os load_dotenv() +# service url URL = os.getenv("SUPABASE_IP") # service key KEY = os.getenv("SUPABASE_KEY") class supaClient: def __init__(self): - self.client = create_client(URL, KEY) \ No newline at end of file + self.client = create_client(URL, KEY) + +# logger +def logger(dbclient: Client, args: list): + if args[0] == "newpost": + hash:str = args[1] + pres = dbclient.table("niming_posts").select("id, hash").eq("hash", hash).execute() + id = int(pres.data[0]["id"]) + + dbres = dbclient.table("niming_log").insert({ + "message": "[id=%d] new post"%id, + "source": "client" + }).execute() + + return dbres + return None \ No newline at end of file