From 245fab0623bedd89b0a3e216ba902078ac693797 Mon Sep 17 00:00:00 2001 From: soraefir Date: Wed, 14 Jun 2023 15:46:43 +0200 Subject: [PATCH] Fix for multibyte ascii --- public/js/main.js | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/public/js/main.js b/public/js/main.js index e67b4bc..0285311 100644 --- a/public/js/main.js +++ b/public/js/main.js @@ -19,6 +19,35 @@ Date.prototype.toJSONLocal = (function() { }; }()) +function toEncoded(string) { + const codeUnits = Uint16Array.from( + { length: string.length }, + (element, index) => string.charCodeAt(index) + ); + const charCodes = new Uint8Array(codeUnits.buffer); + + let result = ""; + charCodes.forEach((char) => { + result += String.fromCharCode(char); + }); + return window.btoa(result); + } + + function toDecoded(string) { + let binary = window.atob(string) + const bytes = Uint8Array.from({ length: binary.length }, (element, index) => + binary.charCodeAt(index) + ); + const charCodes = new Uint16Array(bytes.buffer); + + let result = ""; + charCodes.forEach((char) => { + result += String.fromCharCode(char); + }); + return result; + } + + const query_nominatim = (q,f) => axios.get('/api/place/'+q).then(res=>res.data).then(res=>res.filter(f)) const query_flight = (q) => axios.get('/api/flight/'+q).then(res=>res.data) @@ -99,7 +128,7 @@ const app = new Vue({ }, add_section: function(event){ if(this.journey_data.main==undefined) this.journey_data.main=[]; - this.journey_data.main.push({map:{zoom:2}, hotel:{latlon:[0,0]},places:{restaurants:[],places:[]}}); + this.journey_data.main.push({step_title:"?",map:{zoom:2}, hotel:{latlon:[0,0]},places:{restaurants:[],places:[]}}); }, next_step: function(){ this.journey_step+=1; @@ -237,10 +266,10 @@ const app = new Vue({ }) }, import_data:function(){ - this.journey_data = Object.assign({}, JSON.parse(window.atob(this.impexp))); + this.journey_data = Object.assign({}, JSON.parse(toDecoded(this.impexp))); }, export_data:function(){ - this.impexp = window.btoa(JSON.stringify(this.journey_data)); + this.impexp = toEncoded(JSON.stringify(this.journey_data)); }, filter_selected:function(list,step){ return list.filter(e=>(step?(e.step==this.journey_step):(e.step>=0)))