Browse Source

Change uncached image size defaults to 350, 150

master
jeffvli 3 years ago
committed by Jeff
parent
commit
3b10d63eff
  1. 185
      src/api/api.ts
  2. 8
      src/components/dashboard/Dashboard.tsx

185
src/api/api.ts

@ -113,7 +113,7 @@ const authParams = {
f: 'json', f: 'json',
}; };
const getCoverArtUrl = (item: any, useLegacyAuth: boolean, size = 150) => { const getCoverArtUrl = (item: any, useLegacyAuth: boolean, size?: number) => {
if (!item.coverArt && !item.artistImageUrl) { if (!item.coverArt && !item.artistImageUrl) {
return 'img/placeholder.jpg'; return 'img/placeholder.jpg';
} }
@ -127,17 +127,41 @@ const getCoverArtUrl = (item: any, useLegacyAuth: boolean, size = 150) => {
} }
if (useLegacyAuth) { if (useLegacyAuth) {
if (!size) {
return (
`${API_BASE_URL}/getCoverArt` +
`?id=${item.coverArt}` +
`&u=${auth.username}` +
`&s=${auth.salt}` +
`&t=${auth.hash}` +
`&v=1.15.0` +
`&c=sonixd`
);
}
return ( return (
`${API_BASE_URL}/getCoverArt` + `${API_BASE_URL}/getCoverArt` +
`?id=${item.coverArt}` + `?id=${item.coverArt}` +
`&u=${auth.username}` + `&u=${auth.username}` +
`&p=${auth.password}` + `&s=${auth.salt}` +
`&t=${auth.hash}` +
`&v=1.15.0` + `&v=1.15.0` +
`&c=sonixd` + `&c=sonixd` +
`&size=${size}` `&size=${size}`
); );
} }
if (!size) {
return (
`${API_BASE_URL}/getCoverArt` +
`?id=${item.coverArt}` +
`&u=${auth.username}` +
`&s=${auth.salt}` +
`&t=${auth.hash}` +
`&v=1.15.0` +
`&c=sonixd`
);
}
return ( return (
`${API_BASE_URL}/getCoverArt` + `${API_BASE_URL}/getCoverArt` +
`?id=${item.coverArt}` + `?id=${item.coverArt}` +
@ -192,7 +216,8 @@ export const getPlaylists = async (sortBy: string) => {
return (newData || []).map((playlist: any) => ({ return (newData || []).map((playlist: any) => ({
...playlist, ...playlist,
name: playlist.name, name: playlist.name,
image: playlist.songCount > 0 ? getCoverArtUrl(playlist, legacyAuth) : 'img/placeholder.jpg', image:
playlist.songCount > 0 ? getCoverArtUrl(playlist, legacyAuth, 350) : 'img/placeholder.jpg',
type: 'playlist', type: 'playlist',
uniqueId: nanoid(), uniqueId: nanoid(),
})); }));
@ -206,14 +231,14 @@ export const getPlaylist = async (id: string) => {
song: (data.playlist.entry || []).map((entry: any, index: any) => ({ song: (data.playlist.entry || []).map((entry: any, index: any) => ({
...entry, ...entry,
streamUrl: getStreamUrl(entry.id, legacyAuth), streamUrl: getStreamUrl(entry.id, legacyAuth),
image: getCoverArtUrl(entry, legacyAuth), image: getCoverArtUrl(entry, legacyAuth, 150),
type: 'music', type: 'music',
index, index,
uniqueId: nanoid(), uniqueId: nanoid(),
})), })),
image: image:
data.playlist.songCount > 0 data.playlist.songCount > 0
? getCoverArtUrl(data.playlist, legacyAuth) ? getCoverArtUrl(data.playlist, legacyAuth, 350)
: 'img/placeholder.jpg', : 'img/placeholder.jpg',
}; };
}; };
@ -255,7 +280,7 @@ export const getStarred = async (options: { musicFolderId?: string | number }) =
...entry, ...entry,
title: entry.name, title: entry.name,
albumId: entry.id, albumId: entry.id,
image: getCoverArtUrl(entry, legacyAuth), image: getCoverArtUrl(entry, legacyAuth, 350),
starred: entry.starred || undefined, starred: entry.starred || undefined,
type: 'album', type: 'album',
isDir: false, isDir: false,
@ -265,7 +290,7 @@ export const getStarred = async (options: { musicFolderId?: string | number }) =
song: (data.starred2.song || []).map((entry: any, index: any) => ({ song: (data.starred2.song || []).map((entry: any, index: any) => ({
...entry, ...entry,
streamUrl: getStreamUrl(entry.id, legacyAuth), streamUrl: getStreamUrl(entry.id, legacyAuth),
image: getCoverArtUrl(entry, legacyAuth), image: getCoverArtUrl(entry, legacyAuth, 150),
starred: entry.starred || undefined, starred: entry.starred || undefined,
type: 'music', type: 'music',
index, index,
@ -275,7 +300,7 @@ export const getStarred = async (options: { musicFolderId?: string | number }) =
...entry, ...entry,
albumCount: entry.albumCount || undefined, albumCount: entry.albumCount || undefined,
coverArt: getCoverArtUrl(entry, legacyAuth), coverArt: getCoverArtUrl(entry, legacyAuth),
image: getCoverArtUrl(entry, legacyAuth), image: getCoverArtUrl(entry, legacyAuth, 350),
starred: entry.starred || Date.now(), // Airsonic does not return the starred date starred: entry.starred || Date.now(), // Airsonic does not return the starred date
type: 'artist', type: 'artist',
index, index,
@ -284,28 +309,25 @@ export const getStarred = async (options: { musicFolderId?: string | number }) =
}; };
}; };
export const getAlbums = async ( export const getAlbums = async (options: {
options: { type:
type: | 'random'
| 'random' | 'newest'
| 'newest' | 'highest'
| 'highest' | 'frequent'
| 'frequent' | 'recent'
| 'recent' | 'alphabeticalByName'
| 'alphabeticalByName' | 'alphabeticalByArtist'
| 'alphabeticalByArtist' | 'starred'
| 'starred' | 'byYear'
| 'byYear' | 'byGenre';
| 'byGenre'; size?: number;
size?: number; offset?: number;
offset?: number; fromYear?: number;
fromYear?: number; toYear?: number;
toYear?: number; genre?: string;
genre?: string; musicFolderId?: string | number;
musicFolderId?: string | number; }) => {
},
coverArtSize = 150
) => {
const { data } = await api.get(`/getAlbumList2`, { const { data } = await api.get(`/getAlbumList2`, {
params: options, params: options,
}); });
@ -316,7 +338,7 @@ export const getAlbums = async (
...entry, ...entry,
title: entry.name, title: entry.name,
albumId: entry.id, albumId: entry.id,
image: getCoverArtUrl(entry, legacyAuth, coverArtSize), image: getCoverArtUrl(entry, legacyAuth, 350),
starred: entry.starred || undefined, starred: entry.starred || undefined,
type: 'album', type: 'album',
isDir: false, isDir: false,
@ -326,28 +348,25 @@ export const getAlbums = async (
}; };
}; };
export const getAlbumsDirect = async ( export const getAlbumsDirect = async (options: {
options: { type:
type: | 'random'
| 'random' | 'newest'
| 'newest' | 'highest'
| 'highest' | 'frequent'
| 'frequent' | 'recent'
| 'recent' | 'alphabeticalByName'
| 'alphabeticalByName' | 'alphabeticalByArtist'
| 'alphabeticalByArtist' | 'starred'
| 'starred' | 'byYear'
| 'byYear' | 'byGenre';
| 'byGenre'; size?: number;
size?: number; offset?: number;
offset?: number; fromYear?: number;
fromYear?: number; toYear?: number;
toYear?: number; genre?: string;
genre?: string; musicFolderId?: string | number;
musicFolderId?: string | number; }) => {
},
coverArtSize = 150
) => {
const { data } = await api.get(`/getAlbumList2`, { const { data } = await api.get(`/getAlbumList2`, {
params: options, params: options,
}); });
@ -356,7 +375,7 @@ export const getAlbumsDirect = async (
...entry, ...entry,
title: entry.name, title: entry.name,
albumId: entry.id, albumId: entry.id,
image: getCoverArtUrl(entry, legacyAuth, coverArtSize), image: getCoverArtUrl(entry, legacyAuth, 350),
starred: entry.starred || undefined, starred: entry.starred || undefined,
type: 'album', type: 'album',
isDir: false, isDir: false,
@ -388,8 +407,7 @@ export const getAllAlbums = (
genre?: string; genre?: string;
musicFolderId?: string | number; musicFolderId?: string | number;
}, },
data: any[] = [], data: any[] = []
coverArtSize = 150
) => { ) => {
const albums: any = api const albums: any = api
.get(`/getAlbumList2`, { .get(`/getAlbumList2`, {
@ -413,7 +431,7 @@ export const getAllAlbums = (
...entry, ...entry,
title: entry.name, title: entry.name,
albumId: entry.id, albumId: entry.id,
image: getCoverArtUrl(entry, legacyAuth, coverArtSize), image: getCoverArtUrl(entry, legacyAuth, 350),
starred: entry.starred || undefined, starred: entry.starred || undefined,
type: 'album', type: 'album',
isDir: false, isDir: false,
@ -439,7 +457,7 @@ export const getAllAlbums = (
return albums; return albums;
}; };
export const getAlbum = async (id: string, coverArtSize = 150) => { export const getAlbum = async (id: string) => {
const { data } = await api.get(`/getAlbum`, { const { data } = await api.get(`/getAlbum`, {
params: { params: {
id, id,
@ -448,13 +466,13 @@ export const getAlbum = async (id: string, coverArtSize = 150) => {
return { return {
...data.album, ...data.album,
image: getCoverArtUrl(data.album, legacyAuth, coverArtSize), image: getCoverArtUrl(data.album, legacyAuth, 350),
type: 'album', type: 'album',
isDir: false, isDir: false,
song: (data.album.song || []).map((entry: any, index: any) => ({ song: (data.album.song || []).map((entry: any, index: any) => ({
...entry, ...entry,
streamUrl: getStreamUrl(entry.id, legacyAuth), streamUrl: getStreamUrl(entry.id, legacyAuth),
image: getCoverArtUrl(entry, legacyAuth, coverArtSize), image: getCoverArtUrl(entry, legacyAuth, 150),
type: 'music', type: 'music',
starred: entry.starred || undefined, starred: entry.starred || undefined,
index, index,
@ -463,16 +481,13 @@ export const getAlbum = async (id: string, coverArtSize = 150) => {
}; };
}; };
export const getRandomSongs = async ( export const getRandomSongs = async (options: {
options: { size?: number;
size?: number; genre?: string;
genre?: string; fromYear?: number;
fromYear?: number; toYear?: number;
toYear?: number; musicFolderId?: number;
musicFolderId?: number; }) => {
},
coverArtSize = 150
) => {
const { data } = await api.get(`/getRandomSongs`, { const { data } = await api.get(`/getRandomSongs`, {
params: options, params: options,
}); });
@ -482,7 +497,7 @@ export const getRandomSongs = async (
song: (data.randomSongs.song || []).map((entry: any, index: any) => ({ song: (data.randomSongs.song || []).map((entry: any, index: any) => ({
...entry, ...entry,
streamUrl: getStreamUrl(entry.id, legacyAuth), streamUrl: getStreamUrl(entry.id, legacyAuth),
image: getCoverArtUrl(entry, legacyAuth, coverArtSize), image: getCoverArtUrl(entry, legacyAuth, 150),
starred: entry.starred || undefined, starred: entry.starred || undefined,
index, index,
uniqueId: nanoid(), uniqueId: nanoid(),
@ -501,7 +516,7 @@ export const getArtists = async (options: { musicFolderId?: string | number }) =
artists.map((artist: any) => artists.map((artist: any) =>
artistList.push({ artistList.push({
...artist, ...artist,
image: getCoverArtUrl(artist, legacyAuth, 150), image: getCoverArtUrl(artist, legacyAuth, 350),
type: 'artist', type: 'artist',
uniqueId: nanoid(), uniqueId: nanoid(),
}) })
@ -510,7 +525,7 @@ export const getArtists = async (options: { musicFolderId?: string | number }) =
return artistList; return artistList;
}; };
export const getArtist = async (id: string, coverArtSize = 150) => { export const getArtist = async (id: string) => {
const { data } = await api.get(`/getArtist`, { const { data } = await api.get(`/getArtist`, {
params: { params: {
id, id,
@ -519,14 +534,14 @@ export const getArtist = async (id: string, coverArtSize = 150) => {
return { return {
...data.artist, ...data.artist,
image: getCoverArtUrl(data.artist, legacyAuth, coverArtSize), image: getCoverArtUrl(data.artist, legacyAuth, 350),
type: 'artist', type: 'artist',
album: (data.artist.album || []).map((entry: any, index: any) => ({ album: (data.artist.album || []).map((entry: any, index: any) => ({
...entry, ...entry,
albumId: entry.id, albumId: entry.id,
type: 'album', type: 'album',
isDir: false, isDir: false,
image: getCoverArtUrl(entry, legacyAuth, coverArtSize), image: getCoverArtUrl(entry, legacyAuth, 350),
starred: entry.starred || undefined, starred: entry.starred || undefined,
index, index,
uniqueId: nanoid(), uniqueId: nanoid(),
@ -686,7 +701,7 @@ export const setRating = async (id: string, rating: number) => {
return data; return data;
}; };
export const getSimilarSongs = async (id: string, count: number, coverArtSize = 150) => { export const getSimilarSongs = async (id: string, count: number) => {
const { data } = await api.get(`/getSimilarSongs2`, { const { data } = await api.get(`/getSimilarSongs2`, {
params: { id, count }, params: { id, count },
}); });
@ -694,7 +709,7 @@ export const getSimilarSongs = async (id: string, count: number, coverArtSize =
return { return {
song: (data.similarSongs2.song || []).map((entry: any, index: any) => ({ song: (data.similarSongs2.song || []).map((entry: any, index: any) => ({
...entry, ...entry,
image: getCoverArtUrl(entry, legacyAuth, coverArtSize), image: getCoverArtUrl(entry, legacyAuth, 150),
index, index,
uniqueId: nanoid(), uniqueId: nanoid(),
})), })),
@ -827,7 +842,7 @@ export const search3 = async (options: {
return { return {
artist: (results.artist || []).map((entry: any, index: any) => ({ artist: (results.artist || []).map((entry: any, index: any) => ({
...entry, ...entry,
image: getCoverArtUrl(entry, legacyAuth), image: getCoverArtUrl(entry, legacyAuth, 350),
starred: entry.starred || undefined, starred: entry.starred || undefined,
type: 'artist', type: 'artist',
index, index,
@ -836,7 +851,7 @@ export const search3 = async (options: {
album: (results.album || []).map((entry: any, index: any) => ({ album: (results.album || []).map((entry: any, index: any) => ({
...entry, ...entry,
albumId: entry.id, albumId: entry.id,
image: getCoverArtUrl(entry, legacyAuth), image: getCoverArtUrl(entry, legacyAuth, 350),
starred: entry.starred || undefined, starred: entry.starred || undefined,
type: 'album', type: 'album',
isDir: false, isDir: false,
@ -846,7 +861,7 @@ export const search3 = async (options: {
song: (results.song || []).map((entry: any, index: any) => ({ song: (results.song || []).map((entry: any, index: any) => ({
...entry, ...entry,
streamUrl: getStreamUrl(entry.id, legacyAuth), streamUrl: getStreamUrl(entry.id, legacyAuth),
image: getCoverArtUrl(entry, legacyAuth), image: getCoverArtUrl(entry, legacyAuth, 150),
type: 'music', type: 'music',
starred: entry.starred || undefined, starred: entry.starred || undefined,
index, index,
@ -878,7 +893,7 @@ export const getIndexes = async (options: {
...folder, ...folder,
title: folder.name, title: folder.name,
isDir: true, isDir: true,
image: getCoverArtUrl(folder, legacyAuth), image: getCoverArtUrl(folder, legacyAuth, 150),
uniqueId: nanoid(), uniqueId: nanoid(),
type: 'folder', type: 'folder',
}); });
@ -894,7 +909,7 @@ export const getIndexes = async (options: {
index, index,
type: 'music', type: 'music',
streamUrl: getStreamUrl(song.id, legacyAuth), streamUrl: getStreamUrl(song.id, legacyAuth),
image: getCoverArtUrl(song, legacyAuth), image: getCoverArtUrl(song, legacyAuth, 150),
uniqueId: nanoid(), uniqueId: nanoid(),
}) })
); );
@ -920,7 +935,7 @@ export const getMusicDirectory = async (options: { id: string }) => {
(folders || []).forEach((folder: any) => (folders || []).forEach((folder: any) =>
child.push({ child.push({
...folder, ...folder,
image: getCoverArtUrl(folder, legacyAuth), image: getCoverArtUrl(folder, legacyAuth, 150),
uniqueId: nanoid(), uniqueId: nanoid(),
type: 'folder', type: 'folder',
}) })
@ -932,7 +947,7 @@ export const getMusicDirectory = async (options: { id: string }) => {
index, index,
type: 'music', type: 'music',
streamUrl: getStreamUrl(song.id, legacyAuth), streamUrl: getStreamUrl(song.id, legacyAuth),
image: getCoverArtUrl(song, legacyAuth), image: getCoverArtUrl(song, legacyAuth, 150),
uniqueId: nanoid(), uniqueId: nanoid(),
}) })
); );
@ -955,7 +970,7 @@ export const getAllDirectorySongs = async (options: { id: string }, data: any[]
index, index,
type: 'music', type: 'music',
streamUrl: getStreamUrl(entry.id, legacyAuth), streamUrl: getStreamUrl(entry.id, legacyAuth),
image: getCoverArtUrl(entry, legacyAuth), image: getCoverArtUrl(entry, legacyAuth, 150),
uniqueId: nanoid(), uniqueId: nanoid(),
}); });
} }

8
src/components/dashboard/Dashboard.tsx

@ -29,22 +29,22 @@ const Dashboard = () => {
const { isLoading: isLoadingRecent, data: recentAlbums }: any = useQuery( const { isLoading: isLoadingRecent, data: recentAlbums }: any = useQuery(
['recentAlbums', musicFolder], ['recentAlbums', musicFolder],
() => getAlbums({ type: 'recent', size: 20, musicFolderId: musicFolder }, 250) () => getAlbums({ type: 'recent', size: 20, musicFolderId: musicFolder })
); );
const { isLoading: isLoadingNewest, data: newestAlbums }: any = useQuery( const { isLoading: isLoadingNewest, data: newestAlbums }: any = useQuery(
['newestAlbums', musicFolder], ['newestAlbums', musicFolder],
() => getAlbums({ type: 'newest', size: 20, musicFolderId: musicFolder }, 250) () => getAlbums({ type: 'newest', size: 20, musicFolderId: musicFolder })
); );
const { isLoading: isLoadingRandom, data: randomAlbums }: any = useQuery( const { isLoading: isLoadingRandom, data: randomAlbums }: any = useQuery(
['randomAlbums', musicFolder], ['randomAlbums', musicFolder],
() => getAlbums({ type: 'random', size: 20, musicFolderId: musicFolder }, 250) () => getAlbums({ type: 'random', size: 20, musicFolderId: musicFolder })
); );
const { isLoading: isLoadingFrequent, data: frequentAlbums }: any = useQuery( const { isLoading: isLoadingFrequent, data: frequentAlbums }: any = useQuery(
['frequentAlbums', musicFolder], ['frequentAlbums', musicFolder],
() => getAlbums({ type: 'frequent', size: 20, musicFolderId: musicFolder }, 250) () => getAlbums({ type: 'frequent', size: 20, musicFolderId: musicFolder })
); );
const handleFavorite = async (rowData: any) => { const handleFavorite = async (rowData: any) => {

Loading…
Cancel
Save