Skip to content

Commit

Permalink
feat: 添加useHead到各个页面,添加preview:backend scripts,升级naily,修复ssr下client端r…
Browse files Browse the repository at this point in the history
…pc问题
  • Loading branch information
nailiable committed Dec 28, 2024
1 parent 11be029 commit a1a9f28
Show file tree
Hide file tree
Showing 16 changed files with 138 additions and 96 deletions.
Empty file added app/types.ts
Empty file.
4 changes: 1 addition & 3 deletions backend/controllers/music.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ export class MusicControllerImpl implements MusicController {
) {}

async getVersion(): Promise<VersionResponse> {
return {
version,
}
return { version }
}
}
13 changes: 8 additions & 5 deletions frontend/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,15 @@ function getRouterOptions(): RouterOptions {
export const createApp = ViteSSG(
App,
getRouterOptions(),
(ctx) => {
async (ctx) => {
// install all modules under `modules/`
Object.values(import.meta.glob<{ install: UserModule }>('./modules/*.ts', { eager: true }))
.forEach(i => i.install?.(ctx))
await Promise.all(Object.values(import.meta.glob<{ install: UserModule }>('./modules/*.ts'))
.map(async i => await i()))
.then(async i => await Promise.all(i.map(i => i.install?.(ctx))))

Object.values(import.meta.glob<{ install: UserModule }>('./directives/*.ts', { eager: true }))
.forEach(i => i.install?.(ctx))
// install all directives under `directives/`
await Promise.all(Object.values(import.meta.glob<{ install: UserModule }>('./directives/*.ts'))
.map(async i => await i()))
.then(async i => await Promise.all(i.map(i => i.install?.(ctx))))
},
)
7 changes: 4 additions & 3 deletions frontend/modules/pinia.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import type { UserModule } from '~/types'
import { createPinia } from 'pinia'
import persistedstate from 'pinia-plugin-persistedstate'

// Setup Pinia
// https://pinia.vuejs.org/
export const install: UserModule = ({ isClient, initialState, app }) => {
export const install: UserModule = async ({ isClient, initialState, app }) => {
const pinia = createPinia()
pinia.use(persistedstate)
if (isClient)
pinia.use((await import('pinia-plugin-persistedstate')).default)

app.use(pinia)
// Refer to
// https://github.com/antfu/vite-ssg/blob/main/README.md#state-serialization
Expand Down
1 change: 1 addition & 0 deletions frontend/pages/artist/[id].vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import { ArtistDetailResponse } from '#/artist.protocol'
import { useMusicController } from '~/apis/music'
useHead({ title: '歌手详情 - 网易云音乐下崽器' })
const route = useRoute()
const { id } = route.params as { id: string }
Expand Down
1 change: 1 addition & 0 deletions frontend/pages/login.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { CheckQrCodeResponseType } from '#/user.protocol'
import { match } from 'ts-pattern'
import { useMusicController } from '~/apis/music'
useHead({ title: '登录 - 网易云音乐下崽器' })
const router = useRouter()
const cookie = useLocalStorage('__naily:music-downloader-cookie__', '')
const musicController = useMusicController()
Expand Down
1 change: 1 addition & 0 deletions frontend/pages/my.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { CurrentAccountResponse } from '#/user.protocol'
import { useMessage } from 'naive-ui'
import { useMusicController } from '~/apis/music'
useHead({ title: '我的 - 网易云音乐下崽器' })
const { t } = useI18n()
const router = useRouter()
const message = useMessage()
Expand Down
1 change: 1 addition & 0 deletions frontend/pages/play-list/[id].vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useMusicController } from '~/apis/music'
defineOptions({ name: 'PlayListDetail' })
useHead({ title: '歌单详情 - 网易云音乐下崽器' })
const cookie = useLocalStorage('__naily:music-downloader-cookie__', undefined)
const route = useRoute()
const { id } = route.params as { id: string }
Expand Down
2 changes: 1 addition & 1 deletion frontend/pages/setting.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
import { NSelect } from 'naive-ui'
import { loadLanguageAsync } from '~/modules/i18n'
useHead({ title: '设置 - 网易云音乐下崽器' })
const { locale } = useI18n()
const settingStore = useSettingStore()
const { isElectron } = useEnvironment()
</script>
Expand Down
2 changes: 1 addition & 1 deletion frontend/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import type { ViteSSGContext } from 'vite-ssg'

export type UserModule = (ctx: ViteSSGContext) => void
export type UserModule = (ctx: ViteSSGContext) => void | Promise<void>
2 changes: 1 addition & 1 deletion frontend/utils/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export function useRequest(): AxiosRpcClientReturn {
const settingStore = useSettingStore()

// 如果是electron环境,使用electron rpc
if (isClient && window.electron) {
if (isClient && globalThis.window.electron) {
return createElectronClient(
window.electron.request,
'__naily:electron:rpc__',
Expand Down
38 changes: 20 additions & 18 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@
"author": "Naily Zero <zero@naily.cc> (https://naily.cc)",
"main": "./dist-electron/main.js",
"scripts": {
"build": "vite-ssg build",
"build": "vite-ssg build && tsx scripts/run-finish.ts",
"build:electron": "cross-env ELECTRON=true vite build && electron-builder",
"dev": "vite",
"dev:electron": "cross-env ELECTRON=true vite",
"lint": "eslint .",
"lint:fix": "eslint . --fix",
"preview": "vite preview",
"preview:backend": "cross-env NODE_ENV=production node ./dist/backend/main.js",
"preview-https": "serve dist",
"preview-server": "cross-env NODE_ENV=production node ./dist/backend/main.js",
"test": "vitest",
Expand All @@ -27,8 +29,8 @@
"dependencies": {
"@iconify-json/material-symbols": "^1.2.12",
"@naiable/utils": "^0.0.6",
"@nailyjs/electron": "^2.0.14",
"@nailyjs/typeorm": "^2.0.25",
"@nailyjs/electron": "^2.0.15",
"@nailyjs/typeorm": "^2.0.28",
"@types/js-yaml": "^4.0.9",
"@types/lodash-es": "^4.17.12",
"@unhead/vue": "^1.11.14",
Expand All @@ -39,11 +41,11 @@
"defu": "^6.1.4",
"js-yaml": "^4.1.0",
"lodash-es": "^4.17.21",
"naive-ui": "^2.40.3",
"naive-ui": "^2.40.4",
"nprogress": "^0.2.0",
"pinia": "^2.3.0",
"pinia-plugin-persistedstate": "^4.1.3",
"ts-pattern": "^5.5.0",
"pinia-plugin-persistedstate": "^4.2.0",
"ts-pattern": "^5.6.0",
"vue": "^3.5.13",
"vue-demi": "^0.14.10",
"vue-i18n": "^9.14.2",
Expand All @@ -53,15 +55,15 @@
"devDependencies": {
"@antfu/eslint-config": "^2.27.3",
"@css-render/vue3-ssr": "^0.15.14",
"@iconify-json/carbon": "^1.2.4",
"@iconify-json/ph": "^1.2.1",
"@iconify-json/carbon": "^1.2.5",
"@iconify-json/ph": "^1.2.2",
"@intlify/unplugin-vue-i18n": "^4.0.0",
"@nailyjs/backend": "^2.0.12",
"@nailyjs/backend": "^2.0.15",
"@nailyjs/config": "^2.0.7",
"@nailyjs/eslint": "^2.0.8",
"@nailyjs/ioc": "^2.0.6",
"@nailyjs/rpc": "^2.0.12",
"@shikijs/markdown-it": "^1.24.2",
"@nailyjs/rpc": "^2.0.15",
"@shikijs/markdown-it": "^1.24.4",
"@types/markdown-it-link-attributes": "^3.0.5",
"@types/nprogress": "^0.2.3",
"@unocss/eslint-config": "^0.62.4",
Expand All @@ -71,7 +73,7 @@
"NeteaseCloudMusicApi": "^4.25.0",
"critters": "^0.0.24",
"cross-env": "^7.0.3",
"cypress": "^13.16.1",
"cypress": "^13.17.0",
"cypress-vite": "^1.5.0",
"electron": "^33.2.1",
"electron-builder": "^25.1.8",
Expand All @@ -80,20 +82,20 @@
"eslint-plugin-format": "^0.1.3",
"https-localhost": "^4.7.1",
"less": "^4.2.1",
"lint-staged": "^15.2.11",
"lint-staged": "^15.3.0",
"markdown-it-link-attributes": "^4.0.1",
"pnpm": "^9.15.0",
"pnpm": "^9.15.1",
"reflect-metadata": "^0.2.2",
"rimraf": "^6.0.1",
"rollup": "^4.28.1",
"shiki": "^1.24.2",
"rollup": "^4.29.1",
"shiki": "^1.24.4",
"simple-git-hooks": "^2.11.1",
"taze": "^0.16.9",
"typescript": "^5.7.2",
"unbuilder": "^0.0.19",
"unocss": "^0.62.4",
"unplugin-auto-import": "^0.18.6",
"unplugin-rpc": "^2.0.27",
"unplugin-rpc": "^2.0.30",
"unplugin-vue-components": "^0.27.5",
"unplugin-vue-macros": "^2.13.6",
"unplugin-vue-markdown": "^0.26.3",
Expand All @@ -110,7 +112,7 @@
"vite-ssg": "^0.23.8",
"vite-ssg-sitemap": "^0.8.1",
"vitest": "^2.1.8",
"vue-tsc": "^2.1.10"
"vue-tsc": "^2.2.0"
},
"resolutions": {
"@typescript-eslint/utils": "^8.2.0"
Expand Down
Loading

0 comments on commit a1a9f28

Please sign in to comment.