Skip to content

Commit

Permalink
Pass in library ID when retrieving attachments
Browse files Browse the repository at this point in the history
  • Loading branch information
mgmeyers committed May 11, 2024
1 parent f57a955 commit 98bfb9d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 18 deletions.
29 changes: 12 additions & 17 deletions src/bbt/export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -608,8 +608,8 @@ export async function exportToMarkdown(
// Further down below, when the Markdown file path has been sanitized, we associate the path to the key.
const createdOrUpdatedMarkdownFiles: string[] = [];

for (let i = 0, len = itemData.length; i < len; i++) {
await processItem(itemData[i], importDate, database, exportFormat.cslStyle);
for (const item of itemData) {
await processItem(item, importDate, database, exportFormat.cslStyle);
}

const vaultRoot = getVaultRoot();
Expand Down Expand Up @@ -844,15 +844,15 @@ export async function renderCiteTemplate(params: RenderCiteTemplateParams) {

const output: string[] = [];

for (let i = 0, len = itemData.length; i < len; i++) {
await processItem(itemData[i], importDate, database, format.cslStyle);
for (const item of itemData) {
await processItem(item, importDate, database, format.cslStyle);

const attachments = (itemData[i].attachments as any[]) || [];
const attachments = (item.attachments as any[]) || [];
const firstPDF = attachments.find((a) => !!a.path?.endsWith('.pdf'));

const templateData = {
attachment: firstPDF || attachments.length ? attachments[0] : null,
...itemData[i],
...item,
};

output.push(await renderTemplate('', format.template, templateData));
Expand Down Expand Up @@ -892,20 +892,15 @@ export async function dataExplorerPrompt(settings: ZoteroConnectorSettings) {

const importDate = moment();
const style = getAStyle(settings);

for (let i = 0, len = itemData.length; i < len; i++) {
await processItem(itemData[i], importDate, database, style);
}

const vaultRoot = getVaultRoot();

for (let i = 0, len = itemData.length; i < len; i++) {
const item = itemData[i];
for (const item of itemData) {
await processItem(item, importDate, database, style);

const attachments = item.attachments;
const attachmentData = await getAttachmentData(item, database);

for (let j = 0, jLen = attachments.length; j < jLen; j++) {
const attachment = attachments[j];
for (const attachment of attachments) {
const attachmentPath = attachment.path;
if (!attachmentPath?.endsWith('.pdf')) continue;

Expand All @@ -917,7 +912,7 @@ export async function dataExplorerPrompt(settings: ZoteroConnectorSettings) {
annots.push(
convertNativeAnnotation(
annot,
attachments[j],
attachment,
path.join(vaultRoot, 'output_path'),
'base_name',
'output_path'
Expand Down Expand Up @@ -951,7 +946,7 @@ export async function dataExplorerPrompt(settings: ZoteroConnectorSettings) {
let extracted = JSON.parse(res);

for (const e of extracted) {
processAnnotation(e, attachments[j], 'output_path');
processAnnotation(e, attachment, 'output_path');
}

if (settings.shouldConcat && extracted.length) {
Expand Down
2 changes: 1 addition & 1 deletion src/bbt/jsonRPC.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ export async function getAttachmentsFromCiteKey(
body: JSON.stringify({
jsonrpc: '2.0',
method: 'item.attachments',
params: [citeKey.key],
params: [citeKey.key, citeKey.library],
}),
headers: defaultHeaders,
});
Expand Down

0 comments on commit 98bfb9d

Please sign in to comment.