mirror of
https://github.com/brufdev/many-notes.git
synced 2026-01-24 20:09:50 -06:00
29 lines
618 B
PHP
29 lines
618 B
PHP
<?php
|
|
|
|
namespace App\Actions;
|
|
|
|
use App\Models\VaultNode;
|
|
|
|
class GetPathFromVaultNode
|
|
{
|
|
public function handle(VaultNode $node, bool $includeSelf = true): string
|
|
{
|
|
$relativePath = $node->parent ?
|
|
$node->parent->ancestorsAndSelf->last()->full_path . '/' :
|
|
'';
|
|
|
|
$path = sprintf(
|
|
'private/vaults/%u/%s/%s',
|
|
auth()->user()->id,
|
|
$node->vault->name,
|
|
$relativePath,
|
|
);
|
|
|
|
if ($includeSelf) {
|
|
$path .= $node->name . ($node->is_file ? '.' . $node->extension : '');
|
|
}
|
|
|
|
return $path;
|
|
}
|
|
}
|