diff options
| author | Mar0xy <marie@kaifa.ch> | 2023-11-12 18:19:44 +0100 |
|---|---|---|
| committer | Mar0xy <marie@kaifa.ch> | 2023-11-12 18:19:44 +0100 |
| commit | 1f8c12b984adb7383c006cfd2029b593df40d0dc (patch) | |
| tree | 0dc7f62465eb41af5dd95e02dfa0a7e6bceb75c9 /packages/backend/src/queue | |
| parent | fix: broken unicode in strings on IG imports (diff) | |
| download | sharkey-1f8c12b984adb7383c006cfd2029b593df40d0dc.tar.gz sharkey-1f8c12b984adb7383c006cfd2029b593df40d0dc.tar.bz2 sharkey-1f8c12b984adb7383c006cfd2029b593df40d0dc.zip | |
fix: use a proper function
Diffstat (limited to 'packages/backend/src/queue')
| -rw-r--r-- | packages/backend/src/queue/processors/ImportNotesProcessorService.ts | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/packages/backend/src/queue/processors/ImportNotesProcessorService.ts b/packages/backend/src/queue/processors/ImportNotesProcessorService.ts index e913d3da27..607d4d19a5 100644 --- a/packages/backend/src/queue/processors/ImportNotesProcessorService.ts +++ b/packages/backend/src/queue/processors/ImportNotesProcessorService.ts @@ -364,9 +364,17 @@ export class ImportNotesProcessorService { let title; const files: MiDriveFile[] = []; + function decodeIGString(str: any) { + const arr = []; + for (let i = 0; i < str.length; i++) { + arr.push(str.charCodeAt(i)); + } + return Buffer.from(arr).toString('utf8'); + } + if (post.media && this.isIterable(post.media) && post.media.length > 1) { date = new Date(post.creation_timestamp * 1000); - title = post.title.encode('latin-1').decode('utf-8'); + title = decodeIGString(post.title); for await (const file of post.media) { const slashdex = file.uri.lastIndexOf('/'); const name = file.uri.substring(slashdex + 1); @@ -377,7 +385,7 @@ export class ImportNotesProcessorService { } } else if (post.media && this.isIterable(post.media) && !(post.media.length > 1)) { date = new Date(post.media[0].creation_timestamp * 1000); - title = post.media[0].title.encode('latin-1').decode('utf-8'); + title = decodeIGString(post.media[0].title); const slashdex = post.media[0].uri.lastIndexOf('/'); const name = post.media[0].uri.substring(slashdex + 1); const exists = await this.driveFilesRepository.findOneBy({ name: name, userId: user.id }) ?? await this.driveFilesRepository.findOneBy({ name: `${name}.jpg`, userId: user.id }) ?? await this.driveFilesRepository.findOneBy({ name: `${name}.mp4`, userId: user.id }); |