2024-06-29 07:02:21 +00:00
|
|
|
import { generatePlaylogId, getSongsWithTitles } from "@/lib/api";
|
2024-06-29 05:22:22 +00:00
|
|
|
import { shareScore } from "../token";
|
|
|
|
|
|
|
|
export default async function Share({
|
|
|
|
params,
|
|
|
|
}: {
|
|
|
|
params: { token: string; id: string };
|
|
|
|
}) {
|
|
|
|
const { token, id } = params;
|
|
|
|
|
|
|
|
// Verify the token
|
|
|
|
const tokenResult = await shareScore(token);
|
|
|
|
|
|
|
|
if (tokenResult.error) {
|
2024-06-29 07:02:21 +00:00
|
|
|
|
2024-06-29 05:22:22 +00:00
|
|
|
return <p>{tokenResult.error}</p>;
|
|
|
|
}
|
|
|
|
|
|
|
|
const userId = 10000;
|
|
|
|
const playlogId = parseInt(id);
|
|
|
|
|
|
|
|
const songsData = await getSongsWithTitles(userId);
|
2024-06-29 07:02:21 +00:00
|
|
|
const playlogIds = await generatePlaylogId(playlogId);
|
2024-06-29 05:22:22 +00:00
|
|
|
|
2024-06-29 07:02:21 +00:00
|
|
|
const matchSongToPlaylogId = songsData.filter((song) =>
|
2024-06-29 05:22:22 +00:00
|
|
|
playlogIds.includes(song.id)
|
|
|
|
);
|
|
|
|
|
2024-06-29 07:02:21 +00:00
|
|
|
const songTitles = matchSongToPlaylogId.map((song) => song.title);
|
2024-06-29 05:22:22 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<ul>
|
|
|
|
{songTitles.map((title) => (
|
|
|
|
<li key={title}>{title}</li>
|
|
|
|
))}
|
|
|
|
</ul>
|
|
|
|
);
|
|
|
|
}
|