forked from all-in-aigc/melodisco
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
190 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { formatSong, updateSongs } from "@/services/song"; | ||
import { respData, respErr } from "@/utils/resp"; | ||
|
||
import { Song } from "@/types/song"; | ||
import { getLatestSongs } from "@/services/suno"; | ||
|
||
export async function POST(req: Request) { | ||
try { | ||
const { page } = await req.json(); | ||
|
||
let songs: Song[] = []; | ||
|
||
const data = await getLatestSongs(page); | ||
if (data && data["playlist_clips"]) { | ||
data["playlist_clips"].forEach((item: any) => { | ||
const song = formatSong(item["clip"], false); | ||
songs.push(song); | ||
}); | ||
} | ||
|
||
if (songs.length === 0) { | ||
return respErr("no data"); | ||
} | ||
|
||
const result = await updateSongs(songs); | ||
|
||
return respData(result); | ||
} catch (e) { | ||
console.log("fetch latest songs failed:", e); | ||
return respErr("fetch latest songs failed"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { findByUuid, insertRow } from "@/models/song"; | ||
import { respData, respErr } from "@/utils/resp"; | ||
|
||
import { formatSong } from "@/services/song"; | ||
import { getSongInfo } from "@/services/suno"; | ||
|
||
export async function POST(req: Request) { | ||
try { | ||
const { uuid } = await req.json(); | ||
if (!uuid) { | ||
return respErr("invalid params"); | ||
} | ||
|
||
let song = await findByUuid(uuid); | ||
if (song) { | ||
return respData(song); | ||
} | ||
|
||
const data = await getSongInfo([uuid]); | ||
if (!data || data.length === 0) { | ||
return respErr("fetch song failed"); | ||
} | ||
|
||
song = formatSong(data[0], false); | ||
|
||
await insertRow(song); | ||
|
||
return respData(song); | ||
} catch (e) { | ||
console.log("fetch song failed:", e); | ||
return respErr("fetch song failed"); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { formatSong, updateSongs } from "@/services/song"; | ||
import { respData, respErr } from "@/utils/resp"; | ||
|
||
import { Song } from "@/types/song"; | ||
import { getTrendingSongs } from "@/services/suno"; | ||
|
||
export async function POST(req: Request) { | ||
try { | ||
const { page } = await req.json(); | ||
|
||
let songs: Song[] = []; | ||
|
||
const data = await getTrendingSongs(page); | ||
if (data && data["playlist_clips"]) { | ||
data["playlist_clips"].forEach((item: any) => { | ||
const song = formatSong(item["clip"], true); | ||
songs.push(song); | ||
}); | ||
} | ||
|
||
if (songs.length === 0) { | ||
return respErr("no data"); | ||
} | ||
|
||
const result = await updateSongs(songs); | ||
|
||
return respData(result); | ||
} catch (e) { | ||
console.log("fetch trending songs failed:", e); | ||
return respErr("fetch trending songs failed"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters