From 970432dcfb9d6727cd05c208ab9a2eed0c44814a Mon Sep 17 00:00:00 2001 From: ltctceplrm <14954927+ltctceplrm@users.noreply.github.com> Date: Mon, 12 May 2025 14:06:02 +0200 Subject: [PATCH] Reinstated check if file already exists Plugin will no longer download a poster if it already exists, to avoid unnecessary downloads and in case the user has modified the saved image themselves --- README.md | 1 + src/main.ts | 8 +++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 79dd6f8..dd48ea0 100644 --- a/README.md +++ b/README.md @@ -37,6 +37,7 @@ Available variables that can be used in template tags are the same variables fro I also published my own templates [here](https://github.com/mProjectsCode/obsidian-media-db-templates). #### Download poster images + Allows you to automatically download the poster images for a new media, ensuring offline access. The images are saved as `type_title (year)` e.g. `movie_The Perfect Storm (2000)` with a user chosen save location. #### Metadata field customization diff --git a/src/main.ts b/src/main.ts index 8240617..6128cd4 100644 --- a/src/main.ts +++ b/src/main.ts @@ -327,9 +327,11 @@ export default class MediaDbPlugin extends Plugin { await this.app.vault.createFolder(this.settings.imageFolder); } - const response = await requestUrl({ url: imageurl, method: 'GET' }); - await this.app.vault.createBinary(imagepath, response.arrayBuffer); - + if (!this.app.vault.getAbstractFileByPath(imagepath)) { + const response = await requestUrl({ url: imageurl, method: 'GET' }); + await this.app.vault.createBinary(imagepath, response.arrayBuffer); + } + // Update model to use local image path mediaTypeModel.image = `[[${imagepath}]]`; } catch (e) {