lasthourcloud/app/Http/Livewire/Project/Service/FileStorage.php

54 lines
1.5 KiB
PHP
Raw Normal View History

2023-09-22 19:31:47 +00:00
<?php
namespace App\Http\Livewire\Project\Service;
use App\Models\LocalFileVolume;
use App\Models\ServiceApplication;
use App\Models\ServiceDatabase;
2023-09-22 19:31:47 +00:00
use Livewire\Component;
use Illuminate\Support\Str;
2023-09-22 19:31:47 +00:00
class FileStorage extends Component
{
public LocalFileVolume $fileStorage;
public ServiceApplication|ServiceDatabase $service;
public string $fs_path;
2023-09-22 19:31:47 +00:00
protected $rules = [
2023-09-26 12:45:52 +00:00
'fileStorage.is_directory' => 'required',
2023-09-22 19:31:47 +00:00
'fileStorage.fs_path' => 'required',
'fileStorage.mount_path' => 'required',
'fileStorage.content' => 'nullable',
];
2023-09-27 10:45:53 +00:00
public function mount()
{
$this->service = $this->fileStorage->service;
$this->fs_path = Str::of($this->fileStorage->fs_path)->beforeLast('/');
$file = Str::of($this->fileStorage->fs_path)->afterLast('/');
if (Str::of($this->fs_path)->startsWith('.')) {
$this->fs_path = Str::of($this->fs_path)->after('.');
2023-09-27 10:45:53 +00:00
$this->fs_path = $this->service->service->workdir() . $this->fs_path . "/" . $file;
}
2023-09-28 07:54:21 +00:00
}
public function submit()
{
try {
$this->validate();
$this->fileStorage->save();
$this->service->saveFileVolumes();
$this->emit('success', 'File updated successfully.');
} catch (\Throwable $e) {
return handleError($e, $this);
}
}
2023-09-27 10:45:53 +00:00
public function instantSave()
{
2023-09-26 12:45:52 +00:00
$this->submit();
}
2023-09-22 19:31:47 +00:00
public function render()
{
return view('livewire.project.service.file-storage');
}
}