mirror of
https://github.com/godotengine/godot-asset-library.git
synced 2026-02-25 06:33:01 +03:00
Use a constant to mark requests coming from frontend
This commit is contained in:
@@ -14,6 +14,10 @@ if (PHP_SAPI == 'cli-server') {
|
||||
|
||||
require __DIR__ . '/../vendor/autoload.php';
|
||||
|
||||
if (!defined('FRONTEND')) {
|
||||
define('FRONTEND', false);
|
||||
}
|
||||
|
||||
// Instantiate the app
|
||||
$settings = require __DIR__ . '/../src/settings.php';
|
||||
$local_settings = require __DIR__ . '/../src/settings-local.php';
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<?php
|
||||
$frontend = true;
|
||||
define('FRONTEND', true);
|
||||
include(__DIR__ . '/api/index.php');
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
if(isset($frontend) && $frontend) {
|
||||
if(FRONTEND) {
|
||||
$container = $app->getContainer();
|
||||
|
||||
$app->get('/', function ($request, $response) {
|
||||
|
||||
@@ -2,11 +2,11 @@
|
||||
// Asset routes
|
||||
|
||||
// Searches through the list of assets
|
||||
$app->get('/asset', function ($request, $response, $args) { global $frontend;
|
||||
$app->get('/asset', function ($request, $response, $args) {
|
||||
$params = $request->getQueryParams();
|
||||
|
||||
$category = '%';
|
||||
if(isset($frontend) && $frontend) {
|
||||
if(FRONTEND) {
|
||||
$category_type = $this->constants['category_type']['any'];
|
||||
} else {
|
||||
$category_type = $this->constants['category_type']['addon'];
|
||||
@@ -186,7 +186,7 @@ $get_asset = function ($request, $response, $args) {
|
||||
};
|
||||
// Binding to multiple routes
|
||||
$app->get('/asset/{id:[0-9]+}', $get_asset);
|
||||
if(isset($frontend) && $frontend) {
|
||||
if(FRONTEND) {
|
||||
$app->get('/asset/{id:[0-9]+}/edit', $get_asset);
|
||||
}
|
||||
|
||||
|
||||
@@ -405,7 +405,7 @@ $get_edit = function ($request, $response, $args) {
|
||||
|
||||
// Binding to multiple routes
|
||||
$app->get('/asset/edit/{id:[0-9]+}', $get_edit);
|
||||
if(isset($frontend) && $frontend) {
|
||||
if(FRONTEND) {
|
||||
$app->get('/asset/edit/{id:[0-9]+}/edit', $get_edit);
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
|
||||
// Initializes the connection by sending all categories available
|
||||
$app->get('/configure', function ($request, $response, $args) { global $frontend;
|
||||
$app->get('/configure', function ($request, $response, $args) {
|
||||
$params = $request->getQueryParams();
|
||||
|
||||
$category_type = $this->constants['category_type']['addon'];
|
||||
@@ -29,7 +29,7 @@ $app->get('/configure', function ($request, $response, $args) { global $frontend
|
||||
'categories' => $query->fetchAll(),
|
||||
'token' => $token,
|
||||
'login_url' => $_SERVER['HTTP_HOST'] .
|
||||
(isset($frontend) && $frontend ? dirname($request->getUri()->getBasePath()) : $request->getUri()->getBasePath()) .
|
||||
(FRONTEND ? dirname($request->getUri()->getBasePath()) : $request->getUri()->getBasePath()) .
|
||||
'/login#' . urlencode($token),
|
||||
// ^ TODO: Make those routes actually work
|
||||
], 200);
|
||||
@@ -138,7 +138,7 @@ $app->post('/login', function ($request, $response, $args) {
|
||||
}
|
||||
});
|
||||
|
||||
if(isset($frontend) && $frontend) { // Doesn't work for non-frontend, since we can't unissue tokens -- to logout from api/ just drop the token.
|
||||
if(FRONTEND) { // Doesn't work for non-frontend, since we can't unissue tokens -- to logout from api/ just drop the token.
|
||||
$app->get('/logout', function ($request, $response, $args) {
|
||||
return $response->withJson([
|
||||
'authenticated' => false,
|
||||
|
||||
@@ -43,6 +43,6 @@ $get_feed = function ($request, $response, $args) {
|
||||
|
||||
// Binding to multiple routes
|
||||
$app->post('/user/feed', $get_feed);
|
||||
if(isset($frontend) && $frontend) {
|
||||
$app->get('/user/feed', $get_feed);
|
||||
if(FRONTEND) {
|
||||
$app->get('/user/feed', $get_feed);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user