Skip to content

[WIP] Update Musicanaz frontend to utilize improved mpyapi#1

Merged
Wilooper merged 1 commit into
mainfrom
copilot/update-musicanaz-frontend
Mar 4, 2026
Merged

[WIP] Update Musicanaz frontend to utilize improved mpyapi#1
Wilooper merged 1 commit into
mainfrom
copilot/update-musicanaz-frontend

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 4, 2026

  • Explore existing code and understand what needs to change
  • Update app/api/musiva/artist-songs/route.ts — default limit 100→500, pass through albums field
  • Create app/api/musiva/artist-albums/route.ts — new proxy for /artist/{id}/albums
  • Replace app/api/musiva/trending/route.ts — switch from test-0k.onrender.com to own mpyapi
  • Replace app/api/trending/route.ts — switch from gaanapy-0h31.onrender.com to own mpyapi
  • Update app/artist/page.tsx AllSongsPanel — fetch limit 100→500
Original prompt

Overview

Update the Musicanaz frontend (Next.js/TypeScript) to:

  1. Take full advantage of the improved mpyapi backend (artist songs/albums fixes)
  2. Replace the unreliable external trending APIs with the project's own mpyapi /charts and /trending endpoints
  3. Add a new artist albums section

The backend base URL used throughout is: https://turbo-14uz.onrender.com


Changes Required

1. Update app/api/musiva/artist-songs/route.ts

Current code (fetches from mpyapi):

import { type NextRequest, NextResponse } from "next/server"
const BASE = "https://turbo-14uz.onrender.com"

export async function GET(request: NextRequest) {
  const id    = request.nextUrl.searchParams.get("id")
  const limit = request.nextUrl.searchParams.get("limit") || "100"
  if (!id) return NextResponse.json({ songs: [], total: 0 }, { status: 400 })
  try {
    const res  = await fetch(`${BASE}/artist/${encodeURIComponent(id)}/songs?limit=${limit}`)
    if (!res.ok) throw new Error(`${res.status}`)
    const data = await res.json()
    return NextResponse.json({
      songs:  data.songs  || [],
      total:  data.total  || 0,
      name:   data.name   || "",
    })
  } catch {
    return NextResponse.json({ songs: [], total: 0 }, { status: 500 })
  }
}

Updated code — increase default limit to 500 (mpyapi now supports up to 5000) and pass through the new albums field:

import { type NextRequest, NextResponse } from "next/server"
const BASE = "https://turbo-14uz.onrender.com"

export async function GET(request: NextRequest) {
  const id    = request.nextUrl.searchParams.get("id")
  const limit = request.nextUrl.searchParams.get("limit") || "500"
  if (!id) return NextResponse.json({ songs: [], total: 0, albums: [] }, { status: 400 })
  try {
    const res  = await fetch(`${BASE}/artist/${encodeURIComponent(id)}/songs?limit=${limit}`)
    if (!res.ok) throw new Error(`${res.status}`)
    const data = await res.json()
    return NextResponse.json({
      songs:  data.songs  || [],
      total:  data.total  || 0,
      name:   data.name   || "",
      albums: data.albums || [],
    })
  } catch {
    return NextResponse.json({ songs: [], total: 0, albums: [] }, { status: 500 })
  }
}

2. Create NEW app/api/musiva/artist-albums/route.ts

Create a new API route to proxy the new mpyapi /artist/{id}/albums endpoint:

import { type NextRequest, NextResponse } from "next/server"
const BASE = "https://turbo-14uz.onrender.com"

export async function GET(request: NextRequest) {
  const id = request.nextUrl.searchParams.get("id")
  if (!id) return NextResponse.json({ albums: [], totalAlbums: 0, totalTracks: 0 }, { status: 400 })
  try {
    const res = await fetch(`${BASE}/artist/${encodeURIComponent(id)}/albums`, {
      next: { revalidate: 600 },
    })
    if (!res.ok) throw new Error(`${res.status}`)
    const data = await res.json()
    return NextResponse.json({
      artistId:    data.artistId    || id,
      name:        data.name        || "",
      albums:      data.albums      || [],
      totalAlbums: data.totalAlbums || 0,
      totalTracks: data.totalTracks || 0,
    })
  } catch {
    return NextResponse.json({ albums: [], totalAlbums: 0, totalTracks: 0 }, { status: 500 })
  }
}

3. Replace app/api/musiva/trending/route.ts — Use own mpyapi instead of external API

Current code uses https://test-0k.onrender.com (external, unreliable).

Replace the entire file to use the project's own mpyapi backend at https://turbo-14uz.onrender.com:

import { type NextRequest, NextResponse } from "next/server"

const BASE = "https://turbo-14uz.onrender.com"

// Country metadata for display
export const TRENDING_COUNTRIES: Record<string, { flag: string; name: string }> = {
  US: { flag: "🇺🇸", name: "United States" },
  GB: { flag: "🇬🇧", name: "United Kingdom" },
  IN: { flag: "🇮🇳", name: "India" },
  AU: { flag: "🇦🇺", name: "Australia" },
  CA: { flag: "🇨🇦", name: "Canada" },
  JP: { flag: "🇯🇵", name: "Japan" },
  KR: { flag: "🇰🇷", name: "South Korea" },
  BR: { flag: "🇧🇷", name: "Brazil" },
  DE: { flag: "🇩🇪", name: "Germany" },
  FR: { flag: "🇫🇷", name: "France" },
  MX: { flag: "🇲🇽", name: "Mexico" },
  NG: { flag: "🇳🇬", name: "Nigeria" },
  ZA: { flag: "🇿🇦", name: "South Africa" },
  PK: { flag: "🇵🇰", name: "Pakistan" },
  ID: { flag: "🇮🇩", name: "Indonesia" },
}

async function fetchCountryTrending(country: string, limit: number) {
  try {
    const res = await fetch(
      `${BASE}/trending?country=${country}&limit=${limit}`,
      { next: { revalidate: 600 } }
    )
    if (!res.ok) return []
    const json = await res.json()
    // mpyapi /trending returns { country, trending: [...], count }
    const tracks = json?.trending || []
    return tracks.map((t: any) => ({
      ...t,
      // Ensure consistent fields for the frontend
      videoId:   t.videoId   || "",
      title:     t.title     || "Unknown",
      artist:  ...

</details>



<!-- START COPILOT CODING AGENT SUFFIX -->

*This pull request was created from Copilot chat.*
>

<!-- START COPILOT CODING AGENT TIPS -->
---

 Let Copilot coding agent [set things up for you](https://github.com/Wilooper/Musicanaz/issues/new?title=+Set+up+Copilot+instructions&body=Configure%20instructions%20for%20this%20repository%20as%20documented%20in%20%5BBest%20practices%20for%20Copilot%20coding%20agent%20in%20your%20repository%5D%28https://gh.io/copilot-coding-agent-tips%29%2E%0A%0A%3COnboard%20this%20repo%3E&assignees=copilot) — coding agent works faster and does higher quality work when set up for your repo.

@Wilooper Wilooper marked this pull request as ready for review March 4, 2026 14:30
@Wilooper Wilooper merged commit f34fa02 into main Mar 4, 2026
1 check failed
Copilot stopped work on behalf of Wilooper due to an error March 4, 2026 14:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants