Skip to content
This repository has been archived by the owner on Jan 31, 2024. It is now read-only.

Commit

Permalink
fix: attachments not working on FB import
Browse files Browse the repository at this point in the history
  • Loading branch information
Mar0xy committed Nov 22, 2023
1 parent d078a72 commit 81c3690
Showing 1 changed file with 13 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,7 @@ export class ImportNotesProcessorService {
return;
}

if (!this.isIterable(post.data) || !post.data[0].post) return;
if (!this.isIterable(post.data) || this.isIterable(post.data) && post.data[0].post === undefined) return;

const date = new Date(post.timestamp * 1000);
const title = decodeFBString(post.data[0].post);
Expand All @@ -583,12 +583,18 @@ export class ImportNotesProcessorService {
return Buffer.from(arr).toString('utf8');
}

if (post.attachments && this.isIterable(post.attachments) && this.isIterable(post.attachments.data)) {
for await (const file of post.attachments.data) {
if (!file.media) return;
const slashdex = file.media.uri.lastIndexOf('/');
const name = file.media.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 });
if (post.attachments && this.isIterable(post.attachments)) {
const media = [];
for await (const data of post.attachments[0].data) {
if (data.media) {
media.push(data.media);
}
}

for await (const file of media) {
const slashdex = file.uri.lastIndexOf('/');
const name = file.uri.substring(slashdex + 1);
const exists = await this.driveFilesRepository.findOneBy({ name: name, userId: user.id });
if (exists) {
files.push(exists);
}
Expand Down

0 comments on commit 81c3690

Please sign in to comment.