Skip to content
This repository was archived by the owner on Nov 2, 2024. It is now read-only.

Commit b90d196

Browse files
authored
docs(themes/Shiro): provide links instead of hard-coded code (#54)
1 parent fb06590 commit b90d196

File tree

1 file changed

+6
-48
lines changed

1 file changed

+6
-48
lines changed

pages/themes/shiro/extra.mdx

+6-48
Original file line numberDiff line numberDiff line change
@@ -34,58 +34,16 @@ import { Callout, Steps } from 'nextra/components'
3434
**密钥在后面的步骤中还需要用到,所以请务必记住。**
3535
</Callout>
3636

37-
上方没有提到的选项都不需要填写,然后在右侧的代码编辑器中填入以下代码:
38-
39-
```js
40-
export default async function handler(ctx: Context) {
41-
const { timestamp, process, key, media } = ctx.req.body || {}
42-
43-
const [processName, mediaInfo] = await Promise.all([
44-
ctx.storage.cache.get('ps'),
45-
ctx.storage.cache.get('media').then((JSONString) => {
46-
if (JSONString) {
47-
try {
48-
return JSON.parse(JSONString)
49-
} catch {
50-
return undefined
51-
}
52-
}
53-
}),
54-
])
55-
56-
if (!key) {
57-
return {
58-
processName,
59-
mediaInfo,
60-
}
61-
}
37+
上方没有提到的选项都不需要填写,然后在右侧的代码编辑器中填入下面链接中的代码:
6238

63-
const validKey = (await ctx.secret.key) || 'testing'
64-
if (key != validKey)
65-
ctx.throws(401, "You haven't permission to update process info")
66-
await ctx.storage.cache.set('ps', process, 60)
67-
const ts = +new Date()
68-
69-
if (process !== processName)
70-
ctx.broadcast('ps-update', {
71-
process,
72-
ts,
73-
})
74-
if (media) {
75-
await ctx.storage.cache.set('media', JSON.stringify(media), 10)
76-
77-
if (mediaInfo.title !== media.title) ctx.broadcast('media-update', media)
78-
}
79-
return {
80-
ok: 1,
81-
process,
82-
timestamp: +new Date(),
83-
}
84-
}
85-
```
39+
<ToGitHub repo="https://github.com/mx-space/snippets/blob/main/shiro/functions/ps.ts" />
8640

8741
点击保存按钮,云函数就配置完成了。
8842

43+
<Callout type="info">
44+
请关注此代码的更新,它可能会随时变化,你需要及时更新它们
45+
</Callout>
46+
8947
### 配置主题配置
9048

9149
继续在「配置与云函数」页面,找到「theme -> shiro」配置,点击编辑,进入编辑页面,在代码中找到 `module`,加入 activity 配置,如下:(高亮部分)

0 commit comments

Comments
 (0)