Skip to content

Commit 840a5b8

Browse files
committed
feat: updates
1 parent 9a52681 commit 840a5b8

104 files changed

Lines changed: 3141 additions & 14990 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,4 @@ vercel.json
5757
packages/web/bundle-stats-renderer.html
5858
packages/web/bundle-stats.html
5959
packages/web/storybook-static
60+
packages/desktop/prisma/client

package.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,22 @@
1313
},
1414
"packageManager": "pnpm@7.20.0",
1515
"scripts": {
16+
"postinstall": "turbo run post-install --parallel --no-cache",
1617
"install": "turbo run post-install --parallel --no-cache",
1718
"build": "cross-env-shell IS_ELECTRON=yes turbo run build",
1819
"build:web": "turbo run build:web",
1920
"pack": "turbo run build && turbo run pack",
2021
"pack:test": "turbo run build && turbo run pack:test",
2122
"dev": "cross-env-shell IS_ELECTRON=yes turbo run dev --parallel",
2223
"lint": "eslint .",
23-
"format": "prettier --write \"**/*.{ts,tsx,mjs,js,jsx,md,css}\"",
24-
"storybook": "pnpm -F web storybook",
25-
"storybook:build": "pnpm -F web storybook:build"
24+
"format": "prettier --write \"**/*.{ts,tsx,mjs,js,jsx,md,css}\""
2625
},
2726
"devDependencies": {
2827
"cross-env": "^7.0.3",
2928
"eslint": "^8.31.0",
3029
"prettier": "^2.8.1",
3130
"turbo": "^1.6.3",
32-
"typescript": "^4.9.4",
31+
"typescript": "^4.9.5",
3332
"tsx": "^3.12.1",
3433
"prettier-plugin-tailwindcss": "^0.2.1"
3534
}

packages/desktop/.electron-builder.config.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ module.exports = {
1818
npmRebuild: false,
1919
buildDependenciesFromSource: false,
2020
electronVersion,
21-
afterPack: './scripts/copySQLite3.js',
2221
forceCodeSigning: false,
2322
publish: [
2423
{

packages/desktop/main/appServer/routes/r3play/appleMusic.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import { FastifyInstance } from 'fastify'
22
import proxy from '@fastify/http-proxy'
3+
import { isDev } from '@/desktop/main/env'
34

45
async function appleMusic(fastify: FastifyInstance) {
56
fastify.register(proxy, {
6-
upstream: 'http://168.138.174.244:35530/',
7+
upstream: isDev ? 'http://127.0.0.1:35530/' : 'http://168.138.174.244:35530/',
78
prefix: '/r3play/apple-music',
89
rewritePrefix: '/apple-music',
910
})

packages/desktop/main/appServer/routes/r3play/audio.ts

Lines changed: 56 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import fs from 'fs'
99
import youtube from '@/desktop/main/youtube'
1010
import { CacheAPIs } from '@/shared/CacheAPIs'
1111
import { FetchTracksResponse } from '@/shared/api/Track'
12+
import store from '@/desktop/main/store'
1213

1314
const getAudioFromCache = async (id: number) => {
1415
// get from cache
@@ -76,47 +77,51 @@ const getAudioFromYouTube = async (id: number) => {
7677
const track = fetchTrackResult?.songs?.[0]
7778
if (!track) return
7879

79-
const data = await youtube.matchTrack(track.ar[0].name, track.name)
80-
if (!data) return
81-
return {
82-
data: [
83-
{
84-
source: 'youtube',
85-
id,
86-
url: data.url,
87-
br: data.bitRate,
88-
size: 0,
89-
md5: '',
90-
code: 200,
91-
expi: 0,
92-
type: 'opus',
93-
gain: 0,
94-
fee: 8,
95-
uf: null,
96-
payed: 0,
97-
flag: 4,
98-
canExtend: false,
99-
freeTrialInfo: null,
100-
level: 'standard',
101-
encodeType: 'opus',
102-
freeTrialPrivilege: {
103-
resConsumable: false,
104-
userConsumable: false,
105-
listenType: null,
80+
try {
81+
const data = await youtube.matchTrack(track.ar[0].name, track.name)
82+
if (!data) return
83+
return {
84+
data: [
85+
{
86+
source: 'youtube',
87+
id,
88+
url: data.url,
89+
br: data.bitRate,
90+
size: 0,
91+
md5: '',
92+
code: 200,
93+
expi: 0,
94+
type: 'opus',
95+
gain: 0,
96+
fee: 8,
97+
uf: null,
98+
payed: 0,
99+
flag: 4,
100+
canExtend: false,
101+
freeTrialInfo: null,
102+
level: 'standard',
103+
encodeType: 'opus',
104+
freeTrialPrivilege: {
105+
resConsumable: false,
106+
userConsumable: false,
107+
listenType: null,
108+
},
109+
freeTimeTrialPrivilege: {
110+
resConsumable: false,
111+
userConsumable: false,
112+
type: 0,
113+
remainTime: 0,
114+
},
115+
urlSource: 0,
116+
r3play: {
117+
youtube: data,
118+
},
106119
},
107-
freeTimeTrialPrivilege: {
108-
resConsumable: false,
109-
userConsumable: false,
110-
type: 0,
111-
remainTime: 0,
112-
},
113-
urlSource: 0,
114-
r3play: {
115-
youtube: data,
116-
},
117-
},
118-
],
119-
code: 200,
120+
],
121+
code: 200,
122+
}
123+
} catch (e) {
124+
log.error('getAudioFromYouTube error', id, e)
120125
}
121126
}
122127

@@ -154,9 +159,11 @@ async function audio(fastify: FastifyInstance) {
154159
return
155160
}
156161

157-
const fromYoutube = getAudioFromYouTube(id)
158-
if (fromYoutube) {
159-
return fromYoutube
162+
if (store.get('settings.enableFindTrackOnYouTube')) {
163+
const fromYoutube = getAudioFromYouTube(id)
164+
if (fromYoutube) {
165+
return fromYoutube
166+
}
160167
}
161168

162169
// 是试听歌曲就把url删掉
@@ -181,11 +188,14 @@ async function audio(fastify: FastifyInstance) {
181188
fastify.post(
182189
`/${appName.toLowerCase()}/audio/:id`,
183190
async (
184-
req: FastifyRequest<{ Params: { id: string }; Querystring: { url: string } }>,
191+
req: FastifyRequest<{
192+
Params: { id: string }
193+
Querystring: { url: string; bitrate: number }
194+
}>,
185195
reply
186196
) => {
187197
const id = Number(req.params.id)
188-
const { url } = req.query
198+
const { url, bitrate } = req.query
189199
if (isNaN(id)) {
190200
return reply.status(400).send({ error: 'Invalid param id' })
191201
}
@@ -200,7 +210,7 @@ async function audio(fastify: FastifyInstance) {
200210
}
201211

202212
try {
203-
await cache.setAudio(await data.toBuffer(), { id, url })
213+
await cache.setAudio(await data.toBuffer(), { id, url, bitrate })
204214
reply.status(200).send('Audio cached!')
205215
} catch (error) {
206216
reply.status(500).send({ error })

packages/desktop/main/cache.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ class Cache {
238238
return
239239
}
240240

241-
getAudio(filename: string, reply: FastifyReply) {
241+
async getAudio(filename: string, reply: FastifyReply) {
242242
if (!filename) {
243243
return reply.status(400).send({ error: 'No filename provided' })
244244
}
@@ -252,6 +252,7 @@ class Cache {
252252
fs.unlinkSync(path)
253253
return reply.status(404).send({ error: 'Audio not found' })
254254
}
255+
await prisma.audio.update({ where: { id }, data: { updatedAt: new Date() } })
255256
reply
256257
.status(206)
257258
.header('Accept-Ranges', 'bytes')
@@ -263,7 +264,10 @@ class Cache {
263264
}
264265
}
265266

266-
async setAudio(buffer: Buffer, { id, url }: { id: number; url: string }) {
267+
async setAudio(
268+
buffer: Buffer,
269+
{ id, url, bitrate }: { id: number; url: string; bitrate: number }
270+
) {
267271
const path = `${app.getPath('userData')}/audio_cache`
268272

269273
try {
@@ -273,7 +277,7 @@ class Cache {
273277
}
274278

275279
const meta = await musicMetadata.parseBuffer(buffer)
276-
const bitRate = (meta?.format?.codec === 'OPUS' ? 165000 : meta.format.bitrate ?? 0) / 1000
280+
const bitRate = ~~((meta.format.bitrate || bitrate || 0) / 1000)
277281
const format =
278282
{
279283
'MPEG 1 Layer 3': 'mp3',

packages/desktop/main/ipcMain.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { Thumbar } from './windowsTaskbar'
1212
import fastFolderSize from 'fast-folder-size'
1313
import path from 'path'
1414
import prettyBytes from 'pretty-bytes'
15+
import prisma from './prisma'
1516

1617
const on = <T extends keyof IpcChannelsParams>(
1718
channel: T,
@@ -203,7 +204,7 @@ function initOtherIpcMain() {
203204
* 退出登陆
204205
*/
205206
handle(IpcChannels.Logout, async () => {
206-
// db.truncate(Tables.AccountData)
207+
await prisma.accountData.deleteMany({})
207208
return true
208209
})
209210

0 commit comments

Comments
 (0)