Skip to content

Commit

Permalink
fix: auth error
Browse files Browse the repository at this point in the history
  • Loading branch information
terwer committed Apr 22, 2024
1 parent 858c08c commit 9fdfe20
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 45 deletions.
1 change: 0 additions & 1 deletion composables/api/usePostApi.ts
Expand Up @@ -24,7 +24,6 @@
*/

import { createAppLogger } from "~/common/appLogger"
import { SiYuanApiAdaptor, SiyuanConfig } from "zhi-siyuan-api"
import { useSiyuanApi } from "~/composables/api/useSiyuanApi"

/**
Expand Down
4 changes: 1 addition & 3 deletions composables/useAuthModeFetch.ts
Expand Up @@ -38,9 +38,7 @@ export const useAuthModeFetch = () => {
const fetchPublicText = async (filename: string) => {
const shareTypeFetchFile = `/public/siyuan-blog/${filename}`
logger.info("getPublicFile in auth mode", shareTypeFetchFile)
const resText = await kernelApi.getPublicFile(shareTypeFetchFile)
logger.debug("get text from auth mode", resText)
return resText
return await kernelApi.getPublicFile(shareTypeFetchFile)
}

return { fetchPublicText }
Expand Down
5 changes: 2 additions & 3 deletions composables/useCommonShareType.ts
Expand Up @@ -30,7 +30,6 @@ import { createAppLogger } from "~/common/appLogger"
import { useSiyuanApi } from "~/composables/api/useSiyuanApi"
import { useAuthModeFetch } from "~/composables/useAuthModeFetch"
import { usePost } from "~/composables/usePost"
import { useRouteQuery } from "@vueuse/router"

export const useCommonShareType = () => {
const logger = createAppLogger("use-common-share-type")
Expand Down Expand Up @@ -64,8 +63,8 @@ export const useCommonShareType = () => {
if (isPreview) {
return ShareTypeEnum.ShareType_Public
}
} catch (e) {
logger.info("Not in inner, ignore")
} catch (e: any) {
logger.info("Not in inner, ignore =>", e.toString())
}
}

Expand Down
17 changes: 8 additions & 9 deletions composables/usePost.ts
Expand Up @@ -27,6 +27,7 @@ import { createAppLogger } from "~/common/appLogger"
import { Post } from "zhi-blog-api"
import { ObjectUtil } from "zhi-common"
import { usePostApi } from "~/composables/api/usePostApi"
import { SiyuanDevice } from "zhi-device"

/**
* 文档相关
Expand All @@ -44,6 +45,13 @@ export const usePost = () => {
* 如果缓存已有直接返回,否则去远程抓取数据
*/
const setCurrentPost = async (pageId?: string) => {
const win = SiyuanDevice.siyuanWindow()
if (!win.origin) {
throw new Error("server mode, ignore")
}
if (!win?.origin?.includes("127.0.0.1") && !win?.origin?.includes("localhost")) {
throw new Error("only local service is allowed for preview")
}
if (ObjectUtil.isEmptyObject(currentPost.post)) {
const route = useRoute()
const id = pageId ?? ((route.params.id ?? "") as string)
Expand All @@ -53,14 +61,5 @@ export const usePost = () => {
}
}

// lifecycles
// https://vuejs.org/api/composition-api-lifecycle.html#onserverprefetch
onServerPrefetch(async () => {
await setCurrentPost()
})
onBeforeMount(async () => {
await setCurrentPost()
})

return { currentPost, setCurrentPost }
}
36 changes: 8 additions & 28 deletions nuxt.config.ts
Expand Up @@ -9,7 +9,7 @@ const generateDynamicV = () => {
}

const isDev = process.env.NODE_ENV === "development"
const appBase = "/plugins/siyuan-blog/"
const appBase = "/"
const staticV = generateDynamicV()

// https://nuxt.com/docs/api/configuration/nuxt-config
Expand All @@ -28,14 +28,7 @@ export default defineNuxtConfig({
},

// build modules
modules: [
"@vueuse/nuxt",
"@nuxtjs/i18n-edge",
"@element-plus/nuxt",
"@nuxtjs/color-mode",
"@pinia/nuxt",
"@nuxt/image",
],
modules: ["@vueuse/nuxt", "@nuxtjs/i18n", "@element-plus/nuxt", "@nuxtjs/color-mode", "@pinia/nuxt", "@nuxt/image"],

// vueuse
vueuse: {
Expand All @@ -58,7 +51,7 @@ export default defineNuxtConfig({
define: {
"process.env.DEV_MODE": `"${isDev}"`,
"process.env.APP_BASE": `"${appBase}"`,
"process.env.SSR": `"false"`,
"process.env.SSR": `"true"`,
},
plugins: [],
},
Expand All @@ -69,14 +62,6 @@ export default defineNuxtConfig({
themes: ["dark"],
},

// https://nuxt.com/docs/guide/going-further/custom-routing#hash-mode-spa
ssr: false,
router: {
options: {
hashMode: true,
},
},

css: ["~/assets/siyuan/style.styl", "~/assets/siyuan/index.styl"],

app: {
Expand Down Expand Up @@ -113,17 +98,12 @@ export default defineNuxtConfig({

// 环境变量
runtimeConfig: {
// siyuanAuthToken: process.env.NUXT_SIYUAN_AUTH_TOKEN,
siyuanAuthToken: "",
// siyuanCookie: process.env.NUXT_SIYUAN_COOKIE,
siyuanCookie: "",
siyuanAuthToken: process.env.NUXT_SIYUAN_AUTH_TOKEN,
siyuanCookie: process.env.NUXT_SIYUAN_COOKIE,
public: {
// defaultType: process.env.NUXT_PUBLIC_DEFAULT_TYPE,
defaultType: "siyuan",
// siyuanApiUrl: process.env.NUXT_PUBLIC_SIYUAN_API_URL,
siyuanApiUrl: "",
// waitTime: process.env.NUXT_PUBLIC_WAIT_TIME,
waitTime: "0",
defaultType: process.env.NUXT_PUBLIC_DEFAULT_TYPE ?? "siyuan",
siyuanApiUrl: process.env.NUXT_PUBLIC_SIYUAN_API_URL ?? "http://127.0.0.1:6806",
waitTime: process.env.NUXT_PUBLIC_WAIT_TIME,
},
},
})
2 changes: 1 addition & 1 deletion public/libs/eruda/eruda.js

Large diffs are not rendered by default.

0 comments on commit 9fdfe20

Please sign in to comment.