Handle many files as a zip archive (#1688)

* Handle many files as a zip archive

* Hopefully fix the test

* Try again

* Use latest kittycad/cli version

* update gitignore and push gltf-standard into snapshot array

* Extract zipped gltf; use 8 cores for CI

* Ignore unzipped files

* A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu)

---------

Co-authored-by: Kurt Hutten Irev-Dev <k.hutten@protonmail.ch>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
This commit is contained in:
49fl
2024-03-14 11:50:46 -04:00
committed by GitHub
parent cede44aacf
commit 0579ccd53b
13 changed files with 133 additions and 4105 deletions

View File

@ -4,41 +4,61 @@ import { browserSaveFile } from './browserSaveFile'
import { save } from '@tauri-apps/api/dialog'
import { writeBinaryFile } from '@tauri-apps/api/fs'
// Saves files locally from an export call.
export async function exportSave(data: ArrayBuffer) {
// This converts the ArrayBuffer to a Rust equivalent Vec<u8>.
let uintArray = new Uint8Array(data)
import JSZip from 'jszip'
interface ModelingAppFile {
name: string
contents: number[]
}
const save_ = async (file: ModelingAppFile) => {
try {
const files: { contents: number[]; name: string }[] =
deserialize_files(uintArray)
for (const file of files) {
if (isTauri()) {
// Open a dialog to save the file.
const filePath = await save({
defaultPath: file.name,
})
if (isTauri()) {
// Open a dialog to save the file.
const filePath = await save({
defaultPath: file.name,
})
if (filePath === null) {
// The user canceled the save.
// Return early.
return
}
// Write the file.
await writeBinaryFile(filePath, file.contents)
} else {
// Download the file to the user's computer.
// Now we need to download the files to the user's downloads folder.
// Or the destination they choose.
// Iterate over the files.
// Create a new blob.
const blob = new Blob([new Uint8Array(file.contents)])
// Save the file.
await browserSaveFile(blob, file.name)
if (filePath === null) {
// The user canceled the save.
// Return early.
return
}
// Write the file.
await writeBinaryFile(filePath, file.contents)
} else {
// Download the file to the user's computer.
// Now we need to download the files to the user's downloads folder.
// Or the destination they choose.
// Iterate over the files.
// Create a new blob.
const blob = new Blob([new Uint8Array(file.contents)])
// Save the file.
await browserSaveFile(blob, file.name)
}
} catch (e) {
// TODO: do something real with the error.
console.log('export error', e)
}
}
// Saves files locally from an export call.
export async function exportSave(data: ArrayBuffer) {
// This converts the ArrayBuffer to a Rust equivalent Vec<u8>.
let uintArray = new Uint8Array(data)
const files: ModelingAppFile[] = deserialize_files(uintArray)
if (files.length > 1) {
let zip = new JSZip()
for (const file of files) {
zip.file(file.name, new Uint8Array(file.contents), { binary: true })
}
return zip.generateAsync({ type: 'array' }).then((contents) => {
return save_({ name: 'output.zip', contents })
})
} else {
return save_(files[0])
}
}