Skip to content

Commit

Permalink
fix: ensure folderPath exists
Browse files Browse the repository at this point in the history
  • Loading branch information
zxt-tzx committed Jan 22, 2024
1 parent 94b4dfd commit c06aed3
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions load.ts
Original file line number Diff line number Diff line change
Expand Up @@ -718,8 +718,16 @@ async function load() {
"tt0258000",
];

// Create the folder if it doesn't exist
const folderPath = "./data/imdb";
const imdbFolderExists = await fs
.stat(folderPath)
.then(() => true)
.catch(() => false);
if (!imdbFolderExists) await fs.mkdir(folderPath);

for (const id of ids) {
const path = `./data/imdb/${id}.html`;
const path = `${folderPath}/${id}.html`;
const exists = await fs
.stat(path)
.then(() => true)
Expand Down Expand Up @@ -762,7 +770,7 @@ async function load() {
const year = parseInt(
$("title")
.text()
.match(/\((\d+)\)/)?.[1] || "0",
.match(/\((\d+)\)/)?.[1] || "0"
);
const title = $("[data-testid=subtitle]").text().trim();
const summary = $("[data-testid=sub-section-summaries] li:first-child")
Expand All @@ -783,7 +791,7 @@ async function load() {
Key: "posters/" + id + ".jpg",
ContentType: "image/jpeg",
Body: await fetch(poster).then((res) => res.arrayBuffer() as any),
}),
})
);

await vector.remove({
Expand Down Expand Up @@ -830,7 +838,7 @@ async function load() {
year,
}),
},
}),
})
);
console.log("Finished", ++index);
});
Expand Down

0 comments on commit c06aed3

Please sign in to comment.