Skip to content

Commit 7a95844

Browse files
committed
feat: add password feature release 🍰
1 parent 3604fa9 commit 7a95844

File tree

2 files changed

+33
-21
lines changed

2 files changed

+33
-21
lines changed

apps/app/components/static/Detail.vue

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -49,28 +49,36 @@ const formData = reactive({
4949
const getPostData = async () => {
5050
try {
5151
const resText = await fetchPostMeta(id, providerMode)
52+
const dataJson = JsonUtil.safeParse<any>(resText, {} as any)
53+
logger.debug("dataJson in providerMode=>", dataJson)
5254
if(providerMode){
53-
const dataJson = JsonUtil.safeParse<any>(resText, {} as any)
54-
logger.debug("dataJson in providerMode=>", dataJson)
55-
const currentPost = JsonUtil.safeParse<any>(dataJson.post, {} as any)
56-
currentPost.postid = id
57-
formData.post = currentPost
58-
logger.debug("currentPost in providerMode=>", currentPost)
5955
// 分享信息
6056
formData.shareOptions.passwordEnabled = dataJson.passwordEnabled ?? false
6157
formData.shareOptions.password = dataJson.password ?? ""
58+
formData.isShared = dataJson.isShared === true
59+
// 文档信息
60+
if(dataJson.post){
61+
const currentPost = JsonUtil.safeParse<any>(dataJson.post, {} as any)
62+
currentPost.postid = id
63+
formData.post = currentPost
64+
logger.debug("currentPost in providerMode=>", currentPost)
65+
const attrs = JsonUtil.safeParse<any>(formData.post?.attrs ?? "{}", {})
66+
formData.isExpires = checkExpires(attrs)
67+
}
6268
}else{
69+
// 文档信息
6370
const currentPost = JsonUtil.safeParse<any>(resText, {} as any)
6471
currentPost.postid = id
6572
formData.post = currentPost
6673
logger.debug("currentPost=>", currentPost)
74+
// 分享信息
75+
formData.isShared = !ObjectUtil.isEmptyObject(formData.post)
76+
const attrs = JsonUtil.safeParse<any>(formData.post?.attrs ?? "{}", {})
77+
formData.isExpires = checkExpires(attrs)
6778
}
68-
69-
formData.isShared = !ObjectUtil.isEmptyObject(formData.post)
70-
const attrs = JsonUtil.safeParse<any>(formData.post?.attrs ?? "{}", {})
71-
formData.isExpires = checkExpires(attrs)
7279
} catch (e) {
7380
formData.isShared = false
81+
logger.error("getPostData error=>", e)
7482
}
7583
}
7684
const getSetting = async () => {
@@ -109,16 +117,15 @@ const handlePasswordSubmit = async (password:string) => {
109117
logger.debug("get password:", password)
110118
logger.debug("db password:", formData.shareOptions.password)
111119
// 调用API验证密码
112-
const valid = await validatePassword(formData.post.postid, password, formData.shareOptions.password)
113-
// if (valid.flag) {
120+
const valid = await validatePassword(id, password, formData.shareOptions.password)
121+
if (valid.flag) {
114122
// 当前 url 参数还是 ?key
115123
const url = new URL(window.location.href);
116124
url.searchParams.set("key", valid.data);
117125
window.location.href = url.toString();
118-
119-
// } else {
120-
// ElMessage.error(t('share.password.confirm.password.rule.not.match'))
121-
// }
126+
} else {
127+
ElMessage.error(t('share.password.confirm.password.rule.not.match'))
128+
}
122129
}
123130
</script>
124131

apps/app/composables/useAuthModeFetch.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@
77
* of this license document, but changing it is not allowed.
88
*/
99

10-
import { JsonUtil, StrUtil } from "zhi-common"
11-
import { buildUrl } from "~/server/utils/urlUtils"
12-
import { useSiyuanSPA } from "~/composables/useSiyuanSPA"
10+
import {JsonUtil, StrUtil} from "zhi-common"
11+
import {buildUrl} from "~/server/utils/urlUtils"
12+
import {useSiyuanSPA} from "~/composables/useSiyuanSPA"
13+
import {useRoute} from "#vue-router";
1314

1415
export const useAuthModeFetch = () => {
1516
const logger = createAppLogger("use-config-fetch")
@@ -218,8 +219,12 @@ export const useAuthModeFetch = () => {
218219
const apiBase = env.public.providerUrl
219220
const url = "/api/share/getDoc"
220221
const reqUrl = `${apiBase}${url}`
221-
const params = {
222-
fdId: id,
222+
const { query } = useRoute()
223+
const params: any = {
224+
fdId: id
225+
}
226+
if(query.key){
227+
params.fdKey = query.key
223228
}
224229
let resText = "{}"
225230
try {

0 commit comments

Comments
 (0)