-
-
Save OMGZui/90bce0076fada3fead4f79e7a8d132fd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface IcompressImg { | |
(payload: imageType): () => Promise<Idetail> | |
} | |
let compressImg: IcompressImg | |
compressImg = ({ path, file }: imageType) => { | |
return async () => { | |
const result = { | |
input: 0, | |
output: 0, | |
ratio: 0, | |
path, | |
file, | |
msg: '' | |
} | |
try { | |
const dataUpload = await upload(file) | |
const dataDownload = await download(dataUpload.output.url) | |
result.input = dataUpload.input.size | |
result.output = dataUpload.output.size | |
result.ratio = 1 - dataUpload.output.ratio | |
result.file = Buffer.alloc(dataDownload.length, dataDownload, 'binary') | |
} catch (err) { | |
result.msg = `[${chalk.blue(path)}] ${chalk.red(JSON.stringify(err))}` | |
} | |
return result | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment