mirror of
https://github.com/GiriNeko/YesPlayMusic.git
synced 2025-12-17 13:48:02 +00:00
update
This commit is contained in:
parent
32050e4553
commit
6aee8ae38e
41 changed files with 523 additions and 415 deletions
|
|
@ -13,6 +13,7 @@ import fastFolderSize from 'fast-folder-size'
|
|||
import path from 'path'
|
||||
import prettyBytes from 'pretty-bytes'
|
||||
import { db, Tables } from './db'
|
||||
import { promisify } from 'util'
|
||||
|
||||
log.info('[electron] ipcMain.ts')
|
||||
|
||||
|
|
@ -137,15 +138,15 @@ function initOtherIpcMain() {
|
|||
/**
|
||||
* 清除API缓存
|
||||
*/
|
||||
on(IpcChannels.ClearAPICache, () => {
|
||||
// db.truncate(Tables.Track)
|
||||
// db.truncate(Tables.Album)
|
||||
// db.truncate(Tables.Artist)
|
||||
// db.truncate(Tables.Playlist)
|
||||
// db.truncate(Tables.ArtistAlbum)
|
||||
// db.truncate(Tables.AccountData)
|
||||
// db.truncate(Tables.Audio)
|
||||
// db.vacuum()
|
||||
handle(IpcChannels.ClearAPICache, async () => {
|
||||
db.truncate(Tables.Track)
|
||||
db.truncate(Tables.Album)
|
||||
db.truncate(Tables.Artist)
|
||||
db.truncate(Tables.Playlist)
|
||||
db.truncate(Tables.ArtistAlbum)
|
||||
db.truncate(Tables.AccountData)
|
||||
db.truncate(Tables.Audio)
|
||||
db.vacuum()
|
||||
})
|
||||
|
||||
/**
|
||||
|
|
@ -170,6 +171,31 @@ function initOtherIpcMain() {
|
|||
}
|
||||
})
|
||||
|
||||
// 获取缓存位置
|
||||
handle(IpcChannels.GetCachePath, async () => {
|
||||
return path.join(app.getPath('userData'), './audio_cache')
|
||||
})
|
||||
|
||||
/**
|
||||
* 获取音频缓存文件夹大小
|
||||
*/
|
||||
handle(IpcChannels.GetAudioCacheSize, async () => {
|
||||
const fastFolderSizeAsync = promisify(fastFolderSize)
|
||||
const bytes = await fastFolderSizeAsync(path.join(app.getPath('userData'), './audio_cache'))
|
||||
return prettyBytes(bytes ?? 0)
|
||||
})
|
||||
|
||||
handle(IpcChannels.ClearAudioCache, async () => {
|
||||
try {
|
||||
const audioCachePath = path.join(app.getPath('userData'), './audio_cache')
|
||||
fs.rmdirSync(audioCachePath, { recursive: true })
|
||||
fs.mkdirSync(audioCachePath)
|
||||
return true
|
||||
} catch (e) {
|
||||
return false
|
||||
}
|
||||
})
|
||||
|
||||
/**
|
||||
* 缓存封面颜色
|
||||
*/
|
||||
|
|
@ -178,17 +204,6 @@ function initOtherIpcMain() {
|
|||
cache.set(CacheAPIs.CoverColor, { id, color })
|
||||
})
|
||||
|
||||
/**
|
||||
* 获取音频缓存文件夹大小
|
||||
*/
|
||||
on(IpcChannels.GetAudioCacheSize, event => {
|
||||
fastFolderSize(path.join(app.getPath('userData'), './audio_cache'), (error, bytes) => {
|
||||
if (error) throw error
|
||||
|
||||
event.returnValue = prettyBytes(bytes ?? 0)
|
||||
})
|
||||
})
|
||||
|
||||
/**
|
||||
* 从Apple Music获取专辑信息
|
||||
*/
|
||||
|
|
@ -235,30 +250,26 @@ function initOtherIpcMain() {
|
|||
* 导出tables到json文件,方便查看table大小(dev环境)
|
||||
*/
|
||||
if (process.env.NODE_ENV === 'development') {
|
||||
// on(IpcChannels.DevDbExportJson, () => {
|
||||
// const tables = [
|
||||
// Tables.ArtistAlbum,
|
||||
// Tables.Playlist,
|
||||
// Tables.Album,
|
||||
// Tables.Track,
|
||||
// Tables.Artist,
|
||||
// Tables.Audio,
|
||||
// Tables.AccountData,
|
||||
// Tables.Lyric,
|
||||
// ]
|
||||
// tables.forEach(table => {
|
||||
// const data = db.findAll(table)
|
||||
// fs.writeFile(
|
||||
// `./tmp/${table}.json`,
|
||||
// JSON.stringify(data),
|
||||
// function (err) {
|
||||
// if (err) {
|
||||
// return console.log(err)
|
||||
// }
|
||||
// console.log('The file was saved!')
|
||||
// }
|
||||
// )
|
||||
// })
|
||||
// })
|
||||
on(IpcChannels.DevDbExportJson, () => {
|
||||
const tables = [
|
||||
Tables.ArtistAlbum,
|
||||
Tables.Playlist,
|
||||
Tables.Album,
|
||||
Tables.Track,
|
||||
Tables.Artist,
|
||||
Tables.Audio,
|
||||
Tables.AccountData,
|
||||
Tables.Lyrics,
|
||||
]
|
||||
tables.forEach(table => {
|
||||
const data = db.findAll(table)
|
||||
fs.writeFile(`./tmp/${table}.json`, JSON.stringify(data), function (err) {
|
||||
if (err) {
|
||||
return console.log(err)
|
||||
}
|
||||
console.log('The file was saved!')
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue