forked from AkkomaGang/akkoma-fe
Fix settings export/import with non-ASCII content
This commit is contained in:
parent
af97dd7484
commit
28d180e944
1 changed files with 7 additions and 2 deletions
|
@ -4,11 +4,14 @@ export const newExporter = ({
|
||||||
}) => ({
|
}) => ({
|
||||||
exportData () {
|
exportData () {
|
||||||
const stringified = JSON.stringify(getExportedObject(), null, 2) // Pretty-print and indent with 2 spaces
|
const stringified = JSON.stringify(getExportedObject(), null, 2) // Pretty-print and indent with 2 spaces
|
||||||
|
const bytes = new TextEncoder().encode(stringified)
|
||||||
|
const ascii = Array.from(bytes, (x) => String.fromCodePoint(x)).join("")
|
||||||
|
const data = window.btoa(ascii)
|
||||||
|
|
||||||
// Create an invisible link with a data url and simulate a click
|
// Create an invisible link with a data url and simulate a click
|
||||||
const e = document.createElement('a')
|
const e = document.createElement('a')
|
||||||
e.setAttribute('download', `${filename}.json`)
|
e.setAttribute('download', `${filename}.json`)
|
||||||
e.setAttribute('href', 'data:application/json;base64,' + window.btoa(stringified))
|
e.setAttribute('href', 'data:application/json;base64,' + data)
|
||||||
e.style.display = 'none'
|
e.style.display = 'none'
|
||||||
|
|
||||||
document.body.appendChild(e)
|
document.body.appendChild(e)
|
||||||
|
@ -33,7 +36,9 @@ export const newImporter = ({
|
||||||
const reader = new FileReader()
|
const reader = new FileReader()
|
||||||
reader.onload = ({ target }) => {
|
reader.onload = ({ target }) => {
|
||||||
try {
|
try {
|
||||||
const parsed = JSON.parse(target.result)
|
const bytes = Uint8Array.from(target.result, (x) => x.codePointAt(0))
|
||||||
|
const data = new TextDecoder().decode(bytes)
|
||||||
|
const parsed = JSON.parse(data)
|
||||||
const validationResult = validator(parsed)
|
const validationResult = validator(parsed)
|
||||||
if (validationResult === true) {
|
if (validationResult === true) {
|
||||||
onImport(parsed)
|
onImport(parsed)
|
||||||
|
|
Loading…
Reference in a new issue