Skip to content
This repository has been archived by the owner on Mar 27, 2024. It is now read-only.

Commit

Permalink
api done
Browse files Browse the repository at this point in the history
  • Loading branch information
trent-001 committed Nov 15, 2023
1 parent 1887323 commit 49655f8
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions src/pages/api/update_clicks/[user]/[button].astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
---
import { downloadImageUser, getUserId, supabase } from "@/supabase";
const { user, button } = Astro.params;
console.log("user,button: ", user, button);
const user_user = await getUserId(user || "");
if (!user_user) {
return new Response(null, {
status: 404,
statusText: "Not Found"
});
} else {
const link = user_user.links.find((e) => e.id == button);
if (!link) {
return new Response(null, {
status: 404,
statusText: "Link Not Found"
});
}
if (!link.clicks) {
link.clicks = [new Date().toISOString()];
} else {
link.clicks.push(new Date().toISOString());
}
const updatedLinks = user_user.links.map((e) => (e.id === button ? link : e));
console.log("updatedLinks: ", updatedLinks);
const { error } = await supabase.from("profiles").upsert({
id: user_user.id as string,
links: updatedLinks
});
console.error("error: ", error);
const data = {
username: user_user.username,
displayname: user_user.displayname,
pic: downloadImageUser(user_user.pic)
};
return new Response(JSON.stringify(data), {
status: 200,
statusText: "OK"
});
}
---

0 comments on commit 49655f8

Please sign in to comment.