Skip to content

Commit d69df02

Browse files
committed
The fetchFile API can provide the extension of the downloaded file
1 parent 1457f7e commit d69df02

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

src/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -146,11 +146,11 @@ export default class XCrawl {
146146
const { id, headers, data } = requestResItem
147147

148148
const mimeType = headers['content-type'] ?? ''
149-
const suffix = mimeType.split('/').pop()
149+
const fileExtension = fileConfig.extension ?? mimeType.split('/').pop()
150150
const fileName = new Date().getTime().toString()
151151
const filePath = path.resolve(
152152
fileConfig.storeDir,
153-
`${fileName}.${suffix}`
153+
`${fileName}.${fileExtension}`
154154
)
155155

156156
try {

src/types.ts

+1
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ export interface IFetchDataConfig extends IFetchBaseConifg {}
7777
export interface IFetchFileConfig extends IFetchBaseConifg {
7878
fileConfig: {
7979
storeDir: string
80+
extension?: string
8081
}
8182
}
8283

0 commit comments

Comments
 (0)