@satorijs/adapter-lark 3.7.1 → 3.7.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- import { Dict } from '@satorijs/core';
1
+ import { Dict, HTTP } from '@satorijs/core';
2
2
  import { LarkBot } from '../bot';
3
3
  export interface Internal {
4
4
  }
@@ -8,11 +8,14 @@ export interface BaseResponse {
8
8
  /** error message. would be 'success' if success. */
9
9
  msg: string;
10
10
  }
11
- type Method = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
11
+ export interface InternalConfig {
12
+ multipart?: boolean;
13
+ noExtractData?: boolean;
14
+ }
12
15
  export declare class Internal {
13
16
  private bot;
14
17
  constructor(bot: LarkBot);
15
- private assertResponse;
16
- static define(routes: Dict<Partial<Record<Method, string | string[]>>>, extractData?: boolean): void;
18
+ private _assertResponse;
19
+ private _buildData;
20
+ static define(routes: Dict<Partial<Record<HTTP.Method, string | string[]>>>, options?: InternalConfig): void;
17
21
  }
18
- export {};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@satorijs/adapter-lark",
3
3
  "description": "Lark (飞书) Adapter for Satorijs",
4
- "version": "3.7.1",
4
+ "version": "3.7.3",
5
5
  "type": "module",
6
6
  "main": "lib/index.cjs",
7
7
  "types": "lib/index.d.ts",
@@ -35,10 +35,10 @@
35
35
  ],
36
36
  "devDependencies": {
37
37
  "@cordisjs/plugin-server": "^0.2.4",
38
- "@satorijs/core": "^4.2.11",
38
+ "@satorijs/core": "^4.2.12",
39
39
  "cordis": "^3.18.1"
40
40
  },
41
41
  "peerDependencies": {
42
- "@satorijs/core": "^4.2.11"
42
+ "@satorijs/core": "^4.2.12"
43
43
  }
44
44
  }
package/src/message.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { Context, Dict, h, MessageEncoder } from '@satorijs/core'
2
2
  import { LarkBot } from './bot'
3
- import { Lark, MessageContent } from './types'
3
+ import { CreateImFileForm, Lark, MessageContent } from './types'
4
4
  import { extractIdType } from './utils'
5
5
 
6
6
  export class LarkMessageEncoder<C extends Context = Context> extends MessageEncoder<C, LarkBot<C>> {
@@ -93,40 +93,43 @@ export class LarkMessageEncoder<C extends Context = Context> extends MessageEnco
93
93
 
94
94
  async createImage(url: string) {
95
95
  const { filename, type, data } = await this.bot.assetsQuester.file(url)
96
- const payload = new FormData()
97
- payload.append('image', new Blob([data], { type }), filename)
98
- payload.append('image_type', 'message')
99
- const { image_key } = await this.bot.internal.createImImage(payload)
96
+ const { image_key } = await this.bot.internal.createImImage({
97
+ image_type: 'message',
98
+ image: new File([data], filename, { type }),
99
+ })
100
100
  return image_key
101
101
  }
102
102
 
103
103
  async sendFile(_type: 'video' | 'audio' | 'file', attrs: any) {
104
104
  const url = attrs.src || attrs.url
105
- const payload = new FormData()
106
105
  const { filename, type, data } = await this.bot.assetsQuester.file(url)
107
- payload.append('file', new Blob([data], { type }), filename)
108
- payload.append('file_name', filename)
109
-
110
- if (attrs.duration) {
111
- payload.append('duration', attrs.duration)
112
- }
113
106
 
107
+ let file_type: CreateImFileForm['file_type']
114
108
  if (_type === 'audio') {
115
109
  // FIXME: only support opus
116
- payload.append('file_type', 'opus')
110
+ file_type = 'opus'
117
111
  } else if (_type === 'video') {
118
112
  // FIXME: only support mp4
119
- payload.append('file_type', 'mp4')
113
+ file_type = 'mp4'
120
114
  } else {
121
115
  const ext = filename.split('.').pop()
122
116
  if (['doc', 'xls', 'ppt', 'pdf'].includes(ext)) {
123
- payload.append('file_type', ext)
117
+ file_type = ext
124
118
  } else {
125
- payload.append('file_type', 'stream')
119
+ file_type = 'stream'
126
120
  }
127
121
  }
128
122
 
129
- const { file_key } = await this.bot.internal.createImFile(payload)
123
+ const form: CreateImFileForm = {
124
+ file_type,
125
+ file: new File([data], filename, { type }),
126
+ file_name: filename,
127
+ }
128
+ if (attrs.duration) {
129
+ form.duration = attrs.duration
130
+ }
131
+
132
+ const { file_key } = await this.bot.internal.createImFile(form)
130
133
  await this.post({
131
134
  msg_type: _type === 'video' ? 'media' : _type,
132
135
  content: JSON.stringify({ file_key }),