Skip to content

Commit

Permalink
feat(playground): add file size checker and warning
Browse files Browse the repository at this point in the history
  • Loading branch information
pionxzh committed Jan 21, 2024
1 parent ab78a7f commit 61c6ab7
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion packages/playground/src/pages/Uploader.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ import { SharedDataVersion } from '../const'
import { unpack } from '../worker'
import type { TransformedModule } from '../types'
const INPUT_SIZE_WARNING = 1024 * 1024 * 5 // 5MB
const INPUT_SIZE_WARNING_MESSAGE = `The input file size exceeds ${INPUT_SIZE_WARNING / 1024 / 1024}MB. Processing may take longer and consume more memory than usual. If you experience an 'Out of Memory' error, please consider using the CLI for better performance.`
const route = useRoute()
const router = useRouter()
Expand Down Expand Up @@ -60,7 +63,16 @@ function onUpload(file: File) {
const reader = new FileReader()
reader.onload = (event) => {
const scriptContent = event.target?.result
if (!scriptContent || typeof scriptContent !== 'string') return
if (!scriptContent || typeof scriptContent !== 'string') {
// eslint-disable-next-line no-alert
alert('Invalid file content')
return
}
if (file.size > INPUT_SIZE_WARNING) {
// eslint-disable-next-line no-alert
alert(INPUT_SIZE_WARNING_MESSAGE)
}
resetModules()
startUnpack(scriptContent)
Expand Down

0 comments on commit 61c6ab7

Please sign in to comment.