Reading file size

This commit is contained in:
Krzysztof Płaczek
2022-12-05 19:39:12 +01:00
parent 55c104629f
commit b992d05312
5 changed files with 47 additions and 7 deletions

View File

@@ -46,14 +46,14 @@ class Chapter extends Model
protected function videoPath(): Attribute
{
return Attribute::make(
get: fn() => $this->directory_path . '/' . $this->id . '.' . $this->link . '.mp4'
get: fn() => $this->directory_path . '/' . $this->order . '.mp4'
);
}
protected function directoryPath(): Attribute
{
return Attribute::make(
get: fn() => $this->course_id . '.' . $this->course->link
get: fn() => public_path($this->course_id)
);
}
@@ -63,4 +63,16 @@ class Chapter extends Model
get: fn() => is_file($this->video_path)
);
}
public function videoSizeHuman(): Attribute
{
return Attribute::make(
get: function () {
$base = log($this->video_size) / log(1024);
$suffix = ["", "k", "M", "G", "T"][floor($base)];
return round(pow(1024, $base - floor($base)), 2) . $suffix;
},
);
}
}