Skip to content

Commit

Permalink
Merge pull request #2 from FitzwilliamMuseum/jn-fix-undefined-microgr…
Browse files Browse the repository at this point in the history
…aph-annotation

fix error on undefined micrograph annotation
  • Loading branch information
jonathanolamalu authored Oct 30, 2023
2 parents f1a9e83 + c07ca3f commit e652f84
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
8 changes: 6 additions & 2 deletions directus.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ export async function fetchMicrographAll() {
}

export async function fetchMicrograph(id) {
const response = await fetch(apiBase + "items/micrographs/" + id);
const url = apiBase + "items/micrographs/" + id;
console.log("fetchMicrograph url", url);
const response = await fetch(url);
return (await response.json()).data;
}

Expand All @@ -42,6 +44,8 @@ export async function downloadImage(id, outputFilePath, imageOptions) {
}

export async function fetchFileObject(id) {
const response = await fetch(apiBase + "files/" + id);
const url = apiBase + "files/" + id;
console.log("fetchFileObject url",url);
const response = await fetch(url);
return (await response.json()).data;
}
6 changes: 4 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,11 @@ async function main() {

const micrographId = data[fieldMap.annotation.key][j];

console.log("micrograph index", j);
console.log("micrographId", micrographId);
const currentItem = await fetchMicrograph(micrographId);
if (!currentItem || !currentItem.hotspot) continue
console.log("micrograph", j);
if (!currentItem || !currentItem.hotspot || !currentItem.micrograph) continue
console.log("micrograph hotspot", true);

const annotationItemId = basePath + path.join("annotation/tag/", currentItem.id.toString());
const targetCoords = `${currentItem[fieldMap.annotation.x]},${currentItem[fieldMap.annotation.y]},${currentItem[fieldMap.annotation.w]},${currentItem[fieldMap.annotation.h]}`;
Expand Down

0 comments on commit e652f84

Please sign in to comment.