|
@@ -36,15 +36,52 @@ function formatDateTime(date) {
|
|
|
return `${year}${month}${day}${hours}${minutes}${seconds}${Milliseconds}`
|
|
|
}
|
|
|
|
|
|
-async function DownloadStreamSaver(blob, fileName) {
|
|
|
+async function DownloadStreamSaver(blob, fileName, type) {
|
|
|
const opts = {
|
|
|
suggestedName: fileName,
|
|
|
types: [{ 'image/png': ['png'] }]
|
|
|
}
|
|
|
- const handle = await showSaveFilePicker(opts)
|
|
|
- const ws = await handle.createWritable()
|
|
|
- ws.write(blob)
|
|
|
- ws.close()
|
|
|
+ if (window.parent != window) {
|
|
|
+ window.parent.postMessage(
|
|
|
+ { type: 'native-file-system-adapter', imgOrVideo: type, opts, blob },
|
|
|
+ '*'
|
|
|
+ )
|
|
|
+ } else {
|
|
|
+ if (type === 'img') {
|
|
|
+ // 创建一个新的Image对象
|
|
|
+ const img = new Image()
|
|
|
+ img.src = URL.createObjectURL(blob)
|
|
|
+
|
|
|
+ // 等待图片加载完成
|
|
|
+ img.onload = () => {
|
|
|
+ // 创建Canvas元素
|
|
|
+ const canvas = document.createElement('canvas')
|
|
|
+ const ctx = canvas.getContext('2d')
|
|
|
+ // 设置Canvas大小
|
|
|
+ canvas.width = img.width
|
|
|
+ canvas.height = img.height
|
|
|
+ if (ctx) {
|
|
|
+ ctx.translate(img.width / 2, img.height / 2)
|
|
|
+ ctx.rotate(Math.PI)
|
|
|
+ ctx.translate(-img.width / 2, -img.height / 2)
|
|
|
+ ctx.drawImage(img, 0, 0)
|
|
|
+ }
|
|
|
+
|
|
|
+ // 将旋转后的Canvas转换回Blob
|
|
|
+ canvas.toBlob(async (rotatedBlob) => {
|
|
|
+ const handle = await showSaveFilePicker(opts)
|
|
|
+ const ws = await handle.createWritable()
|
|
|
+ ws.write(rotatedBlob)
|
|
|
+ ws.close()
|
|
|
+ })
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ const handle = await showSaveFilePicker(opts)
|
|
|
+ const ws = await handle.createWritable()
|
|
|
+ ws.write(blob)
|
|
|
+ ws.close()
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
export default function useWorker(url, className, callback = () => {}) {
|
|
@@ -58,7 +95,7 @@ export default function useWorker(url, className, callback = () => {}) {
|
|
|
worker.addEventListener('message', (msg) => {
|
|
|
if (msg.data.type === 'img') {
|
|
|
// saveAs(msg.data.img,`${formatDateTime(new Date())}.png`)
|
|
|
- DownloadStreamSaver(msg.data.img, `${formatDateTime(new Date())}.png`)
|
|
|
+ DownloadStreamSaver(msg.data.img, `${formatDateTime(new Date())}.png`, msg.data.type)
|
|
|
} else {
|
|
|
callback()
|
|
|
}
|
|
@@ -113,7 +150,8 @@ export default function useWorker(url, className, callback = () => {}) {
|
|
|
ffmpeg.deleteFile('test.mp4')
|
|
|
DownloadStreamSaver(
|
|
|
new Blob([data.buffer], { type: 'video/mp4' }),
|
|
|
- `${formatDateTime(new Date())}.mp4`
|
|
|
+ `${formatDateTime(new Date())}.mp4`,
|
|
|
+ message.data.DataType
|
|
|
)
|
|
|
ffmpeg.deleteFile('out.mp4')
|
|
|
}
|