mirror of
https://github.com/DirectoryLister/DirectoryLister.git
synced 2025-08-30 09:10:38 +02:00
Updated frontend to take advantage of query strings
This commit is contained in:
@@ -56,9 +56,6 @@
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
baseHref() {
|
||||
return document.getElementsByTagName('base')[0].href;
|
||||
},
|
||||
styles() {
|
||||
return { 'hidden': ! this.visible };
|
||||
},
|
||||
@@ -71,7 +68,7 @@
|
||||
this.filePath = filePath;
|
||||
this.visible = true;
|
||||
|
||||
await axios.get(this.baseHref + 'file-info/' + filePath).then(function (response) {
|
||||
await axios.get('?info=' + filePath).then(function (response) {
|
||||
this.hashes = response.data.hashes;
|
||||
this.loading = false;
|
||||
}.bind(this)).catch(
|
||||
|
@@ -5,7 +5,7 @@ namespace App\ViewFunctions;
|
||||
class Asset extends ViewFunction
|
||||
{
|
||||
/** @const Constant description */
|
||||
protected const ASSET_PATH = '/app/assets/';
|
||||
protected const ASSET_PATH = 'app/assets/';
|
||||
|
||||
/** @var string The function name */
|
||||
protected $name = 'asset';
|
||||
@@ -19,8 +19,6 @@ class Asset extends ViewFunction
|
||||
*/
|
||||
public function __invoke(string $path): string
|
||||
{
|
||||
$assetPath = dirname($_SERVER['SCRIPT_NAME']) . self::ASSET_PATH . ltrim($path, '/');
|
||||
|
||||
return '/' . ltrim($assetPath, '/');
|
||||
return self::ASSET_PATH . ltrim($path, '/');
|
||||
}
|
||||
}
|
||||
|
@@ -25,9 +25,9 @@ class Breadcrumbs extends ViewFunction
|
||||
return $breadcrumbs->filter(function (string $crumb) {
|
||||
return $crumb !== '.';
|
||||
})->reduce(function (Collection $carry, string $crumb) {
|
||||
return $carry->put($crumb, $carry->last() . '/' . $crumb);
|
||||
}, new Collection)->map(function (string $path) {
|
||||
return '/' . ltrim(dirname($_SERVER['SCRIPT_NAME']) . $path, '/');
|
||||
return $carry->put($crumb, ltrim("{$carry->last()}/{$crumb}", '/'));
|
||||
}, new Collection)->map(function (string $path): string {
|
||||
return sprintf('?dir=%s', $path);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@@ -18,10 +18,10 @@ class ParentDir extends ViewFunction
|
||||
*/
|
||||
public function __invoke(string $path)
|
||||
{
|
||||
$parentDir = dirname($_SERVER['SCRIPT_NAME']) . '/' . Collection::make(
|
||||
$parentDir = Collection::make(
|
||||
explode('/', $path)
|
||||
)->filter()->slice(0, -1)->implode('/');
|
||||
|
||||
return '/' . ltrim($parentDir, '/');
|
||||
return empty($parentDir) ? '' : sprintf('?dir=%s', $parentDir);
|
||||
}
|
||||
}
|
||||
|
@@ -14,10 +14,10 @@ class Url extends ViewFunction
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function __invoke(string $path): string
|
||||
public function __invoke(string $path = '/'): string
|
||||
{
|
||||
$url = dirname($_SERVER['SCRIPT_NAME']) . '/' . ltrim($path, '/');
|
||||
$path = preg_replace('/^[.\/]+/', '', $path);
|
||||
|
||||
return '/' . trim($url, '/');
|
||||
return empty($path) ? '' : sprintf('?dir=%s', ltrim($path, './'));
|
||||
}
|
||||
}
|
||||
|
@@ -1,7 +1,7 @@
|
||||
<header id="header" class="bg-blue-600 shadow sticky top-0">
|
||||
<div class="container flex flex-col justify-between items-center mx-auto p-4 md:flex-row">
|
||||
<div class="font-mono text-white text-sm tracking-tight mb-2 md:my-1">
|
||||
<a href="{{ url('/') }}" class="hover:underline">Home</a>
|
||||
<a href="." class="hover:underline">Home</a>
|
||||
|
||||
{% if path %}
|
||||
{% for name, path in breadcrumbs(path) %}
|
||||
|
@@ -2,7 +2,7 @@
|
||||
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<base href="{{ base_href() }}">
|
||||
{# <base href="{{ base_href() }}"> #}
|
||||
<link rel="icon" href="{{ config('dark_mode') ? asset('images/favicon.dark.png') : asset('images/favicon.light.png') }}">
|
||||
<link rel="stylesheet" href="{{ asset('app.css') }}">
|
||||
|
||||
|
@@ -11,8 +11,8 @@ class AssetTest extends TestCase
|
||||
{
|
||||
$asset = new Asset($this->container, $this->config);
|
||||
|
||||
$this->assertEquals('/app/assets/css/app.css', $asset('css/app.css'));
|
||||
$this->assertEquals('/app/assets/js/app.js', $asset('js/app.js'));
|
||||
$this->assertEquals('app/assets/css/app.css', $asset('css/app.css'));
|
||||
$this->assertEquals('app/assets/js/app.js', $asset('js/app.js'));
|
||||
}
|
||||
|
||||
public function test_it_can_return_an_asset_with_a_subdirectory(): void
|
||||
@@ -21,7 +21,7 @@ class AssetTest extends TestCase
|
||||
|
||||
$asset = new Asset($this->container, $this->config);
|
||||
|
||||
$this->assertEquals('/some/dir/app/assets/css/app.css', $asset('css/app.css'));
|
||||
$this->assertEquals('/some/dir/app/assets/js/app.js', $asset('js/app.js'));
|
||||
$this->assertEquals('app/assets/css/app.css', $asset('css/app.css'));
|
||||
$this->assertEquals('app/assets/js/app.js', $asset('js/app.js'));
|
||||
}
|
||||
}
|
||||
|
@@ -13,9 +13,9 @@ class BreadcrumbsTest extends TestCase
|
||||
$breadcrumbs = new Breadcrumbs($this->container, $this->config);
|
||||
|
||||
$this->assertEquals(Collection::make([
|
||||
'foo' => '/foo',
|
||||
'bar' => '/foo/bar',
|
||||
'baz' => '/foo/bar/baz',
|
||||
'foo' => '?dir=foo',
|
||||
'bar' => '?dir=foo/bar',
|
||||
'baz' => '?dir=foo/bar/baz',
|
||||
]), $breadcrumbs('foo/bar/baz'));
|
||||
}
|
||||
|
||||
@@ -33,9 +33,9 @@ class BreadcrumbsTest extends TestCase
|
||||
$breadcrumbs = new Breadcrumbs($this->container, $this->config);
|
||||
|
||||
$this->assertEquals(Collection::make([
|
||||
'foo' => '/some/dir/foo',
|
||||
'bar' => '/some/dir/foo/bar',
|
||||
'baz' => '/some/dir/foo/bar/baz',
|
||||
'foo' => '?dir=foo',
|
||||
'bar' => '?dir=foo/bar',
|
||||
'baz' => '?dir=foo/bar/baz',
|
||||
]), $breadcrumbs('foo/bar/baz'));
|
||||
}
|
||||
}
|
||||
|
@@ -11,7 +11,7 @@ class ParentDirTest extends TestCase
|
||||
{
|
||||
$parentDir = new ParentDir($this->container, $this->config);
|
||||
|
||||
$this->assertEquals('/foo/bar', $parentDir('foo/bar/baz'));
|
||||
$this->assertEquals('?dir=foo/bar', $parentDir('foo/bar/baz'));
|
||||
}
|
||||
|
||||
public function test_it_can_get_the_parent_directory_from_a_path_in_a_subdirectory(): void
|
||||
@@ -20,6 +20,6 @@ class ParentDirTest extends TestCase
|
||||
|
||||
$parentDir = new ParentDir($this->container, $this->config);
|
||||
|
||||
$this->assertEquals('/some/dir/foo/bar', $parentDir('foo/bar/baz'));
|
||||
$this->assertEquals('?dir=foo/bar', $parentDir('foo/bar/baz'));
|
||||
}
|
||||
}
|
||||
|
@@ -11,9 +11,9 @@ class UrlTest extends TestCase
|
||||
{
|
||||
$url = new Url($this->container, $this->config);
|
||||
|
||||
$this->assertEquals('/', $url('/'));
|
||||
$this->assertEquals('/some/path', $url('some/path'));
|
||||
$this->assertEquals('/some/file.test', $url('some/file.test'));
|
||||
$this->assertEquals('', $url('/'));
|
||||
$this->assertEquals('?dir=some/path', $url('some/path'));
|
||||
$this->assertEquals('?dir=some/file.test', $url('some/file.test'));
|
||||
}
|
||||
|
||||
public function test_it_can_return_a_url_in_a_subdirectory(): void
|
||||
@@ -22,8 +22,8 @@ class UrlTest extends TestCase
|
||||
|
||||
$url = new Url($this->container, $this->config);
|
||||
|
||||
$this->assertEquals('/some/dir', $url('/'));
|
||||
$this->assertEquals('/some/dir/some/path', $url('some/path'));
|
||||
$this->assertEquals('/some/dir/some/file.test', $url('some/file.test'));
|
||||
$this->assertEquals('', $url('/'));
|
||||
$this->assertEquals('?dir=some/path', $url('some/path'));
|
||||
$this->assertEquals('?dir=some/file.test', $url('some/file.test'));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user