Skip to content

Instantly share code, notes, and snippets.

@OMGZui
Created November 18, 2022 09:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save OMGZui/90bce0076fada3fead4f79e7a8d132fd to your computer and use it in GitHub Desktop.
Save OMGZui/90bce0076fada3fead4f79e7a8d132fd to your computer and use it in GitHub Desktop.
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