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 = ({