From b0b1d2707d46835aaceee669735c26b8b70000d3 Mon Sep 17 00:00:00 2001
From: advplyr <advplyr@protonmail.com>
Date: Tue, 12 Apr 2022 17:32:27 -0500
Subject: [PATCH] Add podcast episode date picker for pubDate

---
 .../components/modals/podcast/EditEpisode.vue | 20 ++++++++++++++++---
 client/components/ui/TextInput.vue            |  3 +++
 client/store/index.js                         |  2 +-
 server/managers/PodcastManager.js             |  3 +++
 4 files changed, 24 insertions(+), 4 deletions(-)

diff --git a/client/components/modals/podcast/EditEpisode.vue b/client/components/modals/podcast/EditEpisode.vue
index 6d715f21..fe482f2f 100644
--- a/client/components/modals/podcast/EditEpisode.vue
+++ b/client/components/modals/podcast/EditEpisode.vue
@@ -14,7 +14,7 @@
           <ui-text-input-with-label v-model="newEpisode.episodeType" label="Episode Type" />
         </div>
         <div class="w-1/3 p-1">
-          <ui-text-input-with-label v-model="newEpisode.pubDate" label="Pub Date" />
+          <ui-text-input-with-label v-model="pubDateInput" @input="updatePubDate" type="datetime-local" label="Pub Date" />
         </div>
         <div class="w-full p-1">
           <ui-text-input-with-label v-model="newEpisode.title" label="Title" />
@@ -55,8 +55,10 @@ export default {
         title: null,
         subtitle: null,
         description: null,
-        pubDate: null
-      }
+        pubDate: null,
+        publishedAt: null
+      },
+      pubDateInput: null
     }
   },
   watch: {
@@ -85,6 +87,15 @@ export default {
     }
   },
   methods: {
+    updatePubDate(val) {
+      if (val) {
+        this.newEpisode.pubDate = this.$formatJsDate(new Date(val), 'E, d MMM yyyy HH:mm:ssxx')
+        this.newEpisode.publishedAt = new Date(val).valueOf()
+      } else {
+        this.newEpisode.pubDate = null
+        this.newEpisode.publishedAt = null
+      }
+    },
     init() {
       this.newEpisode.episode = this.episode.episode || ''
       this.newEpisode.episodeType = this.episode.episodeType || ''
@@ -92,6 +103,9 @@ export default {
       this.newEpisode.subtitle = this.episode.subtitle || ''
       this.newEpisode.description = this.episode.description || ''
       this.newEpisode.pubDate = this.episode.pubDate || ''
+      this.newEpisode.publishedAt = this.episode.publishedAt
+
+      this.pubDateInput = this.episode.pubDate ? this.$formatJsDate(new Date(this.episode.pubDate), "yyyy-MM-dd'T'HH:mm") : null
     },
     getUpdatePayload() {
       var updatePayload = {}
diff --git a/client/components/ui/TextInput.vue b/client/components/ui/TextInput.vue
index 5366ecb0..b7244688 100644
--- a/client/components/ui/TextInput.vue
+++ b/client/components/ui/TextInput.vue
@@ -83,4 +83,7 @@ input:read-only {
   color: #bbb;
   background-color: #444;
 }
+input::-webkit-calendar-picker-indicator {
+  filter: invert(1);
+}
 </style>
\ No newline at end of file
diff --git a/client/store/index.js b/client/store/index.js
index 64b18511..0c644400 100644
--- a/client/store/index.js
+++ b/client/store/index.js
@@ -34,7 +34,7 @@ export const getters = {
     return state.serverSettings[key]
   },
   getBookCoverAspectRatio: state => {
-    if (!state.serverSettings || !state.serverSettings.coverAspectRatio) return 1.6
+    if (!state.serverSettings || !state.serverSettings.coverAspectRatio) return 1
     return state.serverSettings.coverAspectRatio === 0 ? 1.6 : 1
   },
   getNumLibraryItemsSelected: state => state.selectedLibraryItems.length,
diff --git a/server/managers/PodcastManager.js b/server/managers/PodcastManager.js
index e7eea417..616ae658 100644
--- a/server/managers/PodcastManager.js
+++ b/server/managers/PodcastManager.js
@@ -79,6 +79,9 @@ class PodcastManager {
 
   async scanAddPodcastEpisodeAudioFile() {
     var libraryFile = await this.getLibraryFile(this.currentDownload.targetPath, this.currentDownload.targetRelPath)
+
+    // TODO: Set meta tags on new audio file
+
     var audioFile = await this.probeAudioFile(libraryFile)
     if (!audioFile) {
       return false