Skip to content

Commit 1312656

Browse files
committed
add album search
1 parent c4d4bf7 commit 1312656

5 files changed

Lines changed: 612 additions & 50 deletions

File tree

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import { NextRequest, NextResponse } from "next/server";
2+
import { getJellyfinService } from "@/services/jellyfin";
3+
4+
interface RouteParams {
5+
params: Promise<{ id: string }>;
6+
}
7+
8+
export async function GET(request: NextRequest, { params }: RouteParams) {
9+
try {
10+
const { searchParams } = new URL(request.url);
11+
const limit = parseInt(searchParams.get("limit") || "50");
12+
const startIndex = parseInt(searchParams.get("startIndex") || "0");
13+
14+
const resolvedParams = await params;
15+
const albumId = resolvedParams.id;
16+
17+
// Extract the Jellyfin ID from our prefixed ID
18+
const jellyfinId = albumId.startsWith("jellyfin_album_")
19+
? albumId.replace("jellyfin_album_", "")
20+
: albumId;
21+
22+
console.log(
23+
`Album songs API: albumId="${albumId}", jellyfinId="${jellyfinId}", limit=${limit}, startIndex=${startIndex}`
24+
);
25+
26+
const jellyfinService = getJellyfinService();
27+
const songs = await jellyfinService.getSongsByAlbumId(
28+
jellyfinId,
29+
limit,
30+
startIndex
31+
);
32+
33+
console.log(
34+
`Album songs API: returning ${songs.length} songs for album ${albumId}`
35+
);
36+
37+
return NextResponse.json({
38+
success: true,
39+
data: songs,
40+
timestamp: new Date(),
41+
});
42+
} catch (error) {
43+
console.error("Album songs API error:", error);
44+
return NextResponse.json(
45+
{
46+
success: false,
47+
error: {
48+
code: "ALBUM_SONGS_FETCH_FAILED",
49+
message:
50+
error instanceof Error
51+
? error.message
52+
: "Failed to get songs by album",
53+
},
54+
timestamp: new Date(),
55+
},
56+
{ status: 500 }
57+
);
58+
}
59+
}

src/app/api/albums/route.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import { NextRequest, NextResponse } from "next/server";
2+
import { getJellyfinService } from "@/services/jellyfin";
3+
import { Album } from "@/types";
4+
5+
export async function GET(request: NextRequest) {
6+
try {
7+
const { searchParams } = new URL(request.url);
8+
const query = searchParams.get("q") || "";
9+
const limit = parseInt(searchParams.get("limit") || "50");
10+
const startIndex = parseInt(searchParams.get("startIndex") || "0");
11+
12+
console.log(
13+
`Albums API: query="${query}", limit=${limit}, startIndex=${startIndex}`
14+
);
15+
16+
const jellyfinService = getJellyfinService();
17+
18+
let albums: Album[];
19+
if (query.trim()) {
20+
// Search for albums by name
21+
albums = await jellyfinService.searchAlbums(query, limit, startIndex);
22+
} else {
23+
// For now, return empty array when no query is provided
24+
// In the future, we could implement browsing all albums
25+
albums = [];
26+
}
27+
28+
console.log(`Albums API: returning ${albums.length} albums`);
29+
30+
return NextResponse.json({
31+
success: true,
32+
data: albums,
33+
timestamp: new Date(),
34+
});
35+
} catch (error) {
36+
console.error("Albums API error:", error);
37+
return NextResponse.json(
38+
{
39+
success: false,
40+
error: {
41+
code: "ALBUMS_SEARCH_FAILED",
42+
message:
43+
error instanceof Error ? error.message : "Failed to search albums",
44+
},
45+
timestamp: new Date(),
46+
},
47+
{ status: 500 }
48+
);
49+
}
50+
}

0 commit comments

Comments
 (0)