Skip to content

A self-hosted media server and file management system

fix: File scan date is imprecise Fixes #245

aminnausin44a29bc9879d
diff --git a/app/Jobs/IndexFiles.php b/app/Jobs/IndexFiles.php
index 3942df4e..ee30b3e2 100755
--- a/app/Jobs/IndexFiles.php
+++ b/app/Jobs/IndexFiles.php
@@ -173,10 +173,10 @@ class IndexFiles extends ManagedSubTask {
$uuid = $metadataChange['uuid'];
$file_size = $metadataChange['file_size'];
$duration = $metadataChange['duration'];
- $date_scanned = $metadataChange['date_scanned'];
+ $file_scanned_at = $metadataChange['file_scanned_at'];
$date_uploaded = $metadataChange['date_uploaded'];
- $dbOut .= "UPSERT INTO [metadata] VALUES ({$videoId}, {$compositeId}, {$uuid}, {$file_size}, {$duration}, {$date_scanned}, {$date_uploaded});\n\n"; // upsert
+ $dbOut .= "UPSERT INTO [metadata] VALUES ({$videoId}, {$compositeId}, {$uuid}, {$file_size}, {$duration}, {$file_scanned_at}, {$date_uploaded});\n\n"; // upsert
$metadataTransactions[] = $metadataChange;
}
@@ -201,7 +201,7 @@ class IndexFiles extends ManagedSubTask {
'duration',
'mime_type',
'media_type',
- 'date_scanned',
+ 'file_scanned_at',
'date_uploaded',
]);
@@ -578,7 +578,7 @@ class IndexFiles extends ManagedSubTask {
'duration' => $duration,
'mime_type' => $mime_type ?? null,
'media_type' => $media_type,
- 'date_scanned' => date('Y-m-d h:i:s A'),
+ 'file_scanned_at' => now(),
'date_uploaded' => date('Y-m-d h:i A', $mtime < $ctime ? $mtime : $ctime),
];
$current[$key] = $currentID; // add to current
diff --git a/app/Jobs/VerifyFiles.php b/app/Jobs/VerifyFiles.php
index 7fde44cf..d8d0278f 100755
--- a/app/Jobs/VerifyFiles.php
+++ b/app/Jobs/VerifyFiles.php
@@ -127,9 +127,9 @@ class VerifyFiles extends ManagedSubTask {
$stored = $metadata->toArray(); // Metadata from db
$changes = []; // Changes -> stored + changes . length has to be the same for every video so must generate defaults
- $lastScannedAt = is_null($metadata->date_scanned) ? 0 : strtotime($metadata->date_scanned);
- $fileUpdated = $metadata->date_scanned && filemtime($filePath) > $lastScannedAt;
+ $fileUpdated = $metadata->file_scanned_at && filemtime($filePath) > $metadata->file_scanned_at->timestamp;
+ Metadata::where('id', 3);
if (is_null($metadata->uuid) || $fileUpdated) {
$changes['uuid'] = $uuid;
}
@@ -209,7 +209,7 @@ class VerifyFiles extends ManagedSubTask {
];
}
- $dirUpdated = $scannedDirectories[$folderPath]['last_modified'] > $lastScannedAt;
+ $dirUpdated = $metadata->file_scanned_at && $scannedDirectories[$folderPath]['last_modified'] > $metadata->file_scanned_at->timestamp;
// if directory updated, check directory for related subtitle files and make subtitle transactions for them with stream 0
diff --git a/app/Models/Metadata.php b/app/Models/Metadata.php
index a47b2e75..5d35b696 100644
--- a/app/Models/Metadata.php
+++ b/app/Models/Metadata.php
@@ -34,7 +34,7 @@ class Metadata extends Model {
'frame_rate',
'poster_url',
'date_released',
- 'date_scanned',
+ 'file_scanned_at',
'date_uploaded',
'media_type',
'album',
@@ -45,6 +45,7 @@ class Metadata extends Model {
protected $casts = [
'date_uploaded' => 'datetime',
+ 'file_scanned_at' => 'datetime',
'media_type' => MediaType::class,
];
diff --git a/database/migrations/2026_01_28_015136_add_scanned_at_to_metadata.php b/database/migrations/2026_01_28_015136_add_scanned_at_to_metadata.php
new file mode 100644
index 00000000..452f76f1
--- /dev/null
+++ b/database/migrations/2026_01_28_015136_add_scanned_at_to_metadata.php
@@ -0,0 +1,30 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\DB;
+use Illuminate\Support\Facades\Schema;
+
+return new class extends Migration {
+ /**
+ * Run the migrations.
+ */
+ public function up(): void {
+ Schema::table('metadata', function (Blueprint $table) {
+ $table->timestampTz('file_scanned_at')->nullable();
+ });
+
+ DB::table('metadata')->whereNotNull('date_scanned')->update(['file_scanned_at' => DB::raw('date_scanned')]);
+ }
+
+ /**
+ * Reverse the migrations.
+ */
+ public function down(): void {
+ DB::table('metadata')->whereNotNull('file_scanned_at')->update(['date_scanned' => DB::raw('DATE(file_scanned_at)')]);
+
+ Schema::table('metadata', function (Blueprint $table) {
+ $table->dropColumn('file_scanned_at');
+ });
+ }
+};
diff --git a/resources/js/types/model.ts b/resources/js/types/model.ts
index 34ea32f2..924967d5 100644
--- a/resources/js/types/model.ts
+++ b/resources/js/types/model.ts
@@ -39,7 +39,6 @@ export interface Metadata {
resolution_width?: number;
resolution_height?: number;
frame_rate?: number;
- date_scanned?: string;
date_released_formatted: any;
video?: Video;
editor?: User;
@@ -49,6 +48,7 @@ export interface Metadata {
album?: string;
video_tags?: VideoTag[];
media_type: MediaTypeValue;
+ file_scanned_at?: string;
subtitles_scanned_at?: string;
}