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

61 lines
1.8 KiB
PHP
Raw Normal View History

2023-09-22 19:31:47 +00:00
<?php
2023-12-07 18:06:32 +00:00
namespace App\Livewire\Project\Service;
2023-09-22 19:31:47 +00:00
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;
public ?string $workdir = null;
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;
if (Str::of($this->fileStorage->fs_path)->startsWith('.')) {
$this->workdir = $this->service->service->workdir();
$this->fs_path = Str::of($this->fileStorage->fs_path)->after('.');
} else {
$this->workdir = null;
$this->fs_path = $this->fileStorage->fs_path;
}
}
public function submit()
{
$original = $this->fileStorage->getOriginal();
try {
$this->validate();
if ($this->fileStorage->is_directory) {
$this->fileStorage->content = null;
}
$this->fileStorage->save();
$this->fileStorage->saveStorageOnServer();
2024-02-22 13:53:42 +00:00
$this->dispatch('success', 'File updated.');
} catch (\Throwable $e) {
$this->fileStorage->setRawAttributes($original);
$this->fileStorage->save();
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');
}
}