Skip to content

Commit

Permalink
fix: 使用 formdata-node
Browse files Browse the repository at this point in the history
  • Loading branch information
TimeRainStarSky committed Jan 19, 2024
1 parent 12d65e3 commit 5ad543c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,19 @@
"author": "凉菜",
"license": "MIT",
"dependencies": {
"axios": "^1.6.1",
"form-data": "^4.0.0",
"axios": "^1.6.5",
"formdata-node": "^6.0.3",
"log4js": "^6.9.1",
"ws": "^8.14.0"
"ws": "^8.16.0"
},
"devDependencies": {
"@types/node": "^20.5.9",
"@types/ws": "^8.5.5",
"@types/node": "^20.11.5",
"@types/ws": "^8.5.10",
"dtsc": "^2.3.0",
"ts-node-dev": "^2.0.0",
"tsc-alias": "^1.8.8",
"tsconfig-paths": "^4.2.0",
"typescript": "^5.2.2",
"vitepress": "^1.0.0-rc.31"
"typescript": "^5.3.3",
"vitepress": "1.0.0-rc.39"
}
}
12 changes: 6 additions & 6 deletions src/entries/sender.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {AudioElem, Dict, ImageElem, QQBot, Quotable, Sendable, VideoElem} from "@";
import {randomInt} from "crypto";
import * as fs from "fs";
import {ReadStream} from "node:fs";
import fs from "node:fs";
import { Blob } from "formdata-node"

export class Sender {
brief: string = ''
Expand Down Expand Up @@ -62,15 +62,15 @@ export class Sender {
return elem.file
}
this.contentType='multipart/form-data'
if(elem.file instanceof ReadStream) return elem.file
if(elem.file instanceof fs.ReadStream) return elem.file
if(Buffer.isBuffer(elem.file)){
return fs.createReadStream(elem.file)
return new Blob([elem.file])
}else if(typeof elem.file !== "string"){
throw new Error("bad file param: " + elem.file)
}else if(elem.file.startsWith("base64://")){
return fs.createReadStream(Buffer.from(elem.file.slice(9),'base64'))
return new Blob([Buffer.from(elem.file.slice(9),'base64')])
}else if(/^data:[^/]+\/[^;]+;base64,/.test(elem.file)){
return fs.createReadStream(Buffer.from(elem.file.replace(/^data:[^/]+\/[^;]+;base64,/,''),'base64'))
return new Blob([Buffer.from(elem.file.replace(/^data:[^/]+\/[^;]+;base64,/,''),'base64')])
}else if(fs.existsSync(elem.file)){
return fs.createReadStream(elem.file)
}
Expand Down
4 changes: 2 additions & 2 deletions src/qqBot.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import axios, {AxiosInstance} from "axios";
import {WebSocket} from "ws";
import FormData from 'form-data'
import {FormData} from 'formdata-node'
import * as log4js from 'log4js'
import {EventEmitter} from "events";
import {SessionManager} from "./sessionManager";
Expand Down Expand Up @@ -42,7 +42,7 @@ export class QQBot extends EventEmitter {
if(config.headers['Content-Type']==='multipart/form-data'){
const formData=new FormData()
for(const key in config.data){
formData.append(key,config.data[key])
formData.set(key,config.data[key])
}
config.data=formData
}
Expand Down

0 comments on commit 5ad543c

Please sign in to comment.