Skip to content

A self-hosted media server and file management system

auto download folder thumbnails and use https production only

aminnausin1a2ff7669c82
diff --git a/app/Jobs/VerifyFiles.php b/app/Jobs/VerifyFiles.php
index bf2c91d3..01231f9e 100755
--- a/app/Jobs/VerifyFiles.php
+++ b/app/Jobs/VerifyFiles.php
@@ -351,7 +351,7 @@ class VerifyFiles implements ShouldQueue {
return ['title' => $title, 'description' => $description === '' ? null : $description, 'season' => $season, 'episode' => $episode];
}
- private function getPathUrl($path) {
+ public static function getPathUrl($path) {
/**
* @disregard P1013 Undefined method but it actually exists
*/
diff --git a/app/Jobs/VerifyFolders.php b/app/Jobs/VerifyFolders.php
index 7e20db31..f1d0a045 100644
--- a/app/Jobs/VerifyFolders.php
+++ b/app/Jobs/VerifyFolders.php
@@ -106,14 +106,15 @@ class VerifyFolders implements ShouldQueue {
if ($response->successful()) {
$imageContent = $response->body();
$extension = pathinfo($series->thumbnail_url, PATHINFO_EXTENSION);
- $path = 'public/thumbnails/' . explode('/', $series->composite_id ?? 'unsorted/unsorted')[0] . '/' . basename($series->id) . '.' . $extension;
- Storage::put($path, $imageContent);
+ $path = 'thumbnails/' . explode('/', $series->composite_id ?? 'unsorted/unsorted')[0] . '/' . basename($series->id) . '.webp';
+ Storage::disk('public')->put($path, $imageContent);
/**
* @disregard P1013 Undefined method but it actually exists
*/
- $changes['thumbnail_url'] = Storage::disk('public')->url($path);
- dump('got thumbnail for ' . $series->id);
+ $url = VerifyFiles::getPathUrl($path);
+ $changes['thumbnail_url'] = $url;
+ dump('got thumbnail for ' . $series->id . ' at ' . $url);
}
}
@@ -143,7 +144,7 @@ class VerifyFolders implements ShouldQueue {
return 'No Changes Found';
}
- Series::upsert($transactions, 'id', ['folder_id', 'title', 'episodes']);
+ Series::upsert($transactions, 'id', ['folder_id', 'title', 'episodes', 'thumbnail_url']);
$summary = 'Updated ' . count($transactions) . ' folders from id ' . ($transactions[0]['folder_id']) . ' to ' . ($transactions[count($transactions) - 1]['folder_id']);
dump($summary);
diff --git a/resources/js/components/cards/CategoryCard.vue b/resources/js/components/cards/CategoryCard.vue
index 84c3145b..821bfb1b 100644
--- a/resources/js/components/cards/CategoryCard.vue
+++ b/resources/js/components/cards/CategoryCard.vue
@@ -1,9 +1,9 @@
<script setup lang="ts">
import { type CategoryResource, type FolderResource } from '@/types/resources';
-import { formatFileSize, toFormattedDate } from '@/service/util';
-import { computed, ref, useTemplateRef, watch } from 'vue';
+import { formatFileSize, handleStorageURL, toFormattedDate } from '@/service/util';
import { startScanFilesTask, startVerifyFilesTask } from '@/service/siteAPI';
+import { computed, ref, useTemplateRef, watch } from 'vue';
import { useQueryClient } from '@tanstack/vue-query';
import { updateCategory } from '@/service/mediaAPI.ts';
import { toast } from '@/service/toaster/toastService';
@@ -91,7 +91,7 @@ watch(
<img
class="w-full h-full object-cover rounded-t-md shadow-sm mb-auto ring-1 ring-gray-900/5"
:src="
- defaultFolder?.series?.thumbnail_url ??
+ handleStorageURL(defaultFolder?.series?.thumbnail_url) ??
'https://m.media-amazon.com/images/M/MV5BMjVjZGU5ZTktYTZiNC00N2Q1LThiZjMtMDVmZDljN2I3ZWIwXkEyXkFqcGdeQXVyMTUzMTg2ODkz._V1_.jpg'
"
alt="Folder Cover Art"
diff --git a/resources/js/components/cards/CategoryFolderCard.vue b/resources/js/components/cards/CategoryFolderCard.vue
index 908ff880..176d6160 100644
--- a/resources/js/components/cards/CategoryFolderCard.vue
+++ b/resources/js/components/cards/CategoryFolderCard.vue
@@ -1,7 +1,7 @@
<script setup lang="ts">
import { type FolderResource } from '@/types/resources';
-import { formatFileSize, toFormattedDate } from '@/service/util';
+import { formatFileSize, handleStorageURL, toFormattedDate } from '@/service/util';
import { useTemplateRef } from 'vue';
import ButtonIcon from '@/components/inputs/ButtonIcon.vue';
@@ -24,7 +24,8 @@ const popover = useTemplateRef('popover');
<img
class="w-full h-full object-cover rounded-t-md shadow-sm mb-auto ring-1 ring-gray-900/5"
:src="
- data?.series?.thumbnail_url ?? 'https://m.media-amazon.com/images/M/MV5BMjVjZGU5ZTktYTZiNC00N2Q1LThiZjMtMDVmZDljN2I3ZWIwXkEyXkFqcGdeQXVyMTUzMTg2ODkz._V1_.jpg'
+ handleStorageURL(data?.series?.thumbnail_url) ??
+ 'https://m.media-amazon.com/images/M/MV5BMjVjZGU5ZTktYTZiNC00N2Q1LThiZjMtMDVmZDljN2I3ZWIwXkEyXkFqcGdeQXVyMTUzMTg2ODkz._V1_.jpg'
"
alt="Folder Cover Art"
/>
diff --git a/resources/js/components/cards/FolderCard.vue b/resources/js/components/cards/FolderCard.vue
index 1ecbadef..3f9b6b16 100755
--- a/resources/js/components/cards/FolderCard.vue
+++ b/resources/js/components/cards/FolderCard.vue
@@ -2,7 +2,7 @@
import type { ContextMenuItem } from '@/types/types';
import type { FolderResource } from '@/types/resources';
-import { formatFileSize } from '@/service/util';
+import { formatFileSize, handleStorageURL } from '@/service/util';
import { computed, ref } from 'vue';
import { useAppStore } from '@/stores/AppStore';
import { RouterLink } from 'vue-router';
@@ -45,7 +45,8 @@ const folderLink = ref(`/${props.categoryName}/${props.folder.name}`);
<template #content>
<img
:src="
- folder.series?.thumbnail_url ?? 'https://m.media-amazon.com/images/M/MV5BMjVjZGU5ZTktYTZiNC00N2Q1LThiZjMtMDVmZDljN2I3ZWIwXkEyXkFqcGdeQXVyMTUzMTg2ODkz._V1_.jpg'
+ handleStorageURL(folder.series?.thumbnail_url) ??
+ 'https://m.media-amazon.com/images/M/MV5BMjVjZGU5ZTktYTZiNC00N2Q1LThiZjMtMDVmZDljN2I3ZWIwXkEyXkFqcGdeQXVyMTUzMTg2ODkz._V1_.jpg'
"
alt="Folder Thumbnail"
class="hidden lg:block h-32 aspect-2/3 object-cover shadow-md"
@@ -63,7 +64,7 @@ const folderLink = ref(`/${props.categoryName}/${props.folder.name}`);
>
<img
:src="
- folder.series?.thumbnail_url ??
+ handleStorageURL(folder.series?.thumbnail_url) ??
'https://m.media-amazon.com/images/M/MV5BMjVjZGU5ZTktYTZiNC00N2Q1LThiZjMtMDVmZDljN2I3ZWIwXkEyXkFqcGdeQXVyMTUzMTg2ODkz._V1_.jpg'
"
alt="Folder Thumbnail"
diff --git a/resources/js/components/forms/EditFolder.vue b/resources/js/components/forms/EditFolder.vue
index 4f668ed0..1e419720 100644
--- a/resources/js/components/forms/EditFolder.vue
+++ b/resources/js/components/forms/EditFolder.vue
@@ -1,5 +1,5 @@
<script setup>
-import { toCalendarFormattedDate } from '@/service/util';
+import { handleStorageURL, toCalendarFormattedDate } from '@/service/util';
import { reactive } from 'vue';
import { toast } from '@/service/toaster/toastService';
@@ -87,7 +87,7 @@ const fields = reactive([
name: 'thumbnail_url',
text: 'Folder Thumbnail URL',
type: 'url',
- value: props.folder?.series?.thumbnail_url,
+ value: handleStorageURL(props.folder?.series?.thumbnail_url),
subtext: 'A thumbnail associated with the series',
default: null,
},
@@ -103,7 +103,7 @@ const form = useForm({
films: props.folder?.series?.films ?? null,
date_start: props.folder?.series?.date_start ? toCalendarFormattedDate(props.folder?.series?.date_start) : null,
date_end: props.folder?.series?.date_end ? toCalendarFormattedDate(props.folder?.series?.date_end) : null,
- thumbnail_url: props.folder?.series?.thumbnail_url ?? null,
+ thumbnail_url: handleStorageURL(props.folder?.series?.thumbnail_url) ?? null,
});
const handleSubmit = async () => {
diff --git a/resources/js/components/video/VideoInfoPanel.vue b/resources/js/components/video/VideoInfoPanel.vue
index 7101e93d..fc148040 100755
--- a/resources/js/components/video/VideoInfoPanel.vue
+++ b/resources/js/components/video/VideoInfoPanel.vue
@@ -1,4 +1,5 @@
<script setup>
+import { handleStorageURL } from '@/service/util';
import { useContentStore } from '@/stores/ContentStore';
import { useAuthStore } from '@/stores/AuthStore';
import { storeToRefs } from 'pinia';
@@ -79,7 +80,7 @@ watch(() => stateVideo.value, handlePropsUpdate, { immediate: true, deep: true }
id="folder-thumbnail"
class="h-full object-cover rounded-md aspect-2/3 ring-1 ring-gray-900/5"
:src="
- stateFolder?.series?.thumbnail_url ??
+ handleStorageURL(stateFolder?.series?.thumbnail_url) ??
'https://m.media-amazon.com/images/M/MV5BMjVjZGU5ZTktYTZiNC00N2Q1LThiZjMtMDVmZDljN2I3ZWIwXkEyXkFqcGdeQXVyMTUzMTg2ODkz._V1_.jpg'
"
alt="Folder Cover Art"
diff --git a/resources/js/components/video/VideoPlayer.vue b/resources/js/components/video/VideoPlayer.vue
index 794bfe2a..09b859a7 100755
--- a/resources/js/components/video/VideoPlayer.vue
+++ b/resources/js/components/video/VideoPlayer.vue
@@ -6,6 +6,7 @@ import type { Metadata, Series } from '@/types/model';
import { computed, onMounted, onUnmounted, ref, useTemplateRef, watch, type Ref } from 'vue';
import { UseCreatePlayback } from '@/service/mutations';
import { useVideoPlayback } from '@/service/queries';
+import { handleStorageURL } from '@/service/util';
import { useContentStore } from '@/stores/ContentStore';
import { useAppStore } from '@/stores/AppStore';
import { storeToRefs } from 'pinia';
@@ -171,15 +172,6 @@ const handlePlayVideo = (override = false) => {
handleProgress(true);
};
-const handleStorageURL = (url: string | undefined) => {
- if (!url) return null;
-
- if (window.location.protocol === 'http:' && url.startsWith(`https://${window.location.host}`)) return url.replace('https:', 'http:');
-
- if (window.location.protocol === 'https:' && url.startsWith(`http://${window.location.host}`)) return url.replace('http:', 'https:');
- return url;
-};
-
const handlePlayerSeeked = () => {
// add heatmap data ?
diff --git a/resources/js/service/util.ts b/resources/js/service/util.ts
index c611c104..30ffbde9 100644
--- a/resources/js/service/util.ts
+++ b/resources/js/service/util.ts
@@ -147,3 +147,12 @@ export function within24Hrs(date: string) {
return diffInHours < 24;
}
+
+export function handleStorageURL(url: string | undefined) {
+ if (!url) return null;
+
+ if (window.location.protocol === 'http:' && url.startsWith(`https://${window.location.host}`)) return url.replace('https:', 'http:');
+
+ if (window.location.protocol === 'https:' && url.startsWith(`http://${window.location.host}`)) return url.replace('http:', 'https:');
+ return url;
+}