burhan-syed / troddit

A web client for Reddit with authenticated logins and a variety of browsing options
https://www.troddit.com
GNU Affero General Public License v3.0
551 stars 80 forks source link

Log api use #166

Closed burhan-syed closed 1 year ago

burhan-syed commented 1 year ago

Anonymously logging Reddit API in response to #159

vercel[bot] commented 1 year ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
troddit ✅ Ready (Inspect) Visit Preview Jun 5, 2023 1:50am
kgnfth commented 1 year ago

I signed up to Supabase buti keep getting 500 error

İ have setup the env like this

DATABASE_URL: db.jnxneredacted.supabase.co SUPABASE_URL: https://jnxneredacted.supabase.co SUPABASE_SERVICE_ROLE_KEY: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsI

burhan-syed commented 1 year ago

@kgnfth not too sure what's happening there but Supabase logging isn't really intended for self hosted instances. I've just put out a commit to make this opt in so your self hosted instance isn't spammed with 500 errors.

If you do want to set this up you will need to setup an instance of Supabase with a table like the following:

image

and create a function named "increment_log" with the following variables:

is_oauth: bool
route_type: text
c_date: date

and definition:

BEGIN
    IF EXISTS (SELECT FROM analytics WHERE type=route_type AND oauth=is_oauth::bool AND date=c_date::date) THEN
        UPDATE analytics
        SET count = count + 1,
            last_updated = now()
        WHERE type=route_type AND oauth=is_oauth::bool AND date=c_date::date;
    ELSE
        INSERT into analytics(type,oauth,date) VALUES (route_type,is_oauth,c_date);
    END IF;
END;

Then setup your troddit environment variables:

ENABLE_API_LOG=true
SUPABASE_URL=<https://your-supabase-url>
SUPABASE_SERVICE_ROLE_KEY=<your service role key>

The exact schema of the table and function definition can be whatever you want. Troddit just calls the remote function with the route_type, c_date, and is_oauth variables.

kgnfth commented 1 year ago

@burhan-syed Thanks it is working ❤️