mirror of
https://github.com/VueFileManager/vuefilemanager.git
synced 2026-04-23 17:50:38 +00:00
encoding troubleshooting
This commit is contained in:
@@ -39,10 +39,10 @@ use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
*/
|
||||
class File extends Model
|
||||
{
|
||||
use Searchable;
|
||||
use SoftDeletes;
|
||||
use Sortable;
|
||||
use Searchable;
|
||||
use HasFactory;
|
||||
use Sortable;
|
||||
|
||||
public ?string $public_access = null;
|
||||
|
||||
@@ -76,6 +76,11 @@ class File extends Model
|
||||
return FileFactory::new();
|
||||
}
|
||||
|
||||
public function setNameAttribute($name): void
|
||||
{
|
||||
$this->attributes['name'] = mb_convert_encoding($name, 'UTF-8');
|
||||
}
|
||||
|
||||
/**
|
||||
* Set routes with public access
|
||||
*/
|
||||
@@ -84,14 +89,6 @@ class File extends Model
|
||||
$this->public_access = $token;
|
||||
}
|
||||
|
||||
/**
|
||||
* Format fileSize
|
||||
*/
|
||||
public function getFilesizeAttribute(): string
|
||||
{
|
||||
return Metric::bytes($this->attributes['filesize'])->format();
|
||||
}
|
||||
|
||||
/**
|
||||
* Format thumbnail url
|
||||
*/
|
||||
@@ -149,36 +146,32 @@ class File extends Model
|
||||
return $route;
|
||||
}
|
||||
|
||||
/**
|
||||
* Index file
|
||||
*/
|
||||
public function toSearchableArray(): array
|
||||
{
|
||||
$array = $this->toArray();
|
||||
$name = Str::slug($array['name'], ' ');
|
||||
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'name' => $name,
|
||||
'nameNgrams' => utf8_encode((new TNTIndexer)->buildTrigrams(implode(', ', [$name]))),
|
||||
];
|
||||
}
|
||||
|
||||
public function parent(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Folder::class, 'folder_id', 'id');
|
||||
}
|
||||
|
||||
public function folder(): HasOne
|
||||
{
|
||||
return $this->hasOne(Folder::class, 'id', 'folder_id');
|
||||
}
|
||||
|
||||
public function shared(): HasOne
|
||||
{
|
||||
return $this->hasOne(Share::class, 'item_id', 'id');
|
||||
}
|
||||
|
||||
public function toSearchableArray(): array
|
||||
{
|
||||
$name = mb_convert_encoding(
|
||||
mb_strtolower($this->name, 'UTF-8'), 'UTF-8'
|
||||
);
|
||||
|
||||
$trigram = (new TNTIndexer)
|
||||
->buildTrigrams(implode(', ', [$name]));
|
||||
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'name' => $name,
|
||||
'nameNgrams' => $trigram,
|
||||
];
|
||||
}
|
||||
|
||||
protected static function boot()
|
||||
{
|
||||
parent::boot();
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
<?php
|
||||
namespace Domain\Files\Resources;
|
||||
|
||||
use ByteUnits\Metric;
|
||||
use Domain\Sharing\Resources\ShareResource;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
@@ -9,21 +10,24 @@ class FileResource extends JsonResource
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* TODO: optimize created_at/updated_at conversion because of performance issue
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
// TODO: optimize created_at/updated_at conversion because of performance issue
|
||||
$fileSize = Metric::bytes($this->filesize)->format();
|
||||
|
||||
return [
|
||||
'data' => [
|
||||
'id' => $this->id,
|
||||
'type' => $this->type,
|
||||
'attributes' => [
|
||||
'filesize' => $fileSize,
|
||||
'name' => $this->name,
|
||||
'basename' => $this->basename,
|
||||
'mimetype' => $this->mimetype,
|
||||
'filesize' => $this->filesize,
|
||||
'file_url' => $this->file_url,
|
||||
'thumbnail' => $this->thumbnail,
|
||||
'metadata' => $this->metadata,
|
||||
|
||||
Reference in New Issue
Block a user