fipamo/routes/api.php
ro 4113418c83
reorganized api, added token validation
regrouped api calls for better organization and to add a bit more
security. it now checks to make sure the incoming token matches the
current session to authorize requests
2024-07-06 17:41:32 -06:00

53 lines
2.2 KiB
PHP

<?php
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\API\AuthAPIController;
use App\Http\Controllers\API\PageAPIController;
use App\Http\Controllers\API\FileUploadAPIController;
use App\Http\Controllers\API\SettingsAPIController;
use App\Http\Controllers\API\InitAPIController;
use App\Http\Controllers\API\MailAPIController;
/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider and all of them will
| be assigned to the "api" middleware group. Make something great!
|
*/
//check if session is active
Route::get("/v1/status", [AuthAPIController::class, 'status']);
//handle page editing actions
Route::group(['prefix' => '/v1/page', 'middleware' => 'validate.token'], function () {
Route::put("/write", [PageAPIController::class, 'write']);
Route::post("/create", [PageAPIController::class, 'create']);
Route::delete("/delete", [PageAPIController::class, 'delete']);
});
//settings
Route::group(['prefix' => '/v1/settings', 'middleware' => 'validate.token'], function () {
Route::put("/publish", [SettingsAPIController::class, 'publish']);
Route::put("/sync", [SettingsAPIController::class, 'sync']);
Route::put("/nav-sync", [SettingsAPIController::class, 'navSync']);
});
//backups
Route::group(['prefix' => '/v1/backup', 'middleware' => 'validate.token'], function () {
Route::put("/create", [SettingsAPIController::class, 'createBackup']);
Route::get("/content-download", [SettingsAPIController::class, 'downloadBackup']);
Route::get("/files-download", [SettingsAPIController::class, 'downloadBackup']);
});
//other
Route::group(['prefix' => '/v1', 'middleware' => 'validate.token'], function () {
Route::post("/files", [FileUploadAPIController::class, 'upload']);
Route::post("/init", [InitAPIController::class, 'setupFresh']);
Route::post("/restore", [InitAPIController::class, 'setupRestore']);
Route::post("/reset", [InitAPIController::class, 'setupReset']);
Route::post("/mailer", [MailAPIController::class, 'sendNotify']);
});