Bump welshman, rename stripExifData
This commit is contained in:
+12
-18
@@ -1,4 +1,4 @@
|
||||
import {sleep, last} from "@welshman/lib"
|
||||
import {sleep, last, randomId} from "@welshman/lib"
|
||||
export {preventDefault, stopPropagation} from "svelte/legacy"
|
||||
|
||||
export const copyToClipboard = (text: string) => {
|
||||
@@ -136,29 +136,23 @@ export const scrollToEvent = async (id: string, attempts = 3): Promise<boolean>
|
||||
return false
|
||||
}
|
||||
|
||||
export const stripExifData = async (file, {maxWidth = null, maxHeight = null} = {}) => {
|
||||
if (window.DataTransferItem && file instanceof DataTransferItem) {
|
||||
file = file.getAsFile()
|
||||
}
|
||||
|
||||
if (!file) {
|
||||
return file
|
||||
}
|
||||
|
||||
export const compressFile = async (file: File | Blob): Promise<File> => {
|
||||
const {default: Compressor} = await import("compressorjs")
|
||||
|
||||
/* eslint no-new: 0 */
|
||||
|
||||
return new Promise((resolve, _reject) => {
|
||||
return new Promise<File>((resolve, _reject) => {
|
||||
new Compressor(file, {
|
||||
maxWidth: maxWidth || 2048,
|
||||
maxHeight: maxHeight || 2048,
|
||||
maxWidth: 2048,
|
||||
maxHeight: 2048,
|
||||
convertSize: 10 * 1024 * 1024,
|
||||
success: resolve,
|
||||
success: result => resolve(result as File),
|
||||
error: e => {
|
||||
// Non-images break compressor
|
||||
// Non-images break compressor, return the original file
|
||||
if (e.toString().includes("File or Blob")) {
|
||||
return resolve(file)
|
||||
if (file instanceof Blob) {
|
||||
file = new File([file], `${randomId()}.${file.type}`, {type: file.type})
|
||||
}
|
||||
|
||||
return resolve(file as File)
|
||||
}
|
||||
|
||||
_reject(e)
|
||||
|
||||
Reference in New Issue
Block a user