From 950baef58bfb4483820ce95a7a2d0024fc1afbfe Mon Sep 17 00:00:00 2001 From: paule Date: Wed, 1 Nov 2023 05:29:10 +0100 Subject: [PATCH] fix: Instagram import broken UTF8 characters --- resources/assets/components/AccountImport.vue | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/resources/assets/components/AccountImport.vue b/resources/assets/components/AccountImport.vue index b669345db..a4e5239bb 100644 --- a/resources/assets/components/AccountImport.vue +++ b/resources/assets/components/AccountImport.vue @@ -348,8 +348,16 @@ }, 500); }, + // Facebook and Instagram are encoding UTF8 characters in a weird way in their json + // here is a good explanation what's going wrong https://sorashi.github.io/fix-facebook-json-archive-encoding + fixFacebookEncoding(string) { + const replaced = string.replace(/\\u00([a-f0-9]{2})/g, (x) => String.fromCharCode(parseInt(x.slice(2), 16))); + const buffer = Array.from(replaced, (c) => c.charCodeAt(0)); + return new TextDecoder().decode(new Uint8Array(buffer)); + }, + filterPostMeta(media) { - let json = JSON.parse(media); + let json = JSON.parse(this.fixFacebookEncoding(media)); let res = json.filter(j => { let ids = j.media.map(m => m.uri).filter(m => { if(this.config.allow_video_posts == true) { @@ -396,12 +404,14 @@ this.filterPostMeta(media); let imgs = await Promise.all(entries.filter(entry => { - return entry.filename.startsWith('media/posts/') && (entry.filename.endsWith('.png') || entry.filename.endsWith('.jpg') || entry.filename.endsWith('.mp4')); + return (entry.filename.startsWith('media/posts/') || entry.filename.startsWith('media/other/')) && (entry.filename.endsWith('.png') || entry.filename.endsWith('.jpg') || entry.filename.endsWith('.mp4')); }) .map(async entry => { if( - entry.filename.startsWith('media/posts/') && - ( + ( + entry.filename.startsWith('media/posts/') || + entry.filename.startsWith('media/other/') + ) && ( entry.filename.endsWith('.png') || entry.filename.endsWith('.jpg') || entry.filename.endsWith('.mp4')