This commit is contained in:
Polaris 2024-08-26 11:15:36 -04:00
parent ca85649057
commit 7841fe8ff9
2 changed files with 10 additions and 14 deletions

View File

@ -1,5 +1,6 @@
"use server";
import { getAuth } from "@/auth/queries/getauth";
import { artemis, daphnis } from "@/lib/prisma";
import type * as Prisma from "@prisma/client";
@ -10,12 +11,14 @@ type LinkSharingToken = {
playlogId: number;
};
export async function getSongsWithTitles(userId: number) {
export async function getSharedSong() {
const { user } = await getAuth();
try {
const songs: ChuniScorePlaylog[] =
await artemis.chuni_score_playlog.findMany({
where: {
user: userId,
user: user?.UserId,
},
orderBy: {
userPlayDate: "desc",
@ -91,7 +94,7 @@ export async function getSongsWithTitles(userId: number) {
musicId: true,
},
where: {
user: userId,
user: user?.UserId,
musicId: {
in: chuniScorePlaylogMusicId,
},
@ -135,7 +138,7 @@ export async function getSongsWithTitles(userId: number) {
}
}
export async function generatePlaylogId(playlogid: number) {
export async function getPlaylogId(playlogid: number) {
try {
const tokens = (await daphnis.linkSharingToken.findMany({
where: {

View File

@ -5,7 +5,7 @@ import {
type chuni_score_playlog,
chuni_static_music,
} from "@/prisma/schemas/artemis/generated/artemis";
import { generatePlaylogId, getSongsWithTitles } from "./actions";
import { getPlaylogId, getSharedSong } from "./actions";
type chunithm = chuni_score_playlog &
chuni_static_music & { playCount: number };
@ -25,17 +25,10 @@ export default async function Share({
return <p>{tokenResult.error}</p>;
}
const { user } = await getAuth();
if (!user?.UserId) {
return <p>Error: No user ID found.</p>;
}
const userId = user?.UserId;
const playlogId = parseInt(id);
const songsData = await getSongsWithTitles(userId);
const playlogIds = await generatePlaylogId(playlogId);
const songsData = await getSharedSong();
const playlogIds = await getPlaylogId(playlogId);
// Filter songsData to match the playlogIds
const chunithm: chunithm[] = songsData.filter((song) =>