From 1eb38937fc2d0e98632d7a9733318d41fc57f627 Mon Sep 17 00:00:00 2001 From: qier222 Date: Tue, 5 Apr 2022 23:02:59 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=94=AF=E6=8C=81=E7=BC=93=E5=AD=98?= =?UTF-8?q?=E6=AD=8C=E8=AF=8D=E5=92=8C=E4=B8=80=E4=BA=9B=E5=B0=8F=E6=9B=B4?= =?UTF-8?q?=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/cache.ts | 19 +++++++++++++++++-- src/main/db.ts | 2 ++ src/main/logger.ts | 11 ++++++++--- src/main/migrations/init.sql | 9 +++++---- src/main/server.ts | 2 +- src/renderer/hooks/useUserAlbums.ts | 1 + src/renderer/hooks/useUserArtists.ts | 1 + src/renderer/hooks/useUserPlaylists.ts | 1 + src/renderer/pages/Artist.tsx | 2 +- src/renderer/pages/Home.tsx | 2 +- src/renderer/pages/Library.tsx | 12 ++++++------ 11 files changed, 44 insertions(+), 18 deletions(-) diff --git a/src/main/cache.ts b/src/main/cache.ts index e09c87e..2275a5e 100644 --- a/src/main/cache.ts +++ b/src/main/cache.ts @@ -80,6 +80,15 @@ export async function setCache(api: string, data: any, query: any) { }) break } + case 'lyric': { + if (!data.lrc) return + db.upsert(Tables.LYRIC, { + id: query.id, + json: JSON.stringify(data), + updatedAt: Date.now(), + }) + break + } } } @@ -160,6 +169,12 @@ export function getCache(api: string, query: any): any { ) return artistAlbums } + case 'lyric': { + if (isNaN(Number(query?.id))) return + const data = db.find(Tables.LYRIC, query.id) + if (data?.json) return JSON.parse(data.json) + break + } } } @@ -168,7 +183,7 @@ export async function getCacheForExpress(api: string, req: Request) { if (api === 'song/detail') { const cache = getCache(api, req.query) if (cache) { - logger.info(`[cache] Cache hit for ${req.path}`) + logger.debug(`[cache] Cache hit for ${req.path}`) return cache } } @@ -185,7 +200,7 @@ export async function getCacheForExpress(api: string, req: Request) { ) if (!isAudioFileExists) return - logger.info(`[cache] Audio cache hit for ${req.path}`) + logger.debug(`[cache] Audio cache hit for ${req.path}`) return { data: [ diff --git a/src/main/db.ts b/src/main/db.ts index e883237..3796c3a 100644 --- a/src/main/db.ts +++ b/src/main/db.ts @@ -15,6 +15,7 @@ export enum Tables { ARTIST = 'artist', PLAYLIST = 'playlist', ARTIST_ALBUMS = 'artist_album', + LYRIC = 'lyric', // Special tables ACCOUNT_DATA = 'account_data', @@ -123,6 +124,7 @@ if (process.env.NODE_ENV === 'development') { Tables.ARTIST, Tables.AUDIO, Tables.ACCOUNT_DATA, + Tables.LYRIC, ] tables.forEach(table => { const data = db.findAll(table) diff --git a/src/main/logger.ts b/src/main/logger.ts index a1e941d..0da81ca 100644 --- a/src/main/logger.ts +++ b/src/main/logger.ts @@ -1,12 +1,17 @@ -import { app } from 'electron' +/** By default, it writes logs to the following locations: + * on Linux: ~/.config/{app name}/logs/{process type}.log + * on macOS: ~/Library/Logs/{app name}/{process type}.log + * on Windows: %USERPROFILE%\AppData\Roaming\{app name}\logs\{process type}.log + * @see https://www.npmjs.com/package/electron-log + */ + import logger from 'electron-log' import pc from 'picocolors' Object.assign(console, logger.functions) - logger.transports.console.format = `${pc.dim('{h}:{i}:{s}{scope}')} › {text}` +logger.transports.file.level = 'info' -logger.transports.file.level = app.isPackaged ? 'info' : 'debug' logger.info( `\n\n██╗ ██╗███████╗███████╗██████╗ ██╗ █████╗ ██╗ ██╗███╗ ███╗██╗ ██╗███████╗██╗ ██████╗ ╚██╗ ██╔╝██╔════╝██╔════╝██╔══██╗██║ ██╔══██╗╚██╗ ██╔╝████╗ ████║██║ ██║██╔════╝██║██╔════╝ diff --git a/src/main/migrations/init.sql b/src/main/migrations/init.sql index 489f477..18ea69c 100644 --- a/src/main/migrations/init.sql +++ b/src/main/migrations/init.sql @@ -1,7 +1,8 @@ -CREATE TABLE "artist" ("id" integer NOT NULL,"json" text NOT NULL,"updatedAt" int NOT NULL, PRIMARY KEY (id)); +CREATE TABLE "account_data" ("id" text NOT NULL,"json" text NOT NULL,"updateAt" int NOT NULL, PRIMARY KEY (id)); CREATE TABLE "album" ("id" integer NOT NULL,"json" text NOT NULL,"updatedAt" int NOT NULL, PRIMARY KEY (id)); +CREATE TABLE "artist_album" ("id" integer NOT NULL,"json" text NOT NULL,"updatedAt" int NOT NULL, PRIMARY KEY (id)); +CREATE TABLE "artist" ("id" integer NOT NULL,"json" text NOT NULL,"updatedAt" int NOT NULL, PRIMARY KEY (id)); +CREATE TABLE "audio" ("id" integer NOT NULL,"br" int NOT NULL,"type" text NOT NULL,"srouce" text NOT NULL,"updateAt" int NOT NULL, PRIMARY KEY (id)); +CREATE TABLE "lyric" ("id" integer NOT NULL,"json" text NOT NULL,"updatedAt" integer NOT NULL, PRIMARY KEY (id)); CREATE TABLE "playlist" ("id" integer NOT NULL,"json" text NOT NULL,"updatedAt" int NOT NULL, PRIMARY KEY (id)); CREATE TABLE "track" ("id" integer NOT NULL,"json" text NOT NULL,"updatedAt" int NOT NULL, PRIMARY KEY (id)); -CREATE TABLE "artist_album" ("id" integer NOT NULL,"json" text NOT NULL,"updatedAt" int NOT NULL, PRIMARY KEY (id)); -CREATE TABLE "audio" ("id" integer NOT NULL,"br" int NOT NULL,"type" text NOT NULL,"srouce" text NOT NULL,"updateAt" int NOT NULL, PRIMARY KEY (id)); -CREATE TABLE "account_data" ("id" text NOT NULL,"json" text NOT NULL,"updateAt" int NOT NULL, PRIMARY KEY (id)); diff --git a/src/main/server.ts b/src/main/server.ts index 1c17f36..a206c1e 100644 --- a/src/main/server.ts +++ b/src/main/server.ts @@ -29,7 +29,7 @@ Object.entries(neteaseApi).forEach(([name, handler]) => { name = pathCase(name) const wrappedHandler = async (req: Request, res: Response) => { - logger.info(`[server] Handling request: ${req.path}`) + logger.debug(`[server] Handling request: ${req.path}`) // Get from cache const cache = await getCacheForExpress(name, req) diff --git a/src/renderer/hooks/useUserAlbums.ts b/src/renderer/hooks/useUserAlbums.ts index 5f6cb5f..2041d0e 100644 --- a/src/renderer/hooks/useUserAlbums.ts +++ b/src/renderer/hooks/useUserAlbums.ts @@ -10,6 +10,7 @@ export default function useUserAlbums(params: FetchUserAlbumsParams = {}) { [UserApiNames.FETCH_USER_ALBUMS, user?.profile?.userId ?? 0], () => fetchUserAlbums(params), { + refetchOnWindowFocus: true, placeholderData: (): FetchUserAlbumsResponse | undefined => window.ipcRenderer?.sendSync('getApiCacheSync', { api: 'album/sublist', diff --git a/src/renderer/hooks/useUserArtists.ts b/src/renderer/hooks/useUserArtists.ts index acf3d58..c7e8f1d 100644 --- a/src/renderer/hooks/useUserArtists.ts +++ b/src/renderer/hooks/useUserArtists.ts @@ -3,6 +3,7 @@ import { UserApiNames, fetchUserArtists } from '@/api/user' export default function useUserArtists() { return useQuery([UserApiNames.FETCH_USER_ARTIST], fetchUserArtists, { + refetchOnWindowFocus: true, placeholderData: (): FetchUserArtistsResponse => window.ipcRenderer?.sendSync('getApiCacheSync', { api: 'album/sublist', diff --git a/src/renderer/hooks/useUserPlaylists.ts b/src/renderer/hooks/useUserPlaylists.ts index b722c2e..ac75240 100644 --- a/src/renderer/hooks/useUserPlaylists.ts +++ b/src/renderer/hooks/useUserPlaylists.ts @@ -29,6 +29,7 @@ export default function useUserPlaylists() { params.uid !== 0 && params.offset !== undefined ), + refetchOnWindowFocus: true, placeholderData: (): FetchUserPlaylistsResponse => window.ipcRenderer?.sendSync('getApiCacheSync', { api: 'user/playlist', diff --git a/src/renderer/pages/Artist.tsx b/src/renderer/pages/Artist.tsx index 1e49cf0..8b1343c 100644 --- a/src/renderer/pages/Artist.tsx +++ b/src/renderer/pages/Artist.tsx @@ -64,7 +64,7 @@ const LatestRelease = ({ ) : ( diff --git a/src/renderer/pages/Home.tsx b/src/renderer/pages/Home.tsx index 8cffdb9..1d2cb81 100644 --- a/src/renderer/pages/Home.tsx +++ b/src/renderer/pages/Home.tsx @@ -40,7 +40,7 @@ export default function Home() { ) const playlists = [ - ...(dailyRecommendPlaylists?.recommend?.slice(1) ?? []), + ...(dailyRecommendPlaylists?.recommend?.slice(1).slice(0, 8) ?? []), ...(recommendedPlaylists?.result ?? []), ] .slice(0, 10) diff --git a/src/renderer/pages/Library.tsx b/src/renderer/pages/Library.tsx index cbc0f64..1c3dbea 100644 --- a/src/renderer/pages/Library.tsx +++ b/src/renderer/pages/Library.tsx @@ -73,7 +73,7 @@ const LikedTracksCard = ({ className }: { className?: string }) => { navigate(`/playlist/${likedSongsPlaylist.playlist.id}`) } className={classNames( - 'relative flex h-full w-full flex-col justify-between rounded-2xl bg-brand-50 py-5 px-6 text-brand-600 ', + 'relative flex h-full w-full flex-col justify-between rounded-2xl bg-brand-50 py-5 px-6 text-brand-600 dark:bg-brand-800 dark:text-brand-50', className )} > @@ -91,7 +91,7 @@ const LikedTracksCard = ({ className }: { className?: string }) => { @@ -111,7 +111,7 @@ const OtherCard = ({ return (
@@ -180,7 +180,7 @@ const TabHeader = ({ setActiveTab: (tab: keyof TabsType) => void }) => { return ( -
+
{Object.entries(tabs).map(([id, name]) => (
@@ -238,7 +238,7 @@ const Library = () => { return (
-
+
{user?.profile?.nickname}的音乐库