Skip to content

Commit

Permalink
The fetchFile API can provide the extension of the downloaded file
Browse files Browse the repository at this point in the history
  • Loading branch information
coder-hxl committed Feb 16, 2023
1 parent 1457f7e commit d69df02
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,11 @@ export default class XCrawl {
const { id, headers, data } = requestResItem

const mimeType = headers['content-type'] ?? ''
const suffix = mimeType.split('/').pop()
const fileExtension = fileConfig.extension ?? mimeType.split('/').pop()
const fileName = new Date().getTime().toString()
const filePath = path.resolve(
fileConfig.storeDir,
`${fileName}.${suffix}`
`${fileName}.${fileExtension}`
)

try {
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export interface IFetchDataConfig extends IFetchBaseConifg {}
export interface IFetchFileConfig extends IFetchBaseConifg {
fileConfig: {
storeDir: string
extension?: string
}
}

Expand Down

0 comments on commit d69df02

Please sign in to comment.