Skip to content

A self-hosted media server and file management system

fix: #226 by casting total_size attribute to int

aminnausina9480273079f
diff --git a/app/Jobs/VerifyFolders.php b/app/Jobs/VerifyFolders.php
index 521404bb..652b302a 100644
--- a/app/Jobs/VerifyFolders.php
+++ b/app/Jobs/VerifyFolders.php
@@ -7,7 +7,6 @@ use App\Exceptions\DataLostException;
use App\Models\Series;
use App\Models\SubTask;
use App\Services\TaskService;
-use Carbon\Carbon;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Storage;
@@ -63,9 +62,20 @@ class VerifyFolders extends ManagedSubTask {
$stored = $series->toArray();
- $changes['episodes'] = $folder->videos->count();
+ $episodeCount = $folder->videos->count();
+ if ($stored['episodes'] !== $episodeCount) {
+ $changes['episodes'] = $episodeCount;
+ }
+
+ $primary_media_type = $folder->primary_media_type;
+ if ($stored['primary_media_type'] !== $primary_media_type) {
+ $changes['primary_media_type'] = $folder->primary_media_type;
+ }
- $changes['primary_media_type'] = $folder->primary_media_type;
+ $totalSize = $folder->total_size;
+ if ($stored['total_size'] !== $totalSize) {
+ $changes['total_size'] = $totalSize;
+ }
if (is_null($series->title)) {
$changes['title'] = $folder->name;
@@ -79,9 +89,14 @@ class VerifyFolders extends ManagedSubTask {
if ($thumbnailResult) {
$changes['raw_thumbnail_url'] = $series->thumbnail_url;
$changes['thumbnail_url'] = $thumbnailResult;
- dump('got thumbnail for ' . $series->id . ' at ' . $thumbnailResult . ' from ' . $changes['raw_thumbnail_url']);
+ Log::info("Downloaded external thumbnail for {$series->id}.", [
+ 'series' => $series->id,
+ 'src' => $changes['raw_thumbnail_url'],
+ 'dst' => $thumbnailResult,
+ ]);
}
} elseif (isset($series->thumbnail_url) && $thumbnailIsInternal && ! Storage::disk('public')->exists("thumbnails/$thumbnailPath.webp")) {
+ // This means the thumbnail is set with another internal image url (for example cover art from a song was used as a thumbnail for some folder)
Log::warning(
"Local thumbnail is set but does not exist for $series->composite_id at " . Storage::disk('public')->path("thumbnails/$thumbnailPath.webp"),
[
@@ -91,13 +106,8 @@ class VerifyFolders extends ManagedSubTask {
);
}
- $totalSize = $folder->total_size;
- if ($stored['total_size'] !== $totalSize) {
- $changes['total_size'] = $totalSize;
- }
-
if (! empty($changes)) {
- // Dont do this wtf 'updated_at' => Carbon::now(config('app.timezone'))
+ $changes['updated_at'] = now();
array_push($transactions, [...$stored, ...$changes]);
/**
* DEBUG
@@ -125,7 +135,6 @@ class VerifyFolders extends ManagedSubTask {
Series::upsert($transactions, 'id', ['folder_id', 'title', 'episodes', 'thumbnail_url', 'raw_thumbnail_url', 'total_size', 'primary_media_type', 'updated_at']);
$summary = 'Updated ' . count($transactions) . ' folders from id ' . ($transactions[0]['folder_id']) . ' to ' . ($transactions[count($transactions) - 1]['folder_id']);
- dump($summary);
return $summary;
} catch (\Throwable $th) {
@@ -139,7 +148,6 @@ class VerifyFolders extends ManagedSubTask {
try {
$response = Http::get($url);
if ($response->successful()) {
- dump('Getting thumbnail');
$imageContent = $response->body();
$path = 'thumbnails/' . $compositePath . '.webp';
Storage::disk('public')->put($path, $imageContent);
diff --git a/app/Models/Folder.php b/app/Models/Folder.php
index f589d571..bcdaf662 100755
--- a/app/Models/Folder.php
+++ b/app/Models/Folder.php
@@ -14,6 +14,10 @@ class Folder extends Model {
public $timestamps = false;
+ protected $casts = [
+ 'total_size' => 'integer',
+ ];
+
public function videos(): HasMany {
return $this->hasMany(Video::class);
}
@@ -31,7 +35,7 @@ class Folder extends Model {
}
public function getTotalSizeAttribute() {
- return $this->videos()->join('metadata', 'videos.id', '=', 'metadata.video_id')->sum('metadata.file_size');
+ return (int) $this->videos()->join('metadata', 'videos.id', '=', 'metadata.video_id')->sum('metadata.file_size');
}
public function getPrimaryMediaTypeAttribute(): int {