Skip to content

Commit 0fd1c80

Browse files
committed
feat: update code storage management to include size validation and improve state handling
1 parent b0af1d9 commit 0fd1c80

1 file changed

Lines changed: 9 additions & 7 deletions

File tree

website/composables/state.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,17 @@ const PREFIX = 'js-deobfuscator:'
2929
export const loading = ref<'parse' | false>(false)
3030
const codeStorageKey = `${PREFIX}code`
3131
const localCode = useLocalStorage<string>(codeStorageKey, '')
32+
const codeValue = ref<string>(localCode.value)
33+
const encoder = typeof TextEncoder !== 'undefined' ? new TextEncoder() : undefined
34+
const MAX_BYTES = 1024 * 1024
35+
3236
export const code = computed<string>({
33-
get: () => localCode.value,
37+
get: () => codeValue.value,
3438
set: (val) => {
35-
const lines = val.split('\n').length
36-
if (lines > 2000) {
37-
localCode.value = ''
38-
return
39-
}
40-
localCode.value = val
39+
codeValue.value = val
40+
const size = encoder ? encoder.encode(val).length : val.length
41+
if (size <= MAX_BYTES)
42+
localCode.value = val
4143
},
4244
})
4345
export const error = shallowRef<unknown>()

0 commit comments

Comments
 (0)