Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 0 additions & 24 deletions app/Filament/Server/Resources/Files/Pages/ListFiles.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@
use App\Models\File;
use App\Models\Server;
use App\Repositories\Daemon\DaemonFileRepository;
use App\Services\Nodes\NodeJWTService;
use App\Traits\Filament\CanCustomizeHeaderActions;
use App\Traits\Filament\CanCustomizeHeaderWidgets;
use Carbon\CarbonImmutable;
use Exception;
use Filament\Actions\Action;
use Filament\Actions\ActionGroup;
Expand Down Expand Up @@ -616,28 +614,6 @@ private function getPermissionsFromModeBit(int $mode): array
};
}

public function getUploadUrl(NodeJWTService $jwtService): string
{
/** @var Server $server */
$server = Filament::getTenant();

if (!user()?->can(SubuserPermission::FileCreate, $server)) {
abort(403, 'You do not have permission to upload files.');
}

$token = $jwtService
->setExpiresAt(CarbonImmutable::now()->addMinutes(15))
->setUser(user())
->setClaims(['server_uuid' => $server->uuid])
->handle($server->node, user()->id . $server->uuid);

return sprintf(
'%s/upload/file?token=%s',
$server->node->getConnectionAddress(),
$token->toString()
);
}

public function getUploadSizeLimit(): int
{
/** @var Server $server */
Expand Down
12 changes: 11 additions & 1 deletion resources/views/filament/server/pages/file-upload.blade.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
<div
x-data="{
serverUuid: @js(\Filament\Facades\Filament::getTenant()->uuid),
isUploading: false,
uploadQueue: [],
currentFileIndex: 0,
totalFiles: 0,
autoCloseTimer: 1000,

async fetchUploadUrl() {
const r = await fetch(`/api/client/servers/${this.serverUuid}/files/upload`, {
headers: { Accept: 'application/json', 'X-Requested-With': 'XMLHttpRequest' },
credentials: 'same-origin',
});
if (!r.ok) throw new Error(`upload url request failed (${r.status})`);
return (await r.json()).attributes.url;
},

async extractFilesFromItems(items) {
const filesWithPaths = [];
const traversePromises = [];
Expand Down Expand Up @@ -210,7 +220,7 @@
const fileData = this.uploadQueue[index];
fileData.status = 'uploading';
try {
const uploadUrl = await $wire.getUploadUrl();
const uploadUrl = await this.fetchUploadUrl();
const url = new URL(uploadUrl);
let basePath = @js($this->path);

Expand Down
12 changes: 11 additions & 1 deletion resources/views/filament/server/pages/list-files.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<div
x-data="
{
serverUuid: @js(\Filament\Facades\Filament::getTenant()->uuid),
isDragging: false,
dragCounter: 0,
isUploading: false,
Expand All @@ -10,6 +11,15 @@
totalFiles: 0,
autoCloseTimer: 1000,

async fetchUploadUrl() {
const r = await fetch(`/api/client/servers/${this.serverUuid}/files/upload`, {
headers: { Accept: 'application/json', 'X-Requested-With': 'XMLHttpRequest' },
credentials: 'same-origin',
});
if (!r.ok) throw new Error(`upload url request failed (${r.status})`);
return (await r.json()).attributes.url;
},

handleDragEnter(e) {
e.preventDefault();
e.stopPropagation();
Expand Down Expand Up @@ -259,7 +269,7 @@
const fileData = this.uploadQueue[index];
fileData.status = 'uploading';
try {
const uploadUrl = await $wire.getUploadUrl();
const uploadUrl = await this.fetchUploadUrl();
const url = new URL(uploadUrl);
let basePath = @js($this->path);

Expand Down
Loading