added comments

This commit is contained in:
Polaris
2024-07-23 17:29:07 -04:00
parent 306ee6cc26
commit ac02b7b901
2 changed files with 12 additions and 9 deletions

View File

@ -13,6 +13,7 @@ type chunithm = chuni_score_playlog &
export default async function Share({ export default async function Share({
params, params,
}: { }: {
// pass the token and playlog id as params
params: { token: string; id: string }; params: { token: string; id: string };
}) { }) {
const { token, id } = params; const { token, id } = params;

View File

@ -7,9 +7,9 @@ import { randomBytes } from "crypto";
import { redirect } from "next/navigation"; import { redirect } from "next/navigation";
export async function generateShareToken(id: number): Promise<{ export async function generateShareToken(id: number): Promise<{
token?: string; token?: string; // share token
id?: string; id?: string; // playlog id after the token
error?: string; error?: string; // error
}> { }> {
const { user } = await getAuth(); const { user } = await getAuth();
@ -18,15 +18,17 @@ export async function generateShareToken(id: number): Promise<{
error: "Invalid user or user ID", error: "Invalid user or user ID",
}; };
} }
// generate the token that expires
const gernatetoken = randomBytes(5).readUInt32BE(0).toString(); const gernatetoken = randomBytes(5).readUInt32BE(0).toString();
// generate token logic
const token = await daphnis.linkSharingToken.create({ const token = await daphnis.linkSharingToken.create({
data: { data: {
playlogId: id, playlogId: id, // sets the playlog id
id: randomUUID(), id: randomUUID(), // generates a random share id
userId: user.id, userId: user.id, // attaches the userid
token: gernatetoken, token: gernatetoken, // makes an expirable token
createdAt: new Date(), createdAt: new Date(), // created at date
}, },
}); });