Skip to content

Commit

Permalink
feat(status): support resource proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed May 15, 2024
1 parent 6dc04f3 commit 29b759b
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 32 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"yakumo": "^1.0.0-beta.15",
"yakumo-esbuild": "^1.0.0-beta.5",
"yakumo-mocha": "^1.0.0-beta.2",
"yakumo-tsc": "^1.0.0-beta.3"
"yakumo-tsc": "^1.0.0-beta.3",
"yml-register": "^1.2.5"
}
}
22 changes: 17 additions & 5 deletions packages/chat/client/index.vue
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
<template>
<k-layout>
<template #left>
<div class="flex px-4 py-2 gap-x-4 justify-between" v-for="guild in data.guilds" :key="guild.id">
<img class="b-rd-full" :src="guild.avatar" width="48" height="48"/>
<div class="flex flex-col flex-1">
<div>{{ guild.name }}</div>
<div>{{ guild.id }}</div>
<el-scrollbar>
<div v-for="guild in data.guilds" :key="guild.id"
class="flex px-4 py-3 gap-x-4 justify-between
bg-gray-700 bg-op-0 hover:bg-op-100 transition cursor-pointer"
@click="onClickGuild(guild)"
>
<img v-if="guild.avatar" :src="withProxy(guild.avatar)" width="48" height="48" class="b-rd-full"/>
<div v-else
class="w-48px h-48px b-rd-full bg-gray-500
font-bolder text-18px
flex justify-center items-center">
{{ short(guild.name!) }}
</div>
<div class="flex flex-col flex-1">
<div>{{ guild.name }}</div>
<div>{{ guild.id }}</div>
</div>
</div>
</div>
</template>
Expand Down
2 changes: 1 addition & 1 deletion packages/status/client/bots/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<span v-if="!Object.values(data.bots).length" class="el-popper__empty"></span>
<template v-for="(bot, key) in data.bots" :key="key">
<bot-preview
:data="bot"
:bot="bot"
:class="{ 'has-link': bot.paths?.length }"
@click="bot.paths && router.push('/plugins/' + bot.paths[0].replace(/\./, '/'))"
></bot-preview>
Expand Down
24 changes: 16 additions & 8 deletions packages/status/client/bots/preview.vue
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
<template>
<section class="bot-view">
<div class="avatar" :style="{ backgroundImage: `url(${data.user!.avatar})` }" @click="$emit('avatar-click')">
<el-tooltip :content="statusNames[data.status]" placement="right">
<status-light :class="getStatus(data.status)"></status-light>
<!-- FIXME avatar may be absent -->
<div class="avatar" :style="{ backgroundImage: `url(${withProxy(bot.user!.avatar!)})` }" @click="$emit('avatar-click')">
<el-tooltip :content="statusNames[bot.status]" placement="right">
<status-light :class="getStatus(bot.status)"></status-light>
</el-tooltip>
</div>
<div class="info">
<div class="truncate" :title="data.user!.name"><k-icon name="robot"/>{{ data.user!.name }}</div>
<div class="truncate" :title="data.platform"><k-icon name="platform"/>{{ data.platform }}</div>
<div class="truncate" :title="bot.user!.name"><k-icon name="robot"/>{{ bot.user!.name }}</div>
<div class="truncate" :title="bot.platform"><k-icon name="platform"/>{{ bot.platform }}</div>
<div class="truncate cur-frequency">
<span style="margin-right: 8px">
<k-icon name="arrow-up"/>
<span>{{ data.messageSent }}/min</span>
<span>{{ bot.messageSent }}/min</span>
</span>
<span>
<k-icon name="arrow-down"/>
<span>{{ data.messageReceived }}/min</span>
<span>{{ bot.messageReceived }}/min</span>
</span>
</div>
</div>
Expand All @@ -25,6 +26,7 @@
<script lang="ts" setup>
import { Status } from '@satorijs/protocol'
import { useRpc } from '@cordisjs/client'
import type { Data } from '../../src'
import { getStatus } from './utils'
import StatusLight from './light.vue'
Expand All @@ -38,9 +40,15 @@ const statusNames: Record<Status, string> = {
}
defineProps<{
data: Data.Bot
bot: Data.Bot
}>()
const data = useRpc<Data>()
function withProxy(url: string) {
return (data.value.proxy ? data.value.proxy + '/' : '') + url
}
</script>

<style scoped lang="scss">
Expand Down
4 changes: 2 additions & 2 deletions packages/status/client/config.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
机器人
</h2>
<div class="bots-container flex flex-wrap gap-4">
<bot-preview v-for="(bot, sid) in bots" :key="sid" :data="bot"/>
<bot-preview v-for="(bot, sid) in bots" :key="sid" :bot="bot"/>
</div>
</template>
</template>
Expand All @@ -22,7 +22,7 @@ const data = useRpc<Data>()
const bots = computed(() => {
return Object.values(data.value.bots || {}).filter(bot => {
return bot.paths?.includes(ctx.manager.current.value!.path)
return bot.paths?.includes(ctx.get('manager')!.current.value!.path)
})
})
Expand Down
17 changes: 7 additions & 10 deletions packages/status/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,16 @@ declare module '@cordisjs/client' {
export default (ctx: Context) => {
ctx.plugin(Bots)

// FIXME auto inject
ctx.inject(['manager'], (ctx) => {
ctx.slot({
type: 'plugin-details',
component: Config,
order: -500,
})
ctx.slot({
type: 'plugin-details',
component: Config,
order: -500,
})

ctx.settings({
id: 'status',
id: 'satori',
schema: Schema.object({
mergeThreshold: Schema.number().default(10).description('当机器人的数量超过这个值时将合并显示状态指示灯。'),
}).description('机器人设置'),
mergeThreshold: Schema.number().default(10).description('当登录号的数量超过这个值时将合并显示状态指示灯。'),
}).description('Satori 设置'),
})
}
10 changes: 6 additions & 4 deletions packages/status/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,19 @@
"webui"
],
"optional": [
"manager"
"manager",
"server.proxy"
]
}
},
"peerDependencies": {
"@cordisjs/plugin-manager": "^0.1.0",
"@cordisjs/plugin-webui": "^0.1.1",
"@cordisjs/plugin-webui": "^0.1.3",
"@satorijs/core": "^4.0.0"
},
"devDependencies": {
"@cordisjs/client": "^0.1.1"
"@cordisjs/client": "^0.1.3",
"@cordisjs/plugin-manager": "^0.1.0",
"@cordisjs/plugin-server-proxy": "^0.2.0"
},
"dependencies": {
"cosmokit": "^1.6.2"
Expand Down
4 changes: 3 additions & 1 deletion packages/status/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Bot, Context, Dict, Schema, Time, Universal } from '@satorijs/core'
import {} from '@cordisjs/loader'
import {} from '@cordisjs/plugin-webui'
import {} from '@cordisjs/plugin-server-proxy'

declare module '@satorijs/core' {
interface Bot {
Expand All @@ -10,6 +11,7 @@ declare module '@satorijs/core' {
}

export interface Data {
proxy?: string
bots: Dict<Data.Bot>
}

Expand Down Expand Up @@ -77,7 +79,7 @@ export function apply(ctx: Context) {
messageReceived: bot._messageReceived.get(),
}
}
return { bots }
return { bots, proxy: ctx.get('server.proxy')?.path }
})

const update = ctx.debounce(() => entry.refresh(), 0)
Expand Down

0 comments on commit 29b759b

Please sign in to comment.