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({
params,
}: {
// pass the token and playlog id as params
params: { token: string; id: string };
}) {
const { token, id } = params;

View File

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