Skip to content

Commit 9f2ca17

Browse files
committed
replace manual json headers with laravel response()->json()
better Carbon dependency rename admin.nodes.configuration-token route style fixes
1 parent 67bb8fe commit 9f2ca17

File tree

5 files changed

+8
-11
lines changed

5 files changed

+8
-11
lines changed

app/Http/Controllers/Admin/NodesController.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727
use DB;
2828
use Log;
2929
use Alert;
30+
use Carbon;
3031
use Validator;
31-
use Carbon\Carbon;
3232
use Pterodactyl\Models;
3333
use Illuminate\Http\Request;
3434
use Pterodactyl\Exceptions\DisplayException;
@@ -296,7 +296,6 @@ public function getConfigurationToken(Request $request, $id)
296296
'expires_at' => $token->expires_at->toDateTimeString(),
297297
];
298298

299-
return response(json_encode($token_response), 200)
300-
->header('Content-Type', 'application/json');
299+
return response()->json($token_response, 200);
301300
}
302301
}

app/Http/Controllers/Remote/RemoteController.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,21 +116,20 @@ public function getConfiguration(Request $request, $tokenString)
116116
$token = Models\NodeConfigurationToken::where('token', $tokenString)->firstOrFail();
117117
$node = Models\Node::findOrFail($token->node);
118118
} catch (\Illuminate\Database\Eloquent\ModelNotFoundException $e) {
119-
return response(json_encode(['error' => 'token_invalid']), 403)
120-
->header('Content-Type', 'application/json');
119+
return response()->json(['error' => 'token_invalid'], 403);
121120
}
122121

123122
// Check if token is expired
124123
if ($token->expires_at->lt(Carbon::now())) {
125124
$token->delete();
126125

127-
return response(json_encode(['error' => 'token_expired']), 403)
128-
->header('Content-Type', 'application/json');
126+
return response()->json(['error' => 'token_expired'], 403);
129127
}
130128

131129
// Delete the token, it's one-time use
132130
$token->delete();
133131

132+
// Manually as getConfigurationAsJson() returns it in correct format already
134133
return response($node->getConfigurationAsJson(), 200)
135134
->header('Content-Type', 'application/json');
136135
}

app/Http/Routes/AdminRoutes.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ public function map(Router $router)
288288
]);
289289

290290
$router->get('/{id}/configurationtoken', [
291-
'as' => 'admin.nodes.configurationtoken',
291+
'as' => 'admin.nodes.configuration-token',
292292
'uses' => 'Admin\NodesController@getConfigurationToken',
293293
]);
294294
});

database/migrations/2017_01_07_154228_create_node_configuration_tokens_table.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ public function up()
1818
$table->char('token', 32);
1919
$table->timestamp('expires_at');
2020
$table->integer('node')->unsigned();
21-
$table->foreign('node')
22-
->references('id')->on('nodes');
21+
$table->foreign('node')->references('id')->on('nodes');
2322
$table->timestamps();
2423
});
2524
}

resources/views/admin/nodes/view.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@
502502
});
503503
504504
$('#configTokenBtn').on('click', function (event) {
505-
$.getJSON('{{ route('admin.nodes.configurationtoken', $node->id) }}')
505+
$.getJSON('{{ route('admin.nodes.configuration-token', $node->id) }}')
506506
.done(function (data) {
507507
swal({
508508
type: 'success',

0 commit comments

Comments
 (0)