Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/idranme/satori
Browse files Browse the repository at this point in the history
  • Loading branch information
idranme committed Dec 22, 2024
2 parents 9582dc7 + 7c8c2bc commit 2adcfcc
Show file tree
Hide file tree
Showing 32 changed files with 295 additions and 257 deletions.
4 changes: 2 additions & 2 deletions adapters/dingtalk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@
"devDependencies": {
"@cordisjs/plugin-server": "^0.2.4",
"@cordisjs/plugin-server-temp": "^0.5.0",
"@satorijs/core": "^4.2.12",
"@satorijs/core": "^4.3.1",
"cordis": "^3.18.1"
},
"peerDependencies": {
"@satorijs/core": "^4.2.12"
"@satorijs/core": "^4.3.1"
}
}
4 changes: 2 additions & 2 deletions adapters/discord/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@
"chat"
],
"devDependencies": {
"@satorijs/core": "^4.2.12",
"@satorijs/core": "^4.3.1",
"cordis": "^3.18.1"
},
"peerDependencies": {
"@satorijs/core": "^4.2.12"
"@satorijs/core": "^4.3.1"
}
}
4 changes: 2 additions & 2 deletions adapters/kook/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@
],
"devDependencies": {
"@cordisjs/plugin-server": "^0.2.4",
"@satorijs/core": "^4.2.12",
"@satorijs/core": "^4.3.1",
"cordis": "^3.18.1"
},
"peerDependencies": {
"@satorijs/core": "^4.2.12"
"@satorijs/core": "^4.3.1"
}
}
6 changes: 3 additions & 3 deletions adapters/lark/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@satorijs/adapter-lark",
"description": "Lark (飞书) Adapter for Satorijs",
"version": "3.7.4",
"version": "3.8.0",
"type": "module",
"main": "lib/index.cjs",
"types": "lib/index.d.ts",
Expand Down Expand Up @@ -35,10 +35,10 @@
],
"devDependencies": {
"@cordisjs/plugin-server": "^0.2.4",
"@satorijs/core": "^4.2.12",
"@satorijs/core": "^4.3.1",
"cordis": "^3.18.1"
},
"peerDependencies": {
"@satorijs/core": "^4.2.12"
"@satorijs/core": "^4.3.1"
}
}
15 changes: 7 additions & 8 deletions adapters/lark/src/bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,21 @@ export class LarkBot<C extends Context = Context> extends Bot<C, LarkBot.Config>
constructor(ctx: C, config: LarkBot.Config) {
super(ctx, config, 'lark')

// lark bot needs config.selfUrl to be set as it should be serve on a public url
if (!config.selfUrl && !ctx.server.config.selfUrl) {
this.logger.warn('selfUrl is not set, some features may not work')
}

this.http = ctx.http.extend({
endpoint: config.endpoint,
})
this.assetsQuester = ctx.http
this.internal = new Internal(this)

ctx.plugin(HttpServer, this)
}

get appId() {
return this.config.appId
this.defineVirtualRoute('/:type/:message_id/:file_key', async ({ params }) => {
const type = params.type === 'image' ? 'image' : 'file'
const key = params.file_key
const messageId = params.message_id
const data = await this.internal.getImMessageResource(messageId, key, { type })
return { data, status: 200 }
})
}

async initialize() {
Expand Down
22 changes: 1 addition & 21 deletions adapters/lark/src/http.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { Readable } from 'node:stream'
import { ReadableStream } from 'node:stream/web'
import { Adapter, Context, Logger, Schema } from '@satorijs/core'
import {} from '@cordisjs/plugin-server'

Expand Down Expand Up @@ -78,32 +76,14 @@ export class HttpServer<C extends Context = Context> extends Adapter<C, LarkBot<
ctx.body = {}
return ctx.status = 200
})

bot.ctx.server.get(path + '/assets/:type/:message_id/:key', async (ctx) => {
const type = ctx.params.type === 'image' ? 'image' : 'file'
const key = ctx.params.key
const messageId = ctx.params.message_id
const selfId = ctx.request.query.self_id
const bot = this.bots.find((bot) => bot.selfId === selfId)
if (!bot) return ctx.status = 404

const resp = await bot.http<ReadableStream>(`/im/v1/messages/${messageId}/resources/${key}`, {
method: 'GET',
params: { type },
responseType: 'stream',
})
ctx.set('content-type', resp.headers.get('content-type'))
ctx.status = 200
ctx.response.body = Readable.fromWeb(resp.data)
})
}

async dispatchSession(body: EventPayload) {
const { header } = body
if (!header) return
const { app_id, event_type } = header
body.type = event_type // add type to body to ease typescript type narrowing
const bot = this.bots.find((bot) => bot.appId === app_id)
const bot = this.bots.find((bot) => bot.config.appId === app_id)
const session = await adaptSession(bot, body)
bot.dispatch(session)
}
Expand Down
Loading

0 comments on commit 2adcfcc

Please sign in to comment.