Skip to content

Commit 59fb0ea

Browse files
committed
Improved file downloading
1 parent 3fb739c commit 59fb0ea

File tree

7 files changed

+83
-196
lines changed

7 files changed

+83
-196
lines changed

app/Exceptions/Handler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public function render($request, Exception $e)
5050
$e = new NotFoundHttpException($e->getMessage(), $e);
5151
}
5252

53-
if ($request->isXmlHttpRequest() || $request->ajax() || $request->is('/api/*')) {
53+
if ($request->isXmlHttpRequest() || $request->ajax() || $request->is('api/*') || $request->is('remote/*')) {
5454

5555
$exception = 'An exception occured while attempting to perform this action, please try again.';
5656

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
namespace Pterodactyl\Http\Controllers\Remote;
4+
5+
use Pterodactyl\Models\Download;
6+
use Pterodactyl\Exceptions\DisplayException;
7+
8+
use Pterodactyl\Http\Controllers\Controller;
9+
use Illuminate\Http\Request;
10+
11+
class RemoteController extends Controller
12+
{
13+
14+
/**
15+
* Controller Constructor
16+
*/
17+
public function __construct()
18+
{
19+
// No middleware for this route.
20+
}
21+
22+
public function postDownload(Request $request) {
23+
$download = Download::where('token', $request->input('token', '00'))->first();
24+
if (!$download) {
25+
return response()->json([
26+
'error' => 'An invalid request token was recieved with this request.'
27+
], 403);
28+
}
29+
30+
$download->delete();
31+
return response()->json([
32+
'path' => $download->path,
33+
'server' => $download->server
34+
]);
35+
}
36+
37+
}

app/Http/Controllers/Scales/FileController.php

Lines changed: 0 additions & 193 deletions
This file was deleted.

app/Http/Controllers/Server/ServerController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ public function getDownloadFile(Request $request, $uuid, $file)
150150
$download = new Download;
151151

152152
$download->token = Uuid::generate(4);
153-
$download->server = $server->id;
153+
$download->server = $server->uuid;
154154
$download->path = str_replace('../', '', $file);
155155

156156
$download->save();

app/Http/Middleware/VerifyCsrfToken.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ class VerifyCsrfToken extends BaseVerifier
1212
* @var array
1313
*/
1414
protected $except = [
15-
//
15+
'remote/*',
1616
];
1717
}

app/Http/Routes/RemoteRoutes.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
namespace Pterodactyl\Http\Routes;
4+
5+
use Illuminate\Routing\Router;
6+
use Request;
7+
8+
class RemoteRoutes {
9+
10+
public function map(Router $router) {
11+
$router->group(['prefix' => 'remote'], function () use ($router) {
12+
$router->post('download', [ 'as' => 'remote.download', 'uses' => 'Remote\RemoteController@postDownload' ]);
13+
});
14+
}
15+
16+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
use Illuminate\Database\Schema\Blueprint;
4+
use Illuminate\Database\Migrations\Migration;
5+
6+
class DownloadsServerIntToString extends Migration
7+
{
8+
/**
9+
* Run the migrations.
10+
*
11+
* @return void
12+
*/
13+
public function up()
14+
{
15+
DB::statement('ALTER TABLE `downloads` MODIFY `server` CHAR(36) NOT NULL');
16+
}
17+
18+
/**
19+
* Reverse the migrations.
20+
*
21+
* @return void
22+
*/
23+
public function down()
24+
{
25+
DB::statement('ALTER TABLE `downloads` MODIFY `server` MEDIUMINT(9) NOT NULL');
26+
}
27+
}

0 commit comments

Comments
 (0)