Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
c4464e1202 | |||
eca669d62a |
@ -2,14 +2,6 @@
|
|||||||
<html lang="zh-CN">
|
<html lang="zh-CN">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8" />
|
<meta charset="UTF-8" />
|
||||||
<title>AO3 Mirror</title>
|
|
||||||
<meta name="description" content="ArchiveOfOurOwn 镜像站, 使用 Vue 3 与 MDUI 2 重写界面, 优化 UI/UX" />
|
|
||||||
<meta name="author" content="UnknownMp" />
|
|
||||||
<meta property="og:title" content="AO3 Mirror">
|
|
||||||
<meta property="og:description" content="ArchiveOfOurOwn 镜像站">
|
|
||||||
<meta property="og:image" content="https://cdn.unknownmp.top/website/ao3mirror.svg">
|
|
||||||
<meta property="og:url" content="https://ao3.unknownmp.top">
|
|
||||||
<meta property="og:type" content="website">
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
<link rel="icon" type="image/svg" href="/favicon.svg" />
|
<link rel="icon" type="image/svg" href="/favicon.svg" />
|
||||||
<!--app-head-->
|
<!--app-head-->
|
||||||
|
163
server.js
163
server.js
@ -2,17 +2,15 @@ import fs from 'node:fs/promises'
|
|||||||
import express from 'express'
|
import express from 'express'
|
||||||
import cookieParser from 'cookie-parser'
|
import cookieParser from 'cookie-parser'
|
||||||
import { compress } from 'compress-json'
|
import { compress } from 'compress-json'
|
||||||
// Constants
|
|
||||||
const isProduction = process.env.NODE_ENV === 'production'
|
const isProduction = process.env.NODE_ENV === 'production'
|
||||||
const port = process.env.PORT || 5173
|
const port = process.env.PORT || 5173
|
||||||
const base = process.env.BASE || '/'
|
const base = process.env.BASE || '/'
|
||||||
|
|
||||||
// Cached production assets
|
|
||||||
const templateHtml = isProduction
|
const templateHtml = isProduction
|
||||||
? await fs.readFile('./dist/client/index.html', 'utf-8')
|
? await fs.readFile('./dist/client/index.html', 'utf-8')
|
||||||
: ''
|
: ''
|
||||||
|
|
||||||
// Create http server
|
|
||||||
const app = express()
|
const app = express()
|
||||||
app.use(cookieParser());
|
app.use(cookieParser());
|
||||||
|
|
||||||
@ -21,73 +19,110 @@ const MESSAGE = {
|
|||||||
0: 'Unknown'
|
0: 'Unknown'
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add Vite or respective production middlewares
|
|
||||||
/** @type {import('vite').ViteDevServer | undefined} */
|
|
||||||
let vite
|
let vite
|
||||||
if (!isProduction) {
|
if (!isProduction) {
|
||||||
const { createServer } = await import('vite')
|
const { createServer } = await import('vite')
|
||||||
vite = await createServer({
|
vite = await createServer({
|
||||||
server: { middlewareMode: true },
|
server: { middlewareMode: true },
|
||||||
appType: 'custom',
|
appType: 'custom',
|
||||||
base,
|
base,
|
||||||
})
|
})
|
||||||
app.use(vite.middlewares)
|
app.use(vite.middlewares)
|
||||||
} else {
|
} else {
|
||||||
//const compression = (await import('compression')).default
|
const sirv = (await import('sirv')).default
|
||||||
const sirv = (await import('sirv')).default
|
app.use(base, sirv('./dist/client', { extensions: [] }))
|
||||||
//app.use(compression())
|
|
||||||
app.use(base, sirv('./dist/client', { extensions: [] }))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Serve HTML
|
// Serve HTML
|
||||||
app.use('*all', async (req, res) => {
|
app.use('*all', async (req, res) => {
|
||||||
try {
|
try {
|
||||||
const url = req.originalUrl.replace(base, '')
|
const url = req.originalUrl.replace(base, '')
|
||||||
console.log(`Request ${url}`)
|
console.log(`Request ${url}`)
|
||||||
/** @type {string} */
|
let template
|
||||||
let template
|
let render, getRoute
|
||||||
/** @type {import('./src/entry-server.js').render} */
|
if (!isProduction) {
|
||||||
let render, getRoute
|
// Always read fresh template in development
|
||||||
if (!isProduction) {
|
template = await fs.readFile('./index.html', 'utf-8')
|
||||||
// Always read fresh template in development
|
template = await vite.transformIndexHtml(url, template)
|
||||||
template = await fs.readFile('./index.html', 'utf-8')
|
const module = await vite.ssrLoadModule('/src/entry-server.js')
|
||||||
template = await vite.transformIndexHtml(url, template)
|
render = module.render
|
||||||
const module = await vite.ssrLoadModule('/src/entry-server.js')
|
getRoute = module.getRoute
|
||||||
render = module.render
|
} else {
|
||||||
getRoute = module.getRoute
|
template = templateHtml
|
||||||
} else {
|
const module = await import('./dist/server/entry-server.js')
|
||||||
template = templateHtml
|
render = module.render
|
||||||
const module = await import('./dist/server/entry-server.js')
|
getRoute = module.getRoute
|
||||||
render = module.render
|
}
|
||||||
getRoute = module.getRoute
|
const { router, code, title, metas, meta } = await getRoute(url)
|
||||||
}
|
if (code != 200 && !req.accepts('html')) {
|
||||||
const { router, code } = await getRoute(url)
|
res.status(code).set({ 'Content-Type': 'text/plain' })
|
||||||
if (code != 200 && !req.accepts('html')) {
|
res.write(MESSAGE[code] || MESSAGE[0])
|
||||||
res.status(code).set({ 'Content-Type': 'text/plain' })
|
res.end()
|
||||||
res.write(MESSAGE[code] || MESSAGE[0])
|
return
|
||||||
res.end()
|
}
|
||||||
return
|
const { stream, piniaState, headState } = await render(router, req.cookies, req.headers.host)
|
||||||
}
|
const [htmlStart, htmlEnd] = template.split('<!--app-html-->')
|
||||||
const { stream, piniaState } = await render(router, req.cookies, req.headers.host)
|
if (meta) {
|
||||||
const [htmlStart, htmlEnd] = template.split('<!--app-html-->')
|
const buffer = []
|
||||||
res.status(code).set({ 'Content-Type': 'text/html' })
|
let headReady = false
|
||||||
res.write(htmlStart)
|
for await (const chunk of stream) {
|
||||||
for await (const chunk of stream) {
|
if (res.closed) break
|
||||||
if (res.closed) break
|
if (headReady) res.write(chunk)
|
||||||
res.write(chunk)
|
else {
|
||||||
}
|
if (headState.ready) {
|
||||||
const piniaStateContent = JSON.stringify(compress(piniaState))
|
res.status(headState.code || code).set({ 'Content-Type': 'text/html' })
|
||||||
const stateScript = `<script>window.__PINIA_STATE__=${piniaStateContent}</script>`
|
const heads = [`<title>${ headState.title || title }</title>`]
|
||||||
res.write(htmlEnd.replace('<!--app-state-->', stateScript))
|
for (const item of [ ...metas, ...headState.meta ]) {
|
||||||
res.end()
|
const properties = []
|
||||||
} catch (e) {
|
for (const [key, value] of Object.entries(item)) properties.push(`${key}="${value}"`)
|
||||||
vite?.ssrFixStacktrace(e)
|
heads.push(`<meta ${properties.join(' ')}>`)
|
||||||
console.log(e.stack)
|
}
|
||||||
res.status(500).end(e.stack)
|
res.write(htmlStart.replace('<!--app-head-->',heads.join('')))
|
||||||
}
|
for (const item of buffer) res.write(item)
|
||||||
|
res.write(chunk)
|
||||||
|
headReady = true
|
||||||
|
} else buffer.push(chunk)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!headState.ready) {
|
||||||
|
console.warn('Page not set meta ready! No stream render at all!')
|
||||||
|
const heads = [`<title>${ title }</title>`]
|
||||||
|
for (const item of metas) {
|
||||||
|
const properties = []
|
||||||
|
for (const [key, value] of Object.entries(item)) properties.push(`${key}="${value}"`)
|
||||||
|
heads.push(`<meta ${properties.join(' ')}>`)
|
||||||
|
}
|
||||||
|
res.write(htmlStart.replace('<!--app-head-->',heads.join('')))
|
||||||
|
for await (const chunk of buffer) {
|
||||||
|
if (res.closed) break
|
||||||
|
res.write(chunk)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
res.status(code).set({ 'Content-Type': 'text/html' })
|
||||||
|
const heads = [`<title>${ title }</title>`]
|
||||||
|
for (const item of metas) {
|
||||||
|
const properties = []
|
||||||
|
for (const [key, value] of Object.entries(item)) properties.push(`${key}="${value}"`)
|
||||||
|
heads.push(`<meta ${properties.join(' ')}>`)
|
||||||
|
}
|
||||||
|
res.write(htmlStart.replace('<!--app-head-->',heads.join('')))
|
||||||
|
for await (const chunk of stream) {
|
||||||
|
if (res.closed) break
|
||||||
|
res.write(chunk)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const piniaStateContent = JSON.stringify(compress(piniaState))
|
||||||
|
const stateScript = `<script>window.__PINIA_STATE__=${piniaStateContent}</script>`
|
||||||
|
res.write(htmlEnd.replace('<!--app-state-->', stateScript))
|
||||||
|
res.end()
|
||||||
|
} catch (e) {
|
||||||
|
vite?.ssrFixStacktrace(e)
|
||||||
|
console.log(e.stack)
|
||||||
|
res.status(500).end(e.stack)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
// Start http server
|
|
||||||
app.listen(port, () => {
|
app.listen(port, () => {
|
||||||
console.log(`Server started at http://localhost:${port}`)
|
console.log(`Server started at port ${port}`)
|
||||||
})
|
})
|
||||||
|
@ -20,9 +20,7 @@ function replaceUrl(url) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function useApiRequest(method, url, data, config = {}) {
|
export function useApiRequest(method, url, data, config = {}) {
|
||||||
const start = Date.now()
|
|
||||||
const baseURL = getEndpoint()
|
const baseURL = getEndpoint()
|
||||||
// 若为 GET 请求,将 data 转为查询参数拼接到 URL 上
|
|
||||||
const fullURL = method === 'GET' && data
|
const fullURL = method === 'GET' && data
|
||||||
? `${baseURL}${url}?${objectToQueryString(data)}`
|
? `${baseURL}${url}?${objectToQueryString(data)}`
|
||||||
: `${baseURL}${url}`
|
: `${baseURL}${url}`
|
||||||
@ -45,14 +43,14 @@ export function useApiRequest(method, url, data, config = {}) {
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
const exec = async () => {
|
const exec = async () => {
|
||||||
await execute()
|
const start = Date.now()
|
||||||
|
try { await execute() }
|
||||||
|
catch (e) {}
|
||||||
const stop = Date.now()
|
const stop = Date.now()
|
||||||
return {
|
return {
|
||||||
status: response.value?.status || (error.value?.response?.status ?? -1),
|
status: response.value?.status || (error.value?.response?.status ?? -1),
|
||||||
data: response.value?.data || error.value?.response?.data || null,
|
data: response.value?.data || error.value?.response?.data || null,
|
||||||
duration: stop - start,
|
duration: stop - start,
|
||||||
start,
|
|
||||||
stop,
|
|
||||||
error: error.value,
|
error: error.value,
|
||||||
isSSR: import.meta.env.SSR,
|
isSSR: import.meta.env.SSR,
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { renderToWebStream } from 'vue/server-renderer'
|
import { renderToWebStream } from 'vue/server-renderer'
|
||||||
import { createApp } from './main'
|
import { createApp } from './main'
|
||||||
|
|
||||||
import { createSSRRouter } from './router.js'
|
import { createSSRRouter, defaultHead } from './router.js'
|
||||||
|
|
||||||
export async function getRoute(_url) {
|
export async function getRoute(_url) {
|
||||||
const router = createSSRRouter()
|
const router = createSSRRouter()
|
||||||
@ -9,15 +9,24 @@ export async function getRoute(_url) {
|
|||||||
await router.isReady()
|
await router.isReady()
|
||||||
const route = router.currentRoute.value.matched[0]
|
const route = router.currentRoute.value.matched[0]
|
||||||
const code = route.meta.code || 200
|
const code = route.meta.code || 200
|
||||||
return { router, code }
|
return { router, code, meta: route.meta.meta || false,
|
||||||
|
title: route.meta.title || route.meta.name || defaultHead.title,
|
||||||
|
metas: [...defaultHead.meta, ...route.meta.metas || []]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function render(router, cookies, host) {
|
export async function render(router, cookies, host) {
|
||||||
const { app, pinia } = createApp()
|
const { app, pinia } = createApp()
|
||||||
app.use(router)
|
app.use(router)
|
||||||
const ctx = { cookies, host }
|
const headState = {
|
||||||
|
ready: false,
|
||||||
|
code: null,
|
||||||
|
title: null,
|
||||||
|
meta: []
|
||||||
|
}
|
||||||
|
const ctx = { cookies, host, headState }
|
||||||
const stream = renderToWebStream(app, ctx)
|
const stream = renderToWebStream(app, ctx)
|
||||||
const piniaState = pinia.state.value
|
const piniaState = pinia.state.value
|
||||||
return { stream, piniaState }
|
return { stream, piniaState, headState }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,25 @@
|
|||||||
import { createMemoryHistory, createWebHistory, createRouter } from 'vue-router'
|
import { createMemoryHistory, createWebHistory, createRouter } from 'vue-router'
|
||||||
|
|
||||||
|
export const defaultHead = {
|
||||||
|
title: 'AO3 Mirror',
|
||||||
|
meta: [
|
||||||
|
{ name: 'description',
|
||||||
|
content: 'ArchiveOfOurOwn 镜像站, 使用 Vue 3 与 MDUI 2 重写界面, 优化 UI/UX' },
|
||||||
|
{ name: 'author',
|
||||||
|
content: 'UnknownMp' },
|
||||||
|
{ property: 'og:title',
|
||||||
|
content: 'AO3 Mirror' },
|
||||||
|
{ property: 'og:description',
|
||||||
|
content: 'ArchiveOfOurOwn 重构镜像' },
|
||||||
|
{ property: 'og:image',
|
||||||
|
content: 'https://cdn.unknownmp.top/website/ao3mirror.svg' },
|
||||||
|
{ property: 'og:url',
|
||||||
|
content: 'https://ao3.unknownmp.top' },
|
||||||
|
{ property: 'og:type',
|
||||||
|
content: 'website' },
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
export const createSSRRouter = () => createRouter({
|
export const createSSRRouter = () => createRouter({
|
||||||
history: import.meta.env.SSR ? createMemoryHistory() : createWebHistory(),
|
history: import.meta.env.SSR ? createMemoryHistory() : createWebHistory(),
|
||||||
scrollBehavior(to, from, savedPosition) {
|
scrollBehavior(to, from, savedPosition) {
|
||||||
@ -25,7 +45,8 @@ export const createSSRRouter = () => createRouter({
|
|||||||
component: () => import('./views/Work.vue'),
|
component: () => import('./views/Work.vue'),
|
||||||
meta: {
|
meta: {
|
||||||
title: '阅读',
|
title: '阅读',
|
||||||
hidden: true
|
hidden: true,
|
||||||
|
meta: true
|
||||||
}
|
}
|
||||||
},{
|
},{
|
||||||
path: '/work/:id/:cid',
|
path: '/work/:id/:cid',
|
||||||
@ -33,7 +54,8 @@ export const createSSRRouter = () => createRouter({
|
|||||||
component: () => import('./views/Work.vue'),
|
component: () => import('./views/Work.vue'),
|
||||||
meta: {
|
meta: {
|
||||||
title: '阅读',
|
title: '阅读',
|
||||||
hidden: true
|
hidden: true,
|
||||||
|
meta: true
|
||||||
}
|
}
|
||||||
},{
|
},{
|
||||||
path: '/search/simple',
|
path: '/search/simple',
|
||||||
@ -48,7 +70,6 @@ export const createSSRRouter = () => createRouter({
|
|||||||
name: '设置',
|
name: '设置',
|
||||||
component: () => import('./views/Settings.vue'),
|
component: () => import('./views/Settings.vue'),
|
||||||
meta: {
|
meta: {
|
||||||
title: '设置',
|
|
||||||
order: 90
|
order: 90
|
||||||
},
|
},
|
||||||
},{
|
},{
|
||||||
@ -56,7 +77,6 @@ export const createSSRRouter = () => createRouter({
|
|||||||
name: '关于',
|
name: '关于',
|
||||||
component: () => import('./views/About.md'),
|
component: () => import('./views/About.md'),
|
||||||
meta: {
|
meta: {
|
||||||
title: '',
|
|
||||||
order: 100
|
order: 100
|
||||||
},
|
},
|
||||||
},{
|
},{
|
||||||
@ -64,7 +84,6 @@ export const createSSRRouter = () => createRouter({
|
|||||||
name: '开发人员选项',
|
name: '开发人员选项',
|
||||||
component: () => import('./views/Developer.vue'),
|
component: () => import('./views/Developer.vue'),
|
||||||
meta: {
|
meta: {
|
||||||
title: '',
|
|
||||||
hidden: true
|
hidden: true
|
||||||
},
|
},
|
||||||
},{
|
},{
|
||||||
|
47
src/ssr/headHelper.js
Normal file
47
src/ssr/headHelper.js
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
import { useSSRContext } from 'vue'
|
||||||
|
|
||||||
|
export function useHeadHelper() {
|
||||||
|
if (!import.meta.env.SSR) {
|
||||||
|
return {
|
||||||
|
headReady: () => {},
|
||||||
|
setMeta: () => {},
|
||||||
|
addMeta: () => {},
|
||||||
|
setTitle: () => {},
|
||||||
|
setCode: () => {},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const ssrContext = useSSRContext()
|
||||||
|
|
||||||
|
if (!ssrContext || !ssrContext.headState) {
|
||||||
|
return {
|
||||||
|
headReady: () => {},
|
||||||
|
setMeta: () => {},
|
||||||
|
addMeta: () => {},
|
||||||
|
setTitle: () => {},
|
||||||
|
setCode: () => {},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
headReady: () => {
|
||||||
|
ssrContext.headState.ready = true
|
||||||
|
},
|
||||||
|
setMeta: (metas = []) => {
|
||||||
|
ssrContext.headState.meta = [
|
||||||
|
...ssrContext.headState.meta,
|
||||||
|
...metas
|
||||||
|
]
|
||||||
|
},
|
||||||
|
addMeta: (meta) => {
|
||||||
|
ssrContext.headState.meta.push(meta)
|
||||||
|
},
|
||||||
|
setTitle: (title) => {
|
||||||
|
ssrContext.headState.title = title
|
||||||
|
},
|
||||||
|
setCode: (code) => {
|
||||||
|
ssrContext.headState.code = code
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -2,6 +2,8 @@ import { ref, computed, watch } from 'vue'
|
|||||||
import { defineStore } from 'pinia'
|
import { defineStore } from 'pinia'
|
||||||
import { useRouter, useRoute } from 'vue-router'
|
import { useRouter, useRoute } from 'vue-router'
|
||||||
|
|
||||||
|
import { useHeadHelper } from '../ssr/headHelper.js'
|
||||||
|
|
||||||
export const useRouteStore = defineStore('route', () => {
|
export const useRouteStore = defineStore('route', () => {
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const route = useRoute()
|
const route = useRoute()
|
||||||
@ -16,7 +18,9 @@ export const useRouteStore = defineStore('route', () => {
|
|||||||
)
|
)
|
||||||
const lastFromDrawer = ref(0)
|
const lastFromDrawer = ref(0)
|
||||||
const customTitle = ref(null)
|
const customTitle = ref(null)
|
||||||
const title = computed(() => customTitle.value || route.meta.title || route.name)
|
const title = import.meta.env.SSR ?
|
||||||
|
computed(() => route.meta.title || route.name) :
|
||||||
|
computed(() => customTitle.value || route.meta.title || route.name)
|
||||||
function drawerPress(target) {
|
function drawerPress(target) {
|
||||||
if (lastFromDrawer.value == 0) {
|
if (lastFromDrawer.value == 0) {
|
||||||
lastFromDrawer.value = 1
|
lastFromDrawer.value = 1
|
||||||
|
@ -15,6 +15,8 @@ export const useWorkReadState = defineStore('workRead', () => {
|
|||||||
const text = ref(null)
|
const text = ref(null)
|
||||||
const state = ref('')
|
const state = ref('')
|
||||||
const publishedTime = ref(null)
|
const publishedTime = ref(null)
|
||||||
|
const completedTime = ref(null)
|
||||||
|
const updatedTime = ref(null)
|
||||||
const wordCount = ref(0)
|
const wordCount = ref(0)
|
||||||
const kudoCount = ref(0)
|
const kudoCount = ref(0)
|
||||||
const hitCount = ref(0)
|
const hitCount = ref(0)
|
||||||
@ -32,6 +34,8 @@ export const useWorkReadState = defineStore('workRead', () => {
|
|||||||
pseud.value = data.pseud
|
pseud.value = data.pseud
|
||||||
text.value = data.text
|
text.value = data.text
|
||||||
publishedTime.value = data.stats.publishedTime
|
publishedTime.value = data.stats.publishedTime
|
||||||
|
completedTime.value = data.stats.completedTime
|
||||||
|
updatedTime.value = data.stats.updatedTime
|
||||||
wordCount.value = data.stats.wordCount
|
wordCount.value = data.stats.wordCount
|
||||||
kudoCount.value = data.stats.kudoCount
|
kudoCount.value = data.stats.kudoCount
|
||||||
hitCount.value = data.stats.hitCount
|
hitCount.value = data.stats.hitCount
|
||||||
@ -62,29 +66,24 @@ export const useWorkReadState = defineStore('workRead', () => {
|
|||||||
if (result.status == 200) {
|
if (result.status == 200) {
|
||||||
setData(result.data)
|
setData(result.data)
|
||||||
state.value = 'ready'
|
state.value = 'ready'
|
||||||
} else {
|
} else if (result.status == 404) {
|
||||||
id.value = target
|
|
||||||
state.value = import.meta.env.SSR ? 'ssrnotfound' : 'notfound'
|
state.value = import.meta.env.SSR ? 'ssrnotfound' : 'notfound'
|
||||||
|
} else if (result.status == 401) {
|
||||||
|
state.value = 'unauth'
|
||||||
|
} else if (result.status == 500) {
|
||||||
|
state.value = 'error'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
id, cid,
|
id, cid,
|
||||||
title,
|
title, summary,
|
||||||
summary,
|
pseud, text, state,
|
||||||
pseud,
|
|
||||||
text,
|
|
||||||
state,
|
|
||||||
publishedTime,
|
publishedTime,
|
||||||
wordCount,
|
completedTime,
|
||||||
kudoCount,
|
updatedTime,
|
||||||
hitCount,
|
wordCount, kudoCount, hitCount,
|
||||||
category,
|
category, fandom, lang,
|
||||||
fandom,
|
chapters, chapterIndex, chapterStat,
|
||||||
lang,
|
setData, loadWork
|
||||||
chapters,
|
|
||||||
chapterIndex,
|
|
||||||
chapterStat,
|
|
||||||
setData,
|
|
||||||
loadWork
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -21,9 +21,10 @@ onUnmounted(() => console.log('Unmounted'))*/
|
|||||||
---
|
---
|
||||||
一个 AO3 镜像站, 优化了 UI/UX
|
一个 AO3 镜像站, 优化了 UI/UX
|
||||||
|
|
||||||
作者 (1)
|
作者 {#contact}
|
||||||
---
|
---
|
||||||
- [UnknownMp](https://www.unknownmp.top)
|
- [UnknownMp](https://www.unknownmp.top)
|
||||||
|
邮件: unknownmp@unknownmp.top
|
||||||
<mdui-avatar src="https://cdn.unknownmp.top/website/logo.jpg"></mdui-avatar>
|
<mdui-avatar src="https://cdn.unknownmp.top/website/logo.jpg"></mdui-avatar>
|
||||||
|
|
||||||
---
|
---
|
||||||
|
@ -4,6 +4,8 @@ import { useRouter, useRoute } from 'vue-router'
|
|||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const route = useRoute()
|
const route = useRoute()
|
||||||
|
|
||||||
|
import { useHeadHelper } from '../ssr/headHelper.js'
|
||||||
|
|
||||||
import { useWorkReadState } from '@/stores/workRead.js'
|
import { useWorkReadState } from '@/stores/workRead.js'
|
||||||
import { useRouteStore } from '@/stores/route.js'
|
import { useRouteStore } from '@/stores/route.js'
|
||||||
|
|
||||||
@ -43,11 +45,23 @@ const categoryName = {
|
|||||||
fm: '女/男'
|
fm: '女/男'
|
||||||
}
|
}
|
||||||
|
|
||||||
onServerPrefetch(async () => await workReadState.loadWork(route.params.id, route.params.cid))
|
onServerPrefetch(async () => {
|
||||||
|
const headHelper = useHeadHelper()
|
||||||
|
await workReadState.loadWork(route.params.id, route.params.cid)
|
||||||
|
if (workReadState.state == 'ready') headHelper.setTitle(workReadState.title)
|
||||||
|
else if (workReadState.state == 'ssrnotfound') {
|
||||||
|
headHelper.setTitle('文章未找到')
|
||||||
|
headHelper.setCode(404)
|
||||||
|
} else if (workReadState.state == 'unauth') {
|
||||||
|
headHelper.setTitle('访问被阻止')
|
||||||
|
headHelper.setCode(401)
|
||||||
|
}
|
||||||
|
headHelper.headReady()
|
||||||
|
})
|
||||||
|
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
watch(() => workReadState.state, (value) => { if (value == 'ready') routeState.customTitle = workReadState.title })
|
watch(() => workReadState.state, (value) => { if (value == 'ready') routeState.customTitle = workReadState.title })
|
||||||
if (workReadState.state != 'ssrnotfound') await workReadState.loadWork(route.params.id, route.params.cid)
|
if (workReadState.state != 'ssrnotfound' && workReadState.state != 'ready') await workReadState.loadWork(route.params.id, route.params.cid)
|
||||||
if (workReadState.state == 'ready') {
|
if (workReadState.state == 'ready') {
|
||||||
routeState.customTitle = workReadState.title
|
routeState.customTitle = workReadState.title
|
||||||
if (workReadState.cid !== null && parseInt(route.params.cid) != workReadState.cid) {
|
if (workReadState.cid !== null && parseInt(route.params.cid) != workReadState.cid) {
|
||||||
@ -94,33 +108,49 @@ async function switchWorkWithIndex(target) {
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<ClientOnly>
|
<template v-if="workReadState.state == 'notfound' || workReadState.state == 'ssrnotfound'">
|
||||||
|
<h2>文章不存在...</h2>
|
||||||
|
是不是链接没有复制完全?<br/>
|
||||||
|
ID: {{ workReadState.id }}<br/>
|
||||||
|
<template v-if="workReadState.cid">
|
||||||
|
CID: {{ workReadState.cid }}
|
||||||
|
</template>
|
||||||
|
<a @click="$router.back()">返回</a>
|
||||||
|
</template><template v-if="workReadState.state == 'unauth'">
|
||||||
|
<h2>访问被阻止!</h2>
|
||||||
|
上游 AO3 不允许匿名用户访问该作品<br/>
|
||||||
|
ID: {{workReadState.id}}<br/>
|
||||||
|
<template v-if="workReadState.cid">
|
||||||
|
CID: {{ workReadState.cid }}
|
||||||
|
</template><br/>
|
||||||
|
<a @click="$router.back()">返回</a>
|
||||||
|
</template><template v-if="workReadState.state == 'error'">
|
||||||
|
<h2>内部服务器错误</h2>
|
||||||
|
这种情况不是你的问题, 而是我给网站写的屎山代码发力了, 在 <a href="/about#contact">这里</a> 联系我修复此问题<br/>
|
||||||
|
并提供以下信息:<br/>
|
||||||
|
ID: {{workReadState.id}}<br/>
|
||||||
|
<template v-if="workReadState.cid">
|
||||||
|
CID: {{ workReadState.cid }}
|
||||||
|
</template><br/>
|
||||||
|
<a @click="$router.back()">返回</a>
|
||||||
|
</template><template v-if="workReadState.state == 'errformat'">
|
||||||
|
<h2>路径格式错误</h2>
|
||||||
|
ID: {{ $route.params.id }}<br/>
|
||||||
|
<template v-if="$route.params.id">
|
||||||
|
CID: {{ $route.params.id }}
|
||||||
|
</template><br/>
|
||||||
|
<a @click="$router.back()">返回</a>
|
||||||
|
</template><ClientOnly>
|
||||||
<template v-if="workReadState.state == 'loading'">
|
<template v-if="workReadState.state == 'loading'">
|
||||||
加载中...<br/>
|
加载中...<br/>
|
||||||
<mdui-linear-progress></mdui-linear-progress>
|
<mdui-linear-progress></mdui-linear-progress>
|
||||||
</template>
|
</template>
|
||||||
<template v-if="workReadState.state == 'notfound' || workReadState.state == 'ssrnotfound'">
|
|
||||||
<h2>文章不存在...</h2>
|
|
||||||
是不是链接没有复制完全?<br/>
|
|
||||||
ID: {{ workReadState.id }}<br/>
|
|
||||||
<template v-if="workReadState.cid">
|
|
||||||
CID: {{ workReadState.cid }}
|
|
||||||
</template>
|
|
||||||
<a @click="$router.back()">返回</a>
|
|
||||||
</template>
|
|
||||||
<template v-if="workReadState.state == 'errformat'">
|
|
||||||
<h2>路径格式错误</h2>
|
|
||||||
ID: {{ $route.params.id }}<br/>
|
|
||||||
<template v-if="$route.params.id">
|
|
||||||
CID: {{ $route.params.id }}
|
|
||||||
</template><br/>
|
|
||||||
<a @click="$router.back()">返回</a>
|
|
||||||
</template>
|
|
||||||
<template v-if="workReadState.state == 'ready'">
|
<template v-if="workReadState.state == 'ready'">
|
||||||
<article>
|
<article>
|
||||||
<h1 style="margin: auto">{{ workReadState.title }}</h1>
|
<h1>{{ workReadState.title }}</h1>
|
||||||
<h4>{{ workReadState.pesud }}</h4>
|
<h4>{{ workReadState.pseud }}</h4>
|
||||||
<mdui-card style="margin: 8px; padding: 16px;">
|
<a target="_blank" :href="workReadState.cid ? `https://archiveofourown.org/works/${workReadState.id}/chapters/${workReadState.cid}` : `https://archiveofourown.org/works/${workReadState.id}`">原 AO3 链接</a>
|
||||||
|
<mdui-card style="margin: 8px 0px; padding: 16px;">
|
||||||
<strong>作品信息</strong><dl>
|
<strong>作品信息</strong><dl>
|
||||||
<template v-if="workReadState.category"><dt>分类</dt><ul>
|
<template v-if="workReadState.category"><dt>分类</dt><ul>
|
||||||
<li v-for="item in workReadState.category" :key="item">
|
<li v-for="item in workReadState.category" :key="item">
|
||||||
@ -130,16 +160,30 @@ async function switchWorkWithIndex(target) {
|
|||||||
<li v-for="item in workReadState.fandom" :key="item">
|
<li v-for="item in workReadState.fandom" :key="item">
|
||||||
{{ item }}</li>
|
{{ item }}</li>
|
||||||
</ul></template>
|
</ul></template>
|
||||||
|
<template v-if="workReadState.additionalTags"><dt>附加 Tag</dt><ul>
|
||||||
|
<li v-for="item in workReadState.additionalTags" :key="item">
|
||||||
|
{{ item }}</li>
|
||||||
|
</ul></template>
|
||||||
<dt>语言</dt><dd>
|
<dt>语言</dt><dd>
|
||||||
{{ workReadState.lang }}
|
{{ workReadState.lang }}
|
||||||
</dd>
|
</dd>
|
||||||
</dl><Hr/>
|
</dl><Hr/>
|
||||||
<strong>作品状态</strong><dl>
|
<strong>作品状态</strong><dl>
|
||||||
<dt>发布时间</dt><dd>
|
<dt>发布</dt><dd>
|
||||||
{{ workReadState.publishedTime.year }} -
|
{{ workReadState.publishedTime.year }} -
|
||||||
{{ workReadState.publishedTime.month }} -
|
{{ workReadState.publishedTime.month }} -
|
||||||
{{ workReadState.publishedTime.date }}
|
{{ workReadState.publishedTime.date }}
|
||||||
</dd>
|
</dd>
|
||||||
|
<template v-if="workReadState.completedTime"><dt>完成</dt><dd>
|
||||||
|
{{ workReadState.completedTime.year }} -
|
||||||
|
{{ workReadState.completedTime.month }} -
|
||||||
|
{{ workReadState.completedTime.date }}
|
||||||
|
</dd></template>
|
||||||
|
<template v-if="workReadState.updatedTime"><dt>更新</dt><dd>
|
||||||
|
{{ workReadState.updatedTime.year }} -
|
||||||
|
{{ workReadState.updatedTime.month }} -
|
||||||
|
{{ workReadState.updatedTime.date }}
|
||||||
|
</dd></template>
|
||||||
<dt>字数</dt><dd>
|
<dt>字数</dt><dd>
|
||||||
{{ workReadState.wordCount }}
|
{{ workReadState.wordCount }}
|
||||||
</dd>
|
</dd>
|
||||||
@ -198,18 +242,9 @@ async function switchWorkWithIndex(target) {
|
|||||||
</mdui-dialog>
|
</mdui-dialog>
|
||||||
</template>
|
</template>
|
||||||
<template #ssr>
|
<template #ssr>
|
||||||
<template v-if="workReadState.state == 'notfound' || workReadState.state == 'ssrnotfound'">
|
|
||||||
<h2>文章不存在...</h2>
|
|
||||||
是不是链接没有复制完全?<br/>
|
|
||||||
ID: {{workReadState.id}}<br/>
|
|
||||||
<template v-if="workReadState.cid">
|
|
||||||
CID: {{ workReadState.cid }}
|
|
||||||
</template>
|
|
||||||
<a @click="$router.back()">返回</a>
|
|
||||||
</template>
|
|
||||||
<template v-if="workReadState.state == 'ready'">
|
<template v-if="workReadState.state == 'ready'">
|
||||||
<h2>{{ workReadState.title }}</h2>
|
<h2>{{ workReadState.title }}</h2>
|
||||||
<h4>{{ workReadState.pesud }}</h4>
|
<h4>{{ workReadState.pseud }}</h4>
|
||||||
<dl>
|
<dl>
|
||||||
<template v-if="workReadState.category"><dt>分类</dt><ul>
|
<template v-if="workReadState.category"><dt>分类</dt><ul>
|
||||||
<li v-for="item in workReadState.category" :key="item">
|
<li v-for="item in workReadState.category" :key="item">
|
||||||
@ -222,11 +257,21 @@ async function switchWorkWithIndex(target) {
|
|||||||
<dt>语言</dt><dd>
|
<dt>语言</dt><dd>
|
||||||
{{ workReadState.lang }}
|
{{ workReadState.lang }}
|
||||||
</dd>
|
</dd>
|
||||||
<dt>发布时间</dt><dd>
|
<dt>发布</dt><dd>
|
||||||
{{ workReadState.publishedTime.year }} -
|
{{ workReadState.publishedTime.year }} -
|
||||||
{{ workReadState.publishedTime.month }} -
|
{{ workReadState.publishedTime.month }} -
|
||||||
{{ workReadState.publishedTime.date }}
|
{{ workReadState.publishedTime.date }}
|
||||||
</dd>
|
</dd>
|
||||||
|
<template v-if="workReadState.completedTime"><dt>完成</dt><dd>
|
||||||
|
{{ workReadState.completedTime.year }} -
|
||||||
|
{{ workReadState.completedTime.month }} -
|
||||||
|
{{ workReadState.completedTime.date }}
|
||||||
|
</dd></template>
|
||||||
|
<template v-if="workReadState.updatedTime"><dt>更新</dt><dd>
|
||||||
|
{{ workReadState.updatedTime.year }} -
|
||||||
|
{{ workReadState.updatedTime.month }} -
|
||||||
|
{{ workReadState.updatedTime.date }}
|
||||||
|
</dd></template>
|
||||||
<dt>字数</dt><dd>
|
<dt>字数</dt><dd>
|
||||||
{{ workReadState.wordCount }}
|
{{ workReadState.wordCount }}
|
||||||
</dd>
|
</dd>
|
||||||
|
Reference in New Issue
Block a user