Skip to content

Commit

Permalink
chore: use Laravel' original structure
Browse files Browse the repository at this point in the history
  • Loading branch information
phanan committed Sep 12, 2020
1 parent 8c7ea70 commit 860ec46
Show file tree
Hide file tree
Showing 32 changed files with 98 additions and 134 deletions.
2 changes: 1 addition & 1 deletion .gitpod.dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
FROM gitpod/workspace-mysql:latest

ENV APACHE_DOCROOT_IN_REPO=""
ENV APACHE_DOCROOT_IN_REPO="public"
4 changes: 2 additions & 2 deletions api-docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2163,7 +2163,7 @@ <h2>Upload an artist&#039;s image</h2>
<p>Example response (200):</p>
</blockquote>
<pre><code class="language-json">{
"artistUrl": "https:\/\/koel.host\/images\/artists\/new-cover.jpg"
"artistUrl": "https:\/\/koel.host\/img\/artists\/new-cover.jpg"
}</code></pre>
<h3>HTTP Request</h3>
<p><code>PUT api/artist/{artist}/image</code></p>
Expand Down Expand Up @@ -3855,4 +3855,4 @@ <h3>HTTP Request</h3>
</div>
</div>
</body>
</html>
</html>
2 changes: 1 addition & 1 deletion api-docs/source/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -2236,7 +2236,7 @@ fetch(url, {
```json
{
"artistUrl": "https:\/\/koel.host\/images\/artists\/new-cover.jpg"
"artistUrl": "https:\/\/koel.host\/img\/artists\/new-cover.jpg"
}
```

Expand Down
18 changes: 4 additions & 14 deletions app/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,6 @@ class Application extends IlluminateApplication
*/
public const KOEL_VERSION = 'v4.4.0';

/**
* We have merged public path and base path.
*
* @return string
*/
public function publicPath()
{
return $this->basePath;
}

/**
* Loads a revision'ed asset file, making use of gulp-rev
* This is a copycat of L5's Elixir, but catered to our directory structure.
Expand All @@ -37,16 +27,16 @@ public function rev(string $file, string $manifestFile = null): string
{
static $manifest = null;

$manifestFile = $manifestFile ?: public_path('public/mix-manifest.json');
$manifestFile = $manifestFile ?: public_path('mix-manifest.json');

if ($manifest === null) {
$manifest = json_decode(file_get_contents($manifestFile), true);
}

if (isset($manifest[$file])) {
return file_exists(public_path('public/hot'))
? "http://localhost:8080/public{$manifest[$file]}"
: $this->staticUrl("public{$manifest[$file]}");
return file_exists(public_path('hot'))
? "http://localhost:8080{$manifest[$file]}"
: $this->staticUrl("{$manifest[$file]}");
}

throw new InvalidArgumentException("File {$file} not defined in asset manifest.");
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/API/AlbumThumbnailController.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function __construct(MediaMetadataService $mediaMetadataService)
* Get an album's thumbnail (a 48px-wide blurry version of the album's cover).
* Returns the full URL to the thumbnail or NULL if the album has no cover.
*
* @response ["thumbnailUrl", "https://localhost/public/img/covers/a146d01afb742b01f28ab8b556f9a75d_thumbnail.jpg"]
* @response ["thumbnailUrl", "https://localhost/img/covers/a146d01afb742b01f28ab8b556f9a75d_thumbnail.jpg"]
*/
public function get(Album $album): JsonResponse
{
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Middleware/RedirectIfAuthenticated.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function __construct(Guard $auth)
public function handle(Request $request, Closure $next)
{
if ($this->auth->check()) {
return redirect('/');
return redirect('/');
}

return $next($request);
Expand Down
25 changes: 0 additions & 25 deletions app/Http/Middleware/UseDifferentConfigIfE2E.php

This file was deleted.

2 changes: 1 addition & 1 deletion bootstrap/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
|
*/

$app = new App\Application(__DIR__.'/../');
$app = new App\Application(dirname(__DIR__));

/*
|--------------------------------------------------------------------------
Expand Down
2 changes: 0 additions & 2 deletions bootstrap/autoload.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<?php

define('LARAVEL_START', microtime(true));

/*
|--------------------------------------------------------------------------
| Register The Composer Auto Loader
Expand Down
4 changes: 2 additions & 2 deletions config/koel.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
'media_path' => env('MEDIA_PATH'),

// The *relative* path to the directory to store album covers and thumbnails, *with* a trailing slash.
'album_cover_dir' => 'public/img/covers/',
'album_cover_dir' => 'img/covers/',

// The *relative* path to the directory to store artist images, *with* a trailing slash.
'artist_image_dir' => 'public/img/artists/',
'artist_image_dir' => 'img/artists/',

/*
|--------------------------------------------------------------------------
Expand Down
7 changes: 1 addition & 6 deletions nginx.conf.example
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
server {
listen *:80;
server_name koel.dev;
root /var/www/koel;
root /var/www/koel/public;
index index.php;

gzip on;
gzip_types text/plain text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript application/json;
gzip_comp_level 9;

# Whitelist only index.php, robots.txt, and some special routes
if ($request_uri !~ ^/$|index\.php|robots\.txt|(public|api|web)/|remote|api-docs|sw\.js) {
return 404;
}

location /media/ {
internal;

Expand Down
12 changes: 7 additions & 5 deletions public/.gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
*
!.gitignore
!manifest.json.example
!manifest-remote.json.example
!browserconfig.xml
css
fonts
img
js
manifest.json
manifest-remote.json
hot
22 changes: 10 additions & 12 deletions .htaccess → public/.htaccess
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,24 @@

<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
Options -MultiViews -Indexes
</IfModule>

RewriteEngine On
RewriteBase /

# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

# Whitelist only index.php, robots.txt, and some special routes
RewriteRule ^(?!($|index\.php|robots\.txt|(public|api|web)/|remote|api-docs|sw\.js)) - [R=404,L]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]

# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* index.php [L]

# https://github.com/tymondesigns/jwt-auth/wiki/Authentication
RewriteCond %{HTTP:Authorization} ^(.*)
RewriteRule .* - [e=HTTP_AUTHORIZATION:%1]
RewriteRule ^ index.php [L]
</IfModule>

<IfModule mod_expires.c>
Expand All @@ -52,7 +50,7 @@
<IfModule mod_deflate.c>

# Disable deflation for media files.
SetEnvIfNoCase Request_URI "^/api/play/" no-gzip dont-vary
SetEnvIfNoCase Request_URI "^/play/" no-gzip dont-vary

# ----------------------------------------------------------------------
# Gzip compression.
Expand Down
8 changes: 4 additions & 4 deletions public/browserconfig.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
<browserconfig>
<msapplication>
<tile>
<square70x70logo src="public/img/tile.png"/>
<square150x150logo src="public/img/tile.png"/>
<wide310x150logo src="public/img/tile-wide.png"/>
<square310x310logo src="public/img/tile.png"/>
<square70x70logo src="img/tile.png"/>
<square150x150logo src="img/tile.png"/>
<wide310x150logo src="img/tile-wide.png"/>
<square310x310logo src="img/tile.png"/>
</tile>
</msapplication>
</browserconfig>
19 changes: 11 additions & 8 deletions index.php → public/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@
|
*/

require __DIR__.'/bootstrap/autoload.php';
use Illuminate\Contracts\Http\Kernel;
use Illuminate\Http\Request;

define('LARAVEL_START', microtime(true));

require __DIR__.'/../bootstrap/autoload.php';

/*
|--------------------------------------------------------------------------
Expand All @@ -32,7 +37,7 @@
|
*/

$app = require_once __DIR__.'/bootstrap/app.php';
$app = require_once __DIR__.'/../bootstrap/app.php';

/*
|--------------------------------------------------------------------------
Expand All @@ -46,12 +51,10 @@
|
*/

$kernel = $app->make(Illuminate\Contracts\Http\Kernel::class);

$response = $kernel->handle(
$request = Illuminate\Http\Request::capture()
);
$kernel = $app->make(Kernel::class);

$response->send();
$response = tap($kernel->handle(
$request = Request::capture()
))->send();

$kernel->terminate($request, $response);
2 changes: 1 addition & 1 deletion public/manifest-remote.json.example
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"display": "standalone",
"orientation": "portrait",
"icons": [{
"src": "/public/img/icon.png",
"src": "/img/icon.png",
"sizes": "192x192",
"type": "image/png"
}],
Expand Down
2 changes: 1 addition & 1 deletion public/manifest.json.example
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"display": "standalone",
"orientation": "portrait",
"icons": [{
"src": "/public/img/icon.png",
"src": "/img/icon.png",
"sizes": "192x192",
"type": "image/png"
}],
Expand Down
6 changes: 6 additions & 0 deletions public/mix-manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"/js/app.js": "/js/app.js",
"/css/app.css": "/css/app.css",
"/css/remote.css": "/css/remote.css",
"/js/remote/app.js": "/js/remote/app.js"
}
File renamed without changes.
10 changes: 5 additions & 5 deletions resources/views/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
<meta name="msapplication-navbutton-color" content="#282828">

<base href="{{ asset('') }}">
<link rel="manifest" href="{{ App::staticUrl('public/manifest.json') }}" />
<meta name="msapplication-config" content="{{ App::staticUrl('public/browserconfig.xml') }}" />
<link rel="icon" type="image/x-icon" href="{{ App::staticUrl('public/img/favicon.ico') }}" />
<link rel="icon" href="{{ App::staticUrl('public/img/icon.png') }}">
<link rel="apple-touch-icon" href="{{ App::staticUrl('public/img/icon.png') }}">
<link rel="manifest" href="{{ App::staticUrl('manifest.json') }}" />
<meta name="msapplication-config" content="{{ App::staticUrl('browserconfig.xml') }}" />
<link rel="icon" type="image/x-icon" href="{{ App::staticUrl('img/favicon.ico') }}" />
<link rel="icon" href="{{ App::staticUrl('img/icon.png') }}">
<link rel="apple-touch-icon" href="{{ App::staticUrl('img/icon.png') }}">

<link rel="stylesheet" href="{{ App::rev('/css/app.css') }}">
</head>
Expand Down
10 changes: 5 additions & 5 deletions resources/views/remote.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
<meta name="msapplication-navbutton-color" content="#282828">

<base href="{{ asset('') }}">
<link rel="manifest" href="{{ App::staticUrl('public/manifest-remote.json') }}" />
<meta name="msapplication-config" content="{{ App::staticUrl('public/browserconfig.xml') }}" />
<link rel="icon" type="image/x-icon" href="{{ App::staticUrl('public/img/favicon.ico') }}" />
<link rel="icon" href="{{ App::staticUrl('public/img/icon.png') }}">
<link rel="apple-touch-icon" href="{{ App::staticUrl('public/img/icon.png') }}">
<link rel="manifest" href="{{ App::staticUrl('manifest-remote.json') }}" />
<meta name="msapplication-config" content="{{ App::staticUrl('browserconfig.xml') }}" />
<link rel="icon" type="image/x-icon" href="{{ App::staticUrl('img/favicon.ico') }}" />
<link rel="icon" href="{{ App::staticUrl('img/icon.png') }}">
<link rel="apple-touch-icon" href="{{ App::staticUrl('img/icon.png') }}">

<link rel="stylesheet" href="{{ App::rev('/css/remote.css') }}">
</head>
Expand Down
4 changes: 2 additions & 2 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
return view('remote');
});

Route::group(['middleware' => 'auth', 'prefix' => 'web'], static function (): void {
Route::get('/{song}/play/{transcode?}/{bitrate?}', 'PlayController@show')
Route::group(['middleware' => 'auth'], static function (): void {
Route::get('play/{song}/{transcode?}/{bitrate?}', 'PlayController@show')
->name('song.play');

Route::group(['prefix' => 'lastfm'], static function (): void {
Expand Down
4 changes: 2 additions & 2 deletions server.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
// This file allows us to emulate Apache's "mod_rewrite" functionality from the
// built-in PHP web server. This provides a convenient way to test a Laravel
// application without having installed a "real" web server software here.
if ($uri !== '/' && file_exists(__DIR__.$uri)) {
if ($uri !== '/' && file_exists(__DIR__.'/public'.$uri)) {
return false;
}

require_once __DIR__.'/index.php';
require_once __DIR__.'/public/index.php';
2 changes: 1 addition & 1 deletion storage/responses/albumCover.update.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"coverUrl": "https://koel.host/images/albums/new-cover.jpg"
"coverUrl": "https://koel.host/img/albums/new-cover.jpg"
}
2 changes: 1 addition & 1 deletion storage/responses/artistImage.update.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"imageUrl": "https://koel.host/images/artists/new-cover.jpg"
"imageUrl": "https://koel.host/img/artists/new-cover.jpg"
}
2 changes: 1 addition & 1 deletion tests/Feature/AlbumThumbnailTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function setUp(): void

public function provideAlbumThumbnailData(): array
{
return [['http://localhost/public/img/covers/foo_thumbnail.jpg'], [null]];
return [['http://localhost/img/covers/foo_thumbnail.jpg'], [null]];
}

/** @dataProvider provideAlbumThumbnailData */
Expand Down
Loading

0 comments on commit 860ec46

Please sign in to comment.