Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Apple Notes bugs #146

Merged
merged 10 commits into from
Oct 24, 2023
20 changes: 15 additions & 5 deletions src/formats/apple-notes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -349,13 +349,14 @@ export class AppleNotesImporter extends FormatImporter {
}

try {
const attachmentPath = await this.getAttachmentPath(this.resolvedFiles[row.ZNOTE]);
mirnovov marked this conversation as resolved.
Show resolved Hide resolved
sourcePath = path.join(this.resolvedAccounts[this.owners[row.ZNOTE]].path, sourcePath);
const binary = await this.getAttachmentSource(this.resolvedAccounts[this.owners[row.ZNOTE]], sourcePath);
//@ts-ignore
const outPath = this.app.vault.getAvailablePath(
`${await this.getAttachmentPath(this.resolvedFiles[row.ZNOTE])}/${outName}`, outExt
);

file = await this.vault.createBinary(
//@ts-ignore
this.app.vault.getAvailablePath(`${attachmentPath}/${outName}`, outExt),
await fsPromises.readFile(sourcePath),
outPath, binary,
{ ctime: this.decodeTime(row.ZCREATIONDATE), mtime: this.decodeTime(row.ZMODIFICATIONDATE) }
);
}
Expand All @@ -380,6 +381,15 @@ export class AppleNotesImporter extends FormatImporter {
return Math.floor((timestamp + CORETIME_OFFSET) * 1000);
}

async getAttachmentSource(account: ANAccount, sourcePath: string): Promise<Buffer> {
try {
return await fsPromises.readFile(path.join(account.path, sourcePath));
}
catch (e) {
return await fsPromises.readFile(path.join(NOTE_FOLDER_PATH, sourcePath));
}
}

async getAttachmentPath(note: TFile): Promise<string> {
if (this.cachedAttachmentPath) return this.cachedAttachmentPath;

Expand Down