Skip to content

Commit

Permalink
feat: updates
Browse files Browse the repository at this point in the history
  • Loading branch information
qier222 committed Mar 2, 2023
1 parent 9a52681 commit 840a5b8
Show file tree
Hide file tree
Showing 104 changed files with 3,141 additions and 14,990 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,4 @@ vercel.json
packages/web/bundle-stats-renderer.html
packages/web/bundle-stats.html
packages/web/storybook-static
packages/desktop/prisma/client
7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,22 @@
},
"packageManager": "[email protected]",
"scripts": {
"postinstall": "turbo run post-install --parallel --no-cache",
"install": "turbo run post-install --parallel --no-cache",
"build": "cross-env-shell IS_ELECTRON=yes turbo run build",
"build:web": "turbo run build:web",
"pack": "turbo run build && turbo run pack",
"pack:test": "turbo run build && turbo run pack:test",
"dev": "cross-env-shell IS_ELECTRON=yes turbo run dev --parallel",
"lint": "eslint .",
"format": "prettier --write \"**/*.{ts,tsx,mjs,js,jsx,md,css}\"",
"storybook": "pnpm -F web storybook",
"storybook:build": "pnpm -F web storybook:build"
"format": "prettier --write \"**/*.{ts,tsx,mjs,js,jsx,md,css}\""
},
"devDependencies": {
"cross-env": "^7.0.3",
"eslint": "^8.31.0",
"prettier": "^2.8.1",
"turbo": "^1.6.3",
"typescript": "^4.9.4",
"typescript": "^4.9.5",
"tsx": "^3.12.1",
"prettier-plugin-tailwindcss": "^0.2.1"
}
Expand Down
1 change: 0 additions & 1 deletion packages/desktop/.electron-builder.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ module.exports = {
npmRebuild: false,
buildDependenciesFromSource: false,
electronVersion,
afterPack: './scripts/copySQLite3.js',
forceCodeSigning: false,
publish: [
{
Expand Down
3 changes: 2 additions & 1 deletion packages/desktop/main/appServer/routes/r3play/appleMusic.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { FastifyInstance } from 'fastify'
import proxy from '@fastify/http-proxy'
import { isDev } from '@/desktop/main/env'

async function appleMusic(fastify: FastifyInstance) {
fastify.register(proxy, {
upstream: 'http://168.138.174.244:35530/',
upstream: isDev ? 'http://127.0.0.1:35530/' : 'http://168.138.174.244:35530/',
prefix: '/r3play/apple-music',
rewritePrefix: '/apple-music',
})
Expand Down
102 changes: 56 additions & 46 deletions packages/desktop/main/appServer/routes/r3play/audio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import fs from 'fs'
import youtube from '@/desktop/main/youtube'
import { CacheAPIs } from '@/shared/CacheAPIs'
import { FetchTracksResponse } from '@/shared/api/Track'
import store from '@/desktop/main/store'

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

const data = await youtube.matchTrack(track.ar[0].name, track.name)
if (!data) return
return {
data: [
{
source: 'youtube',
id,
url: data.url,
br: data.bitRate,
size: 0,
md5: '',
code: 200,
expi: 0,
type: 'opus',
gain: 0,
fee: 8,
uf: null,
payed: 0,
flag: 4,
canExtend: false,
freeTrialInfo: null,
level: 'standard',
encodeType: 'opus',
freeTrialPrivilege: {
resConsumable: false,
userConsumable: false,
listenType: null,
try {
const data = await youtube.matchTrack(track.ar[0].name, track.name)
if (!data) return
return {
data: [
{
source: 'youtube',
id,
url: data.url,
br: data.bitRate,
size: 0,
md5: '',
code: 200,
expi: 0,
type: 'opus',
gain: 0,
fee: 8,
uf: null,
payed: 0,
flag: 4,
canExtend: false,
freeTrialInfo: null,
level: 'standard',
encodeType: 'opus',
freeTrialPrivilege: {
resConsumable: false,
userConsumable: false,
listenType: null,
},
freeTimeTrialPrivilege: {
resConsumable: false,
userConsumable: false,
type: 0,
remainTime: 0,
},
urlSource: 0,
r3play: {
youtube: data,
},
},
freeTimeTrialPrivilege: {
resConsumable: false,
userConsumable: false,
type: 0,
remainTime: 0,
},
urlSource: 0,
r3play: {
youtube: data,
},
},
],
code: 200,
],
code: 200,
}
} catch (e) {
log.error('getAudioFromYouTube error', id, e)
}
}

Expand Down Expand Up @@ -154,9 +159,11 @@ async function audio(fastify: FastifyInstance) {
return
}

const fromYoutube = getAudioFromYouTube(id)
if (fromYoutube) {
return fromYoutube
if (store.get('settings.enableFindTrackOnYouTube')) {
const fromYoutube = getAudioFromYouTube(id)
if (fromYoutube) {
return fromYoutube
}
}

// 是试听歌曲就把url删掉
Expand All @@ -181,11 +188,14 @@ async function audio(fastify: FastifyInstance) {
fastify.post(
`/${appName.toLowerCase()}/audio/:id`,
async (
req: FastifyRequest<{ Params: { id: string }; Querystring: { url: string } }>,
req: FastifyRequest<{
Params: { id: string }
Querystring: { url: string; bitrate: number }
}>,
reply
) => {
const id = Number(req.params.id)
const { url } = req.query
const { url, bitrate } = req.query
if (isNaN(id)) {
return reply.status(400).send({ error: 'Invalid param id' })
}
Expand All @@ -200,7 +210,7 @@ async function audio(fastify: FastifyInstance) {
}

try {
await cache.setAudio(await data.toBuffer(), { id, url })
await cache.setAudio(await data.toBuffer(), { id, url, bitrate })
reply.status(200).send('Audio cached!')
} catch (error) {
reply.status(500).send({ error })
Expand Down
10 changes: 7 additions & 3 deletions packages/desktop/main/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ class Cache {
return
}

getAudio(filename: string, reply: FastifyReply) {
async getAudio(filename: string, reply: FastifyReply) {
if (!filename) {
return reply.status(400).send({ error: 'No filename provided' })
}
Expand All @@ -252,6 +252,7 @@ class Cache {
fs.unlinkSync(path)
return reply.status(404).send({ error: 'Audio not found' })
}
await prisma.audio.update({ where: { id }, data: { updatedAt: new Date() } })
reply
.status(206)
.header('Accept-Ranges', 'bytes')
Expand All @@ -263,7 +264,10 @@ class Cache {
}
}

async setAudio(buffer: Buffer, { id, url }: { id: number; url: string }) {
async setAudio(
buffer: Buffer,
{ id, url, bitrate }: { id: number; url: string; bitrate: number }
) {
const path = `${app.getPath('userData')}/audio_cache`

try {
Expand All @@ -273,7 +277,7 @@ class Cache {
}

const meta = await musicMetadata.parseBuffer(buffer)
const bitRate = (meta?.format?.codec === 'OPUS' ? 165000 : meta.format.bitrate ?? 0) / 1000
const bitRate = ~~((meta.format.bitrate || bitrate || 0) / 1000)
const format =
{
'MPEG 1 Layer 3': 'mp3',
Expand Down
3 changes: 2 additions & 1 deletion packages/desktop/main/ipcMain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { Thumbar } from './windowsTaskbar'
import fastFolderSize from 'fast-folder-size'
import path from 'path'
import prettyBytes from 'pretty-bytes'
import prisma from './prisma'

const on = <T extends keyof IpcChannelsParams>(
channel: T,
Expand Down Expand Up @@ -203,7 +204,7 @@ function initOtherIpcMain() {
* 退出登陆
*/
handle(IpcChannels.Logout, async () => {
// db.truncate(Tables.AccountData)
await prisma.accountData.deleteMany({})
return true
})

Expand Down
Loading

0 comments on commit 840a5b8

Please sign in to comment.