Skip to content

Commit

Permalink
docs(themes/Shiro): provide links instead of hard-coded code (#54)
Browse files Browse the repository at this point in the history
  • Loading branch information
wibus-wee authored Feb 16, 2024
1 parent fb06590 commit b90d196
Showing 1 changed file with 6 additions and 48 deletions.
54 changes: 6 additions & 48 deletions pages/themes/shiro/extra.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -34,58 +34,16 @@ import { Callout, Steps } from 'nextra/components'
**密钥在后面的步骤中还需要用到,所以请务必记住。**
</Callout>

上方没有提到的选项都不需要填写,然后在右侧的代码编辑器中填入以下代码:

```js
export default async function handler(ctx: Context) {
const { timestamp, process, key, media } = ctx.req.body || {}

const [processName, mediaInfo] = await Promise.all([
ctx.storage.cache.get('ps'),
ctx.storage.cache.get('media').then((JSONString) => {
if (JSONString) {
try {
return JSON.parse(JSONString)
} catch {
return undefined
}
}
}),
])

if (!key) {
return {
processName,
mediaInfo,
}
}
上方没有提到的选项都不需要填写,然后在右侧的代码编辑器中填入下面链接中的代码:

const validKey = (await ctx.secret.key) || 'testing'
if (key != validKey)
ctx.throws(401, "You haven't permission to update process info")
await ctx.storage.cache.set('ps', process, 60)
const ts = +new Date()

if (process !== processName)
ctx.broadcast('ps-update', {
process,
ts,
})
if (media) {
await ctx.storage.cache.set('media', JSON.stringify(media), 10)

if (mediaInfo.title !== media.title) ctx.broadcast('media-update', media)
}
return {
ok: 1,
process,
timestamp: +new Date(),
}
}
```
<ToGitHub repo="https://github.com/mx-space/snippets/blob/main/shiro/functions/ps.ts" />

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

<Callout type="info">
请关注此代码的更新,它可能会随时变化,你需要及时更新它们
</Callout>

### 配置主题配置

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

0 comments on commit b90d196

Please sign in to comment.