This commit is contained in:
pictures2333 2024-11-07 17:33:34 +08:00
parent 3f2f7475f2
commit ab47043281
2 changed files with 29 additions and 2 deletions

13
app.py
View File

@ -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

View File

@ -4,6 +4,7 @@ import os
load_dotenv()
# service url
URL = os.getenv("SUPABASE_IP")
# service key
KEY = os.getenv("SUPABASE_KEY")
@ -11,3 +12,18 @@ KEY = os.getenv("SUPABASE_KEY")
class supaClient:
def __init__(self):
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