A self-hosted media server and file management system
Vue ffmpegfile-serverjellyfinlaravelmediamedia-playermedia-servermediabrowsermediaservermusicmusic-librarymusic-playermusicplayerself-hostedvuejs
feat: docker compatibility and better cross platform compatibility with puppeteer
aminnausinbfb513ef0ca1
diff --git a/app/Services/PreviewGeneratorService.php b/app/Services/PreviewGeneratorService.phpindex a0f2d6bd..47d3c9a3 100644--- a/app/Services/PreviewGeneratorService.php+++ b/app/Services/PreviewGeneratorService.php@@ -20,7 +20,8 @@ class PreviewGeneratorService {public function __construct(protected PathResolverService $pathResolver,protected FileJobService $fileJobService,- ) {}+ ) {+ }public function handle(Request $request): Response {$defaultData = $this->defaultData($request);@@ -52,15 +53,15 @@ class PreviewGeneratorService {public function handleGenerateImage(array $data, string $relativePath, ?int $dataLastUpdated = 0, bool $queued = true): ?string {try {- $override = false; // config('services.preview_generator.override');+ $override = config('services.preview_generator.override');$relativePath = trim('previews/' . $relativePath, '/') . '.png';$fullPath = Storage::disk('public')->path($relativePath);-if (! Storage::disk('public')->exists($relativePath)) {$queued = false;} elseif (! $override && Storage::disk('public')->exists($relativePath) && ! is_null($dataLastUpdated) && filemtime($fullPath) > $dataLastUpdated) {return VerifyFiles::getPathUrl($relativePath);}+if (! $override && $queued) {$this->fileJobService->regeneratePreviewImages([['data' => $data, 'path' => $relativePath]]);@@ -103,7 +104,7 @@ class PreviewGeneratorService {'thumbnail_url' => $thumbnail,'upload_date' => $this->formatDate($folderResource->series->date_created),'content_string' => $contentString,- 'tags' => $folderResource->series->folder_tags ? array_map(fn ($tag) => $tag->name, $folderResource->series->folder_tags) : null,+ 'tags' => $folderResource->series->folder_tags ? array_map(fn($tag) => $tag->name, $folderResource->series->folder_tags) : null,'url' => $request->fullUrl(),];@@ -133,7 +134,7 @@ class PreviewGeneratorService {'release_date' => $releaseDate,'upload_date' => $this->formatDate($video->metadata->date_uploaded),'mime_type' => $video->mime_type,- 'tags' => $videoResource->video_tags ? array_map(fn ($tag) => $tag->name, $videoResource->video_tags) : null,+ 'tags' => $videoResource->video_tags ? array_map(fn($tag) => $tag->name, $videoResource->video_tags) : null,'studio' => ucfirst($folderResource?->series?->studio),'url' => $request->fullUrl(),];@@ -159,27 +160,41 @@ class PreviewGeneratorService {Storage::disk('public')->makeDirectory(dirname($relativePath));- $html = view('og-media-preview', $data)->render();+ $html = $this->generatePreviewPage($data);+$browsershot = Browsershot::html($html)->windowSize(1200, 630)->deviceScaleFactor(2)->waitUntilNetworkIdle()->setOption('args', ['--no-sandbox',+ '--disable-setuid-sandbox',+ '--disable-dev-shm-usage','--user-data-dir=/tmp/chromium-profile',+ '--disable-web-security',+ '--font-render-hinting=none',])->ignoreConsoleErrors()->setEnvironmentOptions(['CHROME_CONFIG_HOME' => storage_path('app/chrome/.config'),]);- if (file_exists('/run/current-system/sw/bin/chromium')) {- $browsershot->setChromePath('/run/current-system/sw/bin/chromium');- } elseif (file_exists('node_modules/@sparticuz/chromium/bin/chromium')) {- $browsershot->setChromePath(base_path('node_modules/@sparticuz/chromium/bin/chromium'));- } elseif ($this->canUseDocker()) {- $browsershot->useDocker();- } elseif (file_exists('/usr/bin/chromium') || file_exists('/usr/bin/chromium-browser')) {- $browsershot->setChromePath('/usr/bin/chromium');- } else {- throw new \RuntimeException('No Chromium or Docker available for Browsershot.');++ $puppeteerExe = $this->getPuppeteerChromiumPath();++ if (str_contains($puppeteerExe, 'puppeteer-cache')) {+ $browsershot->setChromePath($puppeteerExe);+ // Using puppeteer within docker+ }++ if (! $puppeteerExe) {+ if (file_exists('/run/current-system/sw/bin/chromium')) {+ $browsershot->setChromePath('/run/current-system/sw/bin/chromium');+ } elseif (file_exists('/usr/bin/chromium') || file_exists('/usr/bin/chromium-browser')) {+ $browsershot->setChromePath('/usr/bin/chromium');+ } elseif ($this->canUseDocker()) {+ $browsershot->useDocker();+ } else {+ throw new \RuntimeException('No Chromium or Docker available for Browsershot.');+ }}+$browsershot->save($tempPath);$imageContents = file_get_contents($tempPath);@@ -213,6 +228,91 @@ class PreviewGeneratorService {}}+ protected function canUseDocker(): bool {+ try {+ $dockerInfo = shell_exec('docker info --format "{{.ServerVersion}}" 2>&1');++ return ! empty($dockerInfo) && ! str_contains(strtolower($dockerInfo), 'error');+ } catch (\Throwable $e) {+ return false;+ }+ }++ protected function getPuppeteerChromiumPath(): string {+ try {+ // Determine user home directory+ $homeDir = getenv('HOME') ?: getenv('USERPROFILE');+ if (! $homeDir) {+ throw new \RuntimeException('Unable to resolve home directory.');+ }++ // Chromium cache path+ $cacheDir = $homeDir . '/.cache/puppeteer/chrome';+ if (! is_dir($cacheDir)) {+ throw new \RuntimeException("Chromium not found in Puppeteer cache: {$cacheDir}");+ }++ return $this->resolveChromiumBinary($cacheDir);+ } catch (\Throwable $th) {+ Log::warning('No puppeteer chromium binary found.', [+ 'error' => $th->getMessage(),+ 'trace' => $th->getTraceAsString(),+ ]);++ return '';+ }+ }++ protected function resolveChromiumBinary(string $baseDir): ?string {+ if (! is_dir($baseDir)) {+ Log::alert('Dir is invalid', [$baseDir]);++ return null;+ }++ $platform = PHP_OS_FAMILY;+ $versions = glob($baseDir . '/*', GLOB_ONLYDIR);++ if (! $versions || empty($versions[0])) {+ // throw new \RuntimeException("No Chromium versions found in: {$baseDir}");+ return null;+ }++ foreach ($versions as $versionDir) {+ $binary = match ($platform) {+ 'Windows' => $versionDir . '/chrome-win64/chrome.exe',+ 'Darwin' => $versionDir . '/chrome-mac/Chromium.app/Contents/MacOS/Chromium',+ default => $versionDir . '/chrome-linux64/chrome',+ };++ if (file_exists($binary)) {+ return $binary;+ }+ // throw new \RuntimeException("Chromium binary not found at: {$binary}");+ }++ return null;+ }++ protected function generatePreviewPage(array $data): string {+ $appURL = config('app.host', 'app.test');++ $appScheme = config('app.scheme') . '://' . $appURL;+ $nonAppScheme = ($appScheme === 'https' ? 'http' : 'https') . '://' . $appURL;++ $internalURL = $appURL . config('app.port', $appScheme === 'https' ? 443 : 80);+++ $html = view('og-media-preview', $data)->render();++ // Have to manage what the local url is and effectively replace the public url. Chrome on the server system may not see the public url if any proxy is done on another system++ $html = str_replace($nonAppScheme, $appScheme, $html); // replacing external scheme with internal scheme (http for docker, https for standard)+ $html = str_replace($appURL . '/', $internalURL . '/', $html); // replacing external port (80 or 443) with internal port (8080 on docker or 443 on standard)++ return $html;+ }+protected function getMediaReleaseSeason(?string $dateString): ?string {if (! $dateString) {return null;@@ -248,16 +348,6 @@ class PreviewGeneratorService {return json_decode(json_encode($resource));}- protected function canUseDocker(): bool {- try {- $dockerInfo = shell_exec('docker info --format "{{.ServerVersion}}" 2>&1');-- return ! empty($dockerInfo) && ! str_contains(strtolower($dockerInfo), 'error');- } catch (\Throwable $e) {- return false;- }- }-protected function formatDate(?string $date, ?string $errorMessage = 'Unknown Date') {if (! $date) {return $errorMessage;diff --git a/config/app.php b/config/app.phpindex 591d23a4..1445c1c2 100755--- a/config/app.php+++ b/config/app.php@@ -57,6 +57,8 @@ return ['url' => env('APP_URL', 'http://localhost'),'host' => env('APP_HOST', 'app.test'),+ 'scheme' => env('APP_SCHEME', 'http'),+ 'port' => env('APP_PORT', 8080),/*|--------------------------------------------------------------------------diff --git a/docker/.env.docker b/docker/.env.dockerindex 008f4ce9..22354b64 100644--- a/docker/.env.docker+++ b/docker/.env.docker@@ -1,26 +1,26 @@######################### USER CONFIG #########################-APP_SCHEME=http # App Protocol -> http OR https -> Should not change-APP_HOST=app.test # App URL -> Website will be available on https://app.test if you use caddy and http://app.test:8080 otherwise-APP_PORT=8080 # App Port -> Website will be available on https://app.test if you use caddy and http://app.test:8080 otherwise-REVERB_PORT=443 # Websocket Port -> Set to 6001 if you have websocket connection issues-REVERB_SCHEME=https # Websocket Protocol -> http OR https -> Set to HTTPS if you have a valid SSL Certificate for your URL+APP_SCHEME=http # App Protocol -> http OR https -> Should not change+APP_HOST=app.test # App URL -> Website will be available on https://app.test if you use caddy and http://app.test:8080 otherwise+APP_PORT=8080 # App Port -> Website will be available on https://app.test if you use caddy and http://app.test:8080 otherwise+REVERB_PORT=443 # Websocket Port -> Set to 6001 if you have websocket connection issues+REVERB_SCHEME=https # Websocket Protocol -> http OR https -> Set to HTTPS if you have a valid SSL Certificate for your URL-APP_ENV=local # App Environment -> change to staging if you are using a valid domain or production server+APP_ENV=local # App Environment -> change to staging if you are using a valid domain or production server-DB_HOST=database # Database URL -> points to the docker compose database -> if you already have a database running elsewhere, provide that URL here-DB_PORT=5432 # Database PORT -> points to the docker compose database -> if you already have a database running elsewhere, provide that URL here-DB_DATABASE=mediaServer # Database Name -> if you are using another database, make sure a database with this name exists-DB_USERNAME=postgres # Database Username -> if you are using another database, provide your credentials here-DB_PASSWORD=root # Database Password -> if you are using another database, provide your credentials here+DB_HOST=database # Database URL -> points to the docker compose database -> if you already have a database running elsewhere, provide that URL here+DB_PORT=5432 # Database PORT -> points to the docker compose database -> if you already have a database running elsewhere, provide that URL here+DB_DATABASE=mediaServer # Database Name -> if you are using another database, make sure a database with this name exists+DB_USERNAME=postgres # Database Username -> if you are using another database, provide your credentials here+DB_PASSWORD=root # Database Password -> if you are using another database, provide your credentials here-TRUSTED_PROXIES=* # Trusted Proxies -> change to the ip address of your reverse proxies if you have issues-DOCKER_RELEASE=latest # Docker Release Tag -> can set to latest or beta depending on which image you want to use+TRUSTED_PROXIES=* # Trusted Proxies -> change to the ip address of your reverse proxies if you have issues+DOCKER_RELEASE=latest # Docker Release Tag -> can set to latest or beta depending on which image you want to use-PLAUSIBLE_SCRIPT_URL= # Plausible URL -> url to plausible js file to monitor your website-PLAUSIBLE_DOMAIN= # Plausible DOMAIN -> the domain for your plausible website-PLAUSIBLE_SITE_ID= # Plausible SITE ID -> id for your site on plausible (probably your url)-PLAUSIBLE_API_TOKEN= # Plausible API TOKEN-> token for accessing plausible stats in realtime+PLAUSIBLE_SCRIPT_URL= # Plausible URL -> url to plausible js file to monitor your website+PLAUSIBLE_DOMAIN= # Plausible DOMAIN -> the domain for your plausible website+PLAUSIBLE_SITE_ID="${APP_HOST}" # Plausible SITE ID -> id for your site on plausible (probably your url)+PLAUSIBLE_API_TOKEN= # Plausible API TOKEN-> token for accessing plausible stats in realtime-CF= # CLOUDFLARE TOKEN -> unused for now+CF= # CLOUDFLARE TOKEN -> unused for nowdiff --git a/package-lock.json b/package-lock.jsonindex 4af37cc6..5b48cf48 100755--- a/package-lock.json+++ b/package-lock.json@@ -15,7 +15,7 @@"lodash.clonedeep": "^4.5.0","lodash.isequal": "^4.5.0","pinia": "^2.1.7",- "puppeteer": "^24.7.0",+ "puppeteer": "^24.7.2","vue": "^3.4.29","vue-chartjs": "^5.3.2","vue-loader": "^17.4.2",@@ -1292,9 +1292,9 @@}},"node_modules/@puppeteer/browsers": {- "version": "2.10.1",- "resolved": "https://registry.npmjs.org/@puppeteer/browsers/-/browsers-2.10.1.tgz",- "integrity": "sha512-NgghEvl9fTZdXvxBHMgTlEVrjhDsbOfXgXzoarsV6o/arp2SvOOzZfFlKpxwLHJo7vVULq9Q/Dg76lUddLxgog==",+ "version": "2.10.2",+ "resolved": "https://registry.npmjs.org/@puppeteer/browsers/-/browsers-2.10.2.tgz",+ "integrity": "sha512-i4Ez+s9oRWQbNjtI/3+jxr7OH508mjAKvza0ekPJem0ZtmsYHP3B5dq62+IaBHKaGCOuqJxXzvFLUhJvQ6jtsQ==","license": "Apache-2.0","dependencies": {"debug": "^4.4.0",@@ -3117,9 +3117,9 @@}},"node_modules/chromium-bidi": {- "version": "4.0.1",- "resolved": "https://registry.npmjs.org/chromium-bidi/-/chromium-bidi-4.0.1.tgz",- "integrity": "sha512-oRgKuzRQYXEUBlrlXWeBbot0KLyFOAwTe0pt3EJYZ1I0yvvr1dl6zhnUxlkKvSAk0pin+c1SxeuxBILISEgIEw==",+ "version": "4.1.1",+ "resolved": "https://registry.npmjs.org/chromium-bidi/-/chromium-bidi-4.1.1.tgz",+ "integrity": "sha512-biR7t4vF3YluE6RlMSk9IWk+b9U+WWyzHp+N2pL9vRTk+UXHYRTVp7jTK58ZNzMLBgoLMHY4QyJMbeuw3eKxqg==","license": "Apache-2.0","dependencies": {"mitt": "^3.0.1",@@ -6492,17 +6492,17 @@}},"node_modules/puppeteer": {- "version": "24.7.0",- "resolved": "https://registry.npmjs.org/puppeteer/-/puppeteer-24.7.0.tgz",- "integrity": "sha512-txRZf6QPYEBhnyzzPMCvWm20tstDbbN+j2e9L6+ib4Q+/9+d2V2CPfFnF0mbcW3txEwDlYrN84YLRYpS9/eSOw==",+ "version": "24.7.2",+ "resolved": "https://registry.npmjs.org/puppeteer/-/puppeteer-24.7.2.tgz",+ "integrity": "sha512-ifYqoY6wGs0yZeFuFPn8BE9FhuveXkarF+eO18I2e/axdoCh4Qh1AE+qXdJBhdaeoPt6eRNTY4Dih29Jbq8wow==","hasInstallScript": true,"license": "Apache-2.0","dependencies": {- "@puppeteer/browsers": "2.10.1",- "chromium-bidi": "4.0.1",+ "@puppeteer/browsers": "2.10.2",+ "chromium-bidi": "4.1.1","cosmiconfig": "^9.0.0","devtools-protocol": "0.0.1425554",- "puppeteer-core": "24.7.0",+ "puppeteer-core": "24.7.2","typed-query-selector": "^2.12.0"},"bin": {@@ -6513,13 +6513,13 @@}},"node_modules/puppeteer-core": {- "version": "24.7.0",- "resolved": "https://registry.npmjs.org/puppeteer-core/-/puppeteer-core-24.7.0.tgz",- "integrity": "sha512-NEqVstBfP8S0L2PSLbGAVuLPXuvE83zfOf0qo3TadfzT62liurQJL5EC0XZ0dGxs5auBPHYncyJUwQymJuk/Hw==",+ "version": "24.7.2",+ "resolved": "https://registry.npmjs.org/puppeteer-core/-/puppeteer-core-24.7.2.tgz",+ "integrity": "sha512-P9pZyTmJqKODFCnkZgemCpoFA4LbAa8+NumHVQKyP5X9IgdNS1ZnAnIh1sMAwhF8/xEUGf7jt+qmNLlKieFw1Q==","license": "Apache-2.0","dependencies": {- "@puppeteer/browsers": "2.10.1",- "chromium-bidi": "4.0.1",+ "@puppeteer/browsers": "2.10.2",+ "chromium-bidi": "4.1.1","debug": "^4.4.0","devtools-protocol": "0.0.1425554","typed-query-selector": "^2.12.0",diff --git a/package.json b/package.jsonindex f7a36c72..b8b018b9 100755--- a/package.json+++ b/package.json@@ -87,7 +87,7 @@"lodash.clonedeep": "^4.5.0","lodash.isequal": "^4.5.0","pinia": "^2.1.7",- "puppeteer": "^24.7.0",+ "puppeteer": "^24.7.2","vue": "^3.4.29","vue-chartjs": "^5.3.2","vue-loader": "^17.4.2",diff --git a/resources/js/composables/useMultiSelect.js b/resources/js/composables/useMultiSelect.jsindex ce9542a7..ac6b2f5c 100644--- a/resources/js/composables/useMultiSelect.js+++ b/resources/js/composables/useMultiSelect.js@@ -36,6 +36,7 @@ export default function useMultiSelect({ options, defaultItems }, refs) {if (focus) activeElement.focus({ preventScroll: false });},selectKeydown(event) {+ // Handles input and therefore searchif (event.keyCode < 65 || event.keyCode > 90) return;this.selectKeydownValue += event.key;diff --git a/resources/views/og-media-preview.blade.php b/resources/views/og-media-preview.blade.phpindex d49388b2..d4147266 100644--- a/resources/views/og-media-preview.blade.php+++ b/resources/views/og-media-preview.blade.php@@ -1,12 +1,6 @@<!DOCTYPE html><html lang="en">-@php-$thumbnail_url = str_replace('http://', 'https://', $thumbnail_url ?? '');-$banner_url = str_replace('http://', 'https://', $banner_url ?? $thumbnail_url);-@endphp--<head><meta charset="UTF-8">@vite('resources/css/app.css')