Skip to content

Commit 9065dfc

Browse files
committed
feat(chat): proxy url based on satori protocol
1 parent ebd4265 commit 9065dfc

File tree

10 files changed

+37
-28
lines changed

10 files changed

+37
-28
lines changed

packages/chat/client/avatar.vue

+5-2
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,21 @@
1111
<script setup lang="ts">
1212
1313
import { useRpc } from '@cordisjs/client'
14+
import type { Login } from '@satorijs/protocol'
1415
import getWidth from 'string-width'
1516
import type { Data } from '../src'
1617
17-
defineProps<{
18+
const props = defineProps<{
1819
src?: string
1920
name?: string
21+
login: Login
2022
}>()
2123
2224
const data = useRpc<Data>()
2325
2426
function withProxy(url: string) {
25-
return (data.value.proxy ? data.value.proxy + '/' : '') + url
27+
if (!props.login.proxyUrls.some((proxy) => url.startsWith(proxy))) return url
28+
return data.value.serverUrl + '/v1/proxy/' + url
2629
}
2730
2831
function short(name: string) {

packages/chat/client/index.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { Context, Dict, Service } from '@cordisjs/client'
2-
import { computed, markRaw, reactive } from 'vue'
2+
import { computed, markRaw, reactive, Ref } from 'vue'
33
import HTTP from '@cordisjs/plugin-http'
44
import Satori, { Bot, Universal } from '@satorijs/core'
55
import SatoriAdapter from '@satorijs/adapter-satori'
6-
import {} from '../src'
6+
import { Data } from '../src'
77
import Chat from './index.vue'
88
import './icons'
99

@@ -44,7 +44,7 @@ export default class ChatService extends Service {
4444
return result
4545
})
4646

47-
constructor(ctx: Context) {
47+
constructor(ctx: Context, data: Ref<Data>) {
4848
super(ctx, 'chat', true)
4949
ctx.plugin(HTTP)
5050
ctx.plugin(Satori)
@@ -72,7 +72,7 @@ export default class ChatService extends Service {
7272

7373
ctx.inject(['satori'], (ctx) => {
7474
ctx.plugin(SatoriAdapter, {
75-
endpoint: new URL('/satori', location.href).href,
75+
endpoint: data.value.serverUrl,
7676
})
7777

7878
ctx.page({

packages/chat/client/index.vue

+4-3
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@
3030
@click="setGuild(guild)"
3131
@contextmenu.stop="triggerGuild($event, guild)"
3232
>
33-
<avatar :src="guild.avatar" :name="guild.name" class="w-48px h-48px"/>
33+
<avatar :src="guild.avatar" :name="guild.name" :login="ctx.bots[guild.assignees[0]]"
34+
class="w-48px h-48px"/>
3435
<div class="flex flex-col flex-1">
3536
<div>{{ guild.name }}</div>
3637
<div>{{ guild.id }}</div>
@@ -58,11 +59,11 @@
5859
<span
5960
class="left-timestamp text-gray-4 text-xs
6061
absolute top-0 left-0 h-full w-18
61-
inline-flex items-center justify-center"
62+
inline-flex items-center justify-center"
6263
>{{ formatTime(new Date(message?.createdAt!)) }}</span>
6364
</template>
6465
<template v-else>
65-
<avatar :src="message.user?.avatar" :name="message.user?.name"
66+
<avatar :src="message.user?.avatar" :name="message.user?.name" :login="useBot()"
6667
class="w-10 h-10 absolute mt-1.5"/>
6768
<div class="header">
6869
<span class="font-bold lh-relaxed ml-14">{{ message.user?.name }}</span>

packages/chat/package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@
3131
"cordis": {
3232
"service": {
3333
"required": [
34-
"satori.database",
3534
"webui"
3635
],
3736
"optional": [
38-
"server.proxy"
37+
"satori.database",
38+
"satori.server"
3939
]
4040
}
4141
},
@@ -47,11 +47,11 @@
4747
"devDependencies": {
4848
"@cordisjs/client": "^0.1.4",
4949
"@cordisjs/plugin-http": "^0.5.1",
50-
"@cordisjs/plugin-server-proxy": "^0.2.0",
5150
"@cordisjs/plugin-webui": "^0.1.4",
5251
"@satorijs/adapter-satori": "^1.3.0",
5352
"@satorijs/core": "^4.1.0",
54-
"@satorijs/plugin-database": "^0.1.1"
53+
"@satorijs/plugin-database": "^0.1.1",
54+
"@satorijs/plugin-server": "^2.6.3"
5555
},
5656
"dependencies": {
5757
"cosmokit": "^1.6.2",

packages/chat/src/index.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import { Context, Schema } from '@satorijs/core'
22
import {} from '@cordisjs/plugin-webui'
3-
import {} from '@cordisjs/plugin-server-proxy'
43
import {} from '@satorijs/plugin-database'
4+
import {} from '@satorijs/plugin-server'
55

66
export interface Data {
7-
proxy?: string
7+
serverUrl: string
88
}
99

1010
export const name = 'chat'
1111

12-
export const inject = ['webui']
12+
export const inject = ['webui', 'satori.server']
1313

1414
export interface Config {}
1515

@@ -23,6 +23,6 @@ export function apply(ctx: Context) {
2323
import.meta.resolve('../dist/style.css'),
2424
],
2525
}, () => ({
26-
proxy: ctx.get('server.proxy')?.path,
26+
serverUrl: ctx.satori.server.url,
2727
}))
2828
}

packages/database/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
}
3939
},
4040
"devDependencies": {
41-
"@satorijs/plugin-server": "^2.6.0",
41+
"@satorijs/plugin-server": "^2.6.3",
4242
"minato": "^3.3.0"
4343
},
4444
"peerDependencies": {

packages/status/client/bots/preview.vue

+4-2
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,16 @@ const statusNames: Record<Status, string> = {
3939
[Status.DISCONNECT]: '正在断开',
4040
}
4141
42-
defineProps<{
42+
const props = defineProps<{
4343
bot: Data.Bot
4444
}>()
4545
4646
const data = useRpc<Data>()
4747
4848
function withProxy(url: string) {
49-
return (data.value.proxy ? data.value.proxy + '/' : '') + url
49+
if (!data.value.serverUrl) return url
50+
if (!props.bot.proxyUrls.some((proxy) => url.startsWith(proxy))) return url
51+
return data.value.serverUrl + '/v1/proxy/' + url
5052
}
5153
5254
</script>

packages/status/client/config.vue

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<template>
22
<template v-if="bots?.length">
33
<h2 class="k-schema-header">
4-
机器人
4+
登录号
55
</h2>
66
<div class="bots-container flex flex-wrap gap-4">
77
<bot-preview v-for="(bot, sid) in bots" :key="sid" :bot="bot"/>
@@ -22,7 +22,7 @@ const data = useRpc<Data>()
2222
2323
const bots = computed(() => {
2424
return Object.values(data.value.bots || {}).filter(bot => {
25-
return bot.paths?.includes(ctx.get('manager')!.current.value!.path)
25+
return bot.paths?.includes(ctx.get('manager')!.current.value!.id)
2626
})
2727
})
2828

packages/status/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
],
3636
"optional": [
3737
"manager",
38-
"server.proxy"
38+
"satori.server"
3939
]
4040
}
4141
},
@@ -46,7 +46,7 @@
4646
"devDependencies": {
4747
"@cordisjs/client": "^0.1.4",
4848
"@cordisjs/plugin-manager": "^0.1.1",
49-
"@cordisjs/plugin-server-proxy": "^0.2.0"
49+
"@satorijs/plugin-server": "^2.6.3"
5050
},
5151
"dependencies": {
5252
"cosmokit": "^1.6.2"

packages/status/src/index.ts

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Bot, Context, Dict, Schema, Time, Universal } from '@satorijs/core'
22
import {} from '@cordisjs/loader'
33
import {} from '@cordisjs/plugin-webui'
4-
import {} from '@cordisjs/plugin-server-proxy'
4+
import {} from '@satorijs/plugin-server'
55

66
declare module '@satorijs/core' {
77
interface Bot {
@@ -11,8 +11,8 @@ declare module '@satorijs/core' {
1111
}
1212

1313
export interface Data {
14-
proxy?: string
1514
bots: Dict<Data.Bot>
15+
serverUrl?: string
1616
}
1717

1818
export namespace Data {
@@ -54,7 +54,10 @@ class TickCounter {
5454

5555
export const name = 'status'
5656

57-
export const inject = ['webui']
57+
export const inject = {
58+
required: ['webui'],
59+
optional: ['satori.server'],
60+
}
5861

5962
export interface Config {}
6063

@@ -79,7 +82,7 @@ export function apply(ctx: Context) {
7982
messageReceived: bot._messageReceived.get(),
8083
}
8184
}
82-
return { bots, proxy: ctx.get('server.proxy')?.path }
85+
return { bots, serverUrl: ctx.get('satori.server')?.url }
8386
})
8487

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

0 commit comments

Comments
 (0)