forked from PolarisPyra/daphnis
added comments
This commit is contained in:
parent
306ee6cc26
commit
ac02b7b901
@ -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;
|
||||
|
@ -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
|
||||
},
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user