File tree Expand file tree Collapse file tree 4 files changed +18
-5
lines changed Expand file tree Collapse file tree 4 files changed +18
-5
lines changed Original file line number Diff line number Diff line change @@ -10,8 +10,14 @@ export const token = <T = Upload.TokenResponse>(md5: string) =>
10
10
)
11
11
12
12
export const upload = async ( image : File | Buffer , token : string ) => {
13
+ let file : File
14
+ if ( typeof Buffer !== 'undefined' && Buffer . isBuffer ( image ) ) {
15
+ file = new File ( [ image . buffer ] , '?' )
16
+ } else {
17
+ file = image as File
18
+ }
13
19
const formData = new FormData ( )
14
- formData . append ( 'file' , image as any )
20
+ formData . append ( 'file' , file )
15
21
formData . append ( 'token' , token )
16
22
const result = await ky
17
23
. post ( 'https://upload.qiniup.com/' , {
Original file line number Diff line number Diff line change 4
4
Headers ,
5
5
Request ,
6
6
Response ,
7
+ File ,
7
8
// @ts -expect-error
8
9
FormData ,
9
10
} from 'node-fetch'
@@ -19,6 +20,7 @@ if (!globals.fetch) {
19
20
}
20
21
21
22
if ( ! globals . FormData ) {
23
+ globals . File = File
22
24
globals . FormData = FormData
23
25
}
24
26
Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ import { defaultEnvironment } from './constants'
4
4
import { generateUUID } from './utils'
5
5
import type { KyInstance } from 'ky/distribution/types/ky'
6
6
import type { BeforeRetryState } from 'ky/distribution/types/hooks'
7
- import type { ResponsePromise } from 'ky'
7
+ import type { ResponsePromise , Options } from 'ky'
8
8
9
9
/**
10
10
* API 配置
@@ -64,7 +64,11 @@ let apiConfig: ApiConfigResolved = undefined as any // MUST BE SET FIRST
64
64
*/
65
65
export const setApiConfig = ( config : ApiConfig ) => {
66
66
apiConfig = resolveApiConfig ( config )
67
- _request = ky . create ( {
67
+ _request = ky . create ( resolveKyOptions ( ) )
68
+ }
69
+
70
+ export const resolveKyOptions = ( ) : Options => {
71
+ return {
68
72
prefixUrl : apiConfig . endpointUrl ,
69
73
headers : {
70
74
manufacturer : defaultEnvironment . manufacturer ,
@@ -107,7 +111,7 @@ export const setApiConfig = (config: ApiConfig) => {
107
111
} ,
108
112
] ,
109
113
} ,
110
- } )
114
+ }
111
115
}
112
116
113
117
/** 获取 API 配置 */
Original file line number Diff line number Diff line change @@ -3,8 +3,9 @@ import { setApiConfig, api } from '../../src'
3
3
import { PostType } from '../../src/types/options'
4
4
import { config } from '../config'
5
5
6
+ setApiConfig ( config )
7
+
6
8
describe ( 'posts should work' , ( ) => {
7
- setApiConfig ( config )
8
9
const id = '61b8b9d298f39200100ba010'
9
10
10
11
it ( 'share should work' , async ( ) => {
You can’t perform that action at this time.
0 commit comments