fix(adapters): tsconfig-strict types for Dirent and Lark image upload

- attachment-store.ts: pin Dirent<string>[] and pass `encoding: 'utf8'`
  so newer @types/node doesn't infer Dirent<NonSharedBuffer>
- feishu/media.ts: drop Readable.from(buffer) and pass Buffer directly
  to im.image.create / im.file.create — Lark SDK already accepts Buffer
  and the stream wrapper trips the stricter Buffer | ReadStream union
  used on the main branch's tsconfig

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
程序员阿江(Relakkes) 2026-04-11 21:14:28 +08:00
parent 6bcbbc547f
commit 80eaa8cc1e
2 changed files with 10 additions and 9 deletions

View File

@ -12,6 +12,7 @@
import * as fs from 'node:fs/promises' import * as fs from 'node:fs/promises'
import * as fsSync from 'node:fs' import * as fsSync from 'node:fs'
import type { Dirent } from 'node:fs'
import * as path from 'node:path' import * as path from 'node:path'
import * as os from 'node:os' import * as os from 'node:os'
import type { ImPlatform } from './attachment-types.js' import type { ImPlatform } from './attachment-types.js'
@ -84,9 +85,11 @@ export class AttachmentStore {
const now = Date.now() const now = Date.now()
const walk = async (dir: string): Promise<void> => { const walk = async (dir: string): Promise<void> => {
let entries: Awaited<ReturnType<typeof fs.readdir>> let entries: Dirent<string>[]
try { try {
entries = await fs.readdir(dir, { withFileTypes: true }) // Pass encoding explicitly so Dirent stays string-typed under
// newer @types/node where the Buffer overload becomes the default.
entries = await fs.readdir(dir, { withFileTypes: true, encoding: 'utf8' })
} catch { } catch {
return return
} }

View File

@ -12,7 +12,6 @@
import * as Lark from '@larksuiteoapi/node-sdk' import * as Lark from '@larksuiteoapi/node-sdk'
import * as fs from 'node:fs/promises' import * as fs from 'node:fs/promises'
import * as path from 'node:path' import * as path from 'node:path'
import { Readable } from 'node:stream'
import { AttachmentStore } from '../common/attachment/attachment-store.js' import { AttachmentStore } from '../common/attachment/attachment-store.js'
import type { LocalAttachment } from '../common/attachment/attachment-types.js' import type { LocalAttachment } from '../common/attachment/attachment-types.js'
@ -123,13 +122,13 @@ export class FeishuMediaService {
} }
/** Upload an image buffer, returns image_key. /** Upload an image buffer, returns image_key.
* node-sdk expects `image` to be a readable stream (see OpenClaw media.ts:290). * The Lark node-sdk type for `image` accepts `Buffer | ReadStream`,
* We use Readable.from(buffer) to avoid spilling to disk for pure in-memory buffers. */ * so passing the buffer directly is the simplest path. */
async uploadImage(buffer: Buffer, _mime: string): Promise<string> { async uploadImage(buffer: Buffer, _mime: string): Promise<string> {
const resp: any = await this.client.im.image.create({ const resp: any = await this.client.im.image.create({
data: { data: {
image_type: 'message', image_type: 'message',
image: Readable.from(buffer), image: buffer,
}, },
}) })
const key = resp?.data?.image_key const key = resp?.data?.image_key
@ -137,14 +136,13 @@ export class FeishuMediaService {
return key return key
} }
/** Upload a non-image file, returns file_key. /** Upload a non-image file, returns file_key. */
* See OpenClaw media.ts:334 for stream-based upload pattern. */
async uploadFile(buffer: Buffer, fileName: string): Promise<string> { async uploadFile(buffer: Buffer, fileName: string): Promise<string> {
const resp: any = await this.client.im.file.create({ const resp: any = await this.client.im.file.create({
data: { data: {
file_type: detectFeishuFileType(fileName), file_type: detectFeishuFileType(fileName),
file_name: fileName, file_name: fileName,
file: Readable.from(buffer), file: buffer,
}, },
}) })
const key = resp?.data?.file_key const key = resp?.data?.file_key