Commit 9a01df2c authored by duanjinfei's avatar duanjinfei

fix user rank background exec

parent 61c8e9a2
......@@ -17,17 +17,7 @@ async function count_holders(supabase) {
return count
}
Deno.serve(async (req) => {
if (req.method === 'OPTIONS') {
return new Response('ok', { headers: corsHeaders })
}
try {
// const { name } = await req.json()
const supabase = createClient(
Deno.env.get('SUPABASE_URL') ?? '',
Deno.env.get('SUPABASE_ANON_KEY') ?? '',
{ global: { headers: { Authorization: req.headers.get('Authorization')! } } }
)
async function cacheUserRank(supabase) {
const { data: userData, error: userError } = await supabase.from('user').select('*').gt('rank', 0).order('rank', { ascending: true }).limit(100);
......@@ -54,7 +44,6 @@ Deno.serve(async (req) => {
if (uploadError) {
console.error('Error uploading file to storage:', uploadError);
return new Response(JSON.stringify({ error: 'Failed to upload file' }), { status: 500 });
}
const holdersCountFileName = `${directory}/user_holders.json`;
......@@ -72,8 +61,22 @@ Deno.serve(async (req) => {
if (uploadHolderError) {
console.error('Error uploading file to storage:', uploadHolderError);
return new Response(JSON.stringify({ error: 'Failed to upload file' }), { status: 500 });
}
}
Deno.serve(async (req) => {
if (req.method === 'OPTIONS') {
return new Response('ok', { headers: corsHeaders })
}
try {
// const { name } = await req.json()
const supabase = createClient(
Deno.env.get('SUPABASE_URL') ?? '',
Deno.env.get('SUPABASE_ANON_KEY') ?? '',
{ global: { headers: { Authorization: req.headers.get('Authorization')! } } }
)
EdgeRuntime.waitUntil(cacheUserRank(supabase));
return new Response(JSON.stringify({
code: 200,
......@@ -87,15 +90,3 @@ Deno.serve(async (req) => {
return new Response(String(err?.message ?? err), { status: 500 })
}
})
/* To invoke locally:
1. Run `supabase start` (see: https://supabase.com/docs/reference/cli/supabase-start)
2. Make an HTTP request:
curl -i --location --request POST 'http://127.0.0.1:54321/functions/v1/hello-world' \
--header 'Authorization: Bearer ' \
--header 'Content-Type: application/json' \
--data '{"name":"Functions"}'
*/
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment