Update api routes, add DeprecatedEndpoint middleware

This commit is contained in:
Daniel Supernault 2023-06-06 01:55:28 -06:00
parent b49310a2d3
commit a8453e7719
No known key found for this signature in database
GPG key ID: 0DEF1C662C9033F7
2 changed files with 117 additions and 4 deletions

View file

@ -0,0 +1,28 @@
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Response;
class DeprecatedEndpoint
{
/**
* Handle an incoming request.
*
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next
*/
public function handle(Request $request, Closure $next): Response
{
abort_if(now()->gt('Jan 01, 2024'), 404);
$response = $next($request);
$link = $response->headers->has('link') ? $response->headers->get('link') . ',<https://pixelfed.org/kb/10404>; rel="deprecation"' : '<https://pixelfed.org/kb/10404>; rel="deprecation"';
$response->withHeaders([
'Deprecation' => 'Sat, 01 Jul 2023 00:00:00 GMT',
'Sunset' => 'Mon, 01 Jan 2024 00:00:00 GMT',
'Link' => $link
]);
return $response;
}
}

View file

@ -1,6 +1,7 @@
<?php
use Illuminate\Http\Request;
use App\Http\Middleware\DeprecatedEndpoint;
$middleware = ['auth:api','validemail'];
@ -107,9 +108,13 @@ Route::group(['prefix' => 'api'], function() use($middleware) {
});
Route::group(['prefix' => 'v1.1'], function() use($middleware) {
Route::post('report', 'Api\ApiV1Dot1Controller@report')->middleware($middleware);
$reportMiddleware = $middleware;
$reportMiddleware[] = DeprecatedEndpoint::class;
Route::post('report', 'Api\ApiV1Dot1Controller@report')->middleware($reportMiddleware);
Route::group(['prefix' => 'accounts'], function () use($middleware) {
$middleware[] = DeprecatedEndpoint::class;
Route::get('timelines/home', 'Api\ApiV1Controller@timelineHome')->middleware($middleware);
Route::delete('avatar', 'Api\ApiV1Dot1Controller@deleteAvatar')->middleware($middleware);
Route::get('{id}/posts', 'Api\ApiV1Dot1Controller@accountPosts')->middleware($middleware);
Route::post('change-password', 'Api\ApiV1Dot1Controller@accountChangePassword')->middleware($middleware);
@ -117,12 +122,10 @@ Route::group(['prefix' => 'api'], function() use($middleware) {
Route::get('two-factor', 'Api\ApiV1Dot1Controller@accountTwoFactor')->middleware($middleware);
Route::get('emails-from-pixelfed', 'Api\ApiV1Dot1Controller@accountEmailsFromPixelfed')->middleware($middleware);
Route::get('apps-and-applications', 'Api\ApiV1Dot1Controller@accountApps')->middleware($middleware);
Route::get('app/settings', 'UserAppSettingsController@get')->middleware($middleware);
Route::post('app/settings', 'UserAppSettingsController@store')->middleware($middleware);
});
Route::group(['prefix' => 'collections'], function () use($middleware) {
$middleware[] = DeprecatedEndpoint::class;
Route::get('accounts/{id}', 'CollectionController@getUserCollections')->middleware($middleware);
Route::get('items/{id}', 'CollectionController@getItems')->middleware($middleware);
Route::get('view/{id}', 'CollectionController@getCollection')->middleware($middleware);
@ -133,6 +136,7 @@ Route::group(['prefix' => 'api'], function() use($middleware) {
});
Route::group(['prefix' => 'direct'], function () use($middleware) {
$middleware[] = DeprecatedEndpoint::class;
Route::get('thread', 'DirectMessageController@thread')->middleware($middleware);
Route::post('thread/send', 'DirectMessageController@create')->middleware($middleware);
Route::delete('thread/message', 'DirectMessageController@delete')->middleware($middleware);
@ -144,16 +148,19 @@ Route::group(['prefix' => 'api'], function() use($middleware) {
});
Route::group(['prefix' => 'archive'], function () use($middleware) {
$middleware[] = DeprecatedEndpoint::class;
Route::post('add/{id}', 'Api\ApiV1Dot1Controller@archive')->middleware($middleware);
Route::post('remove/{id}', 'Api\ApiV1Dot1Controller@unarchive')->middleware($middleware);
Route::get('list', 'Api\ApiV1Dot1Controller@archivedPosts')->middleware($middleware);
});
Route::group(['prefix' => 'places'], function () use($middleware) {
$middleware[] = DeprecatedEndpoint::class;
Route::get('posts/{id}/{slug}', 'Api\ApiV1Dot1Controller@placesById')->middleware($middleware);
});
Route::group(['prefix' => 'stories'], function () use($middleware) {
$middleware[] = DeprecatedEndpoint::class;
Route::get('carousel', 'Stories\StoryApiV1Controller@carousel')->middleware($middleware);
Route::post('add', 'Stories\StoryApiV1Controller@add')->middleware($middleware);
Route::post('publish', 'Stories\StoryApiV1Controller@publish')->middleware($middleware);
@ -163,17 +170,20 @@ Route::group(['prefix' => 'api'], function() use($middleware) {
});
Route::group(['prefix' => 'compose'], function () use($middleware) {
$middleware[] = DeprecatedEndpoint::class;
Route::get('search/location', 'ComposeController@searchLocation')->middleware($middleware);
Route::get('settings', 'ComposeController@composeSettings')->middleware($middleware);
});
Route::group(['prefix' => 'discover'], function () use($middleware) {
$middleware[] = DeprecatedEndpoint::class;
Route::get('accounts/popular', 'Api\ApiV1Controller@discoverAccountsPopular')->middleware($middleware);
Route::get('posts/trending', 'DiscoverController@trendingApi')->middleware($middleware);
Route::get('posts/hashtags', 'DiscoverController@trendingHashtags')->middleware($middleware);
});
Route::group(['prefix' => 'directory'], function () use($middleware) {
$middleware[] = DeprecatedEndpoint::class;
Route::get('listing', 'PixelfedDirectoryController@get');
});
@ -230,4 +240,79 @@ Route::group(['prefix' => 'api'], function() use($middleware) {
Route::group(['prefix' => 'landing/v1'], function() use($middleware) {
Route::get('directory', 'LandingController@getDirectoryApi');
});
Route::group(['prefix' => 'pixelfed'], function() use($middleware) {
Route::group(['prefix' => 'v1'], function() use($middleware) {
Route::post('report', 'Api\ApiV1Dot1Controller@report')->middleware($middleware);
Route::group(['prefix' => 'accounts'], function () use($middleware) {
Route::get('timelines/home', 'Api\ApiV1Controller@timelineHome')->middleware($middleware);
Route::delete('avatar', 'Api\ApiV1Dot1Controller@deleteAvatar')->middleware($middleware);
Route::get('{id}/posts', 'Api\ApiV1Dot1Controller@accountPosts')->middleware($middleware);
Route::post('change-password', 'Api\ApiV1Dot1Controller@accountChangePassword')->middleware($middleware);
Route::get('login-activity', 'Api\ApiV1Dot1Controller@accountLoginActivity')->middleware($middleware);
Route::get('two-factor', 'Api\ApiV1Dot1Controller@accountTwoFactor')->middleware($middleware);
Route::get('emails-from-pixelfed', 'Api\ApiV1Dot1Controller@accountEmailsFromPixelfed')->middleware($middleware);
Route::get('apps-and-applications', 'Api\ApiV1Dot1Controller@accountApps')->middleware($middleware);
});
Route::group(['prefix' => 'archive'], function () use($middleware) {
Route::post('add/{id}', 'Api\ApiV1Dot1Controller@archive')->middleware($middleware);
Route::post('remove/{id}', 'Api\ApiV1Dot1Controller@unarchive')->middleware($middleware);
Route::get('list', 'Api\ApiV1Dot1Controller@archivedPosts')->middleware($middleware);
});
Route::group(['prefix' => 'collections'], function () use($middleware) {
Route::get('accounts/{id}', 'CollectionController@getUserCollections')->middleware($middleware);
Route::get('items/{id}', 'CollectionController@getItems')->middleware($middleware);
Route::get('view/{id}', 'CollectionController@getCollection')->middleware($middleware);
Route::post('add', 'CollectionController@storeId')->middleware($middleware);
Route::post('update/{id}', 'CollectionController@store')->middleware($middleware);
Route::delete('delete/{id}', 'CollectionController@delete')->middleware($middleware);
Route::post('remove', 'CollectionController@deleteId')->middleware($middleware);
});
Route::group(['prefix' => 'compose'], function () use($middleware) {
Route::get('search/location', 'ComposeController@searchLocation')->middleware($middleware);
Route::get('settings', 'ComposeController@composeSettings')->middleware($middleware);
});
Route::group(['prefix' => 'direct'], function () use($middleware) {
Route::get('thread', 'DirectMessageController@thread')->middleware($middleware);
Route::post('thread/send', 'DirectMessageController@create')->middleware($middleware);
Route::delete('thread/message', 'DirectMessageController@delete')->middleware($middleware);
Route::post('thread/mute', 'DirectMessageController@mute')->middleware($middleware);
Route::post('thread/unmute', 'DirectMessageController@unmute')->middleware($middleware);
Route::post('thread/media', 'DirectMessageController@mediaUpload')->middleware($middleware);
Route::post('thread/read', 'DirectMessageController@read')->middleware($middleware);
Route::post('lookup', 'DirectMessageController@composeLookup')->middleware($middleware);
});
Route::group(['prefix' => 'discover'], function () use($middleware) {
Route::get('accounts/popular', 'Api\ApiV1Controller@discoverAccountsPopular')->middleware($middleware);
Route::get('posts/trending', 'DiscoverController@trendingApi')->middleware($middleware);
Route::get('posts/hashtags', 'DiscoverController@trendingHashtags')->middleware($middleware);
});
Route::group(['prefix' => 'directory'], function () use($middleware) {
Route::get('listing', 'PixelfedDirectoryController@get');
});
Route::group(['prefix' => 'places'], function () use($middleware) {
Route::get('posts/{id}/{slug}', 'Api\ApiV1Dot1Controller@placesById')->middleware($middleware);
});
Route::get('app/settings', 'UserAppSettingsController@get')->middleware($middleware);
Route::post('app/settings', 'UserAppSettingsController@store')->middleware($middleware);
Route::group(['prefix' => 'stories'], function () use($middleware) {
Route::get('carousel', 'Stories\StoryApiV1Controller@carousel')->middleware($middleware);
Route::post('add', 'Stories\StoryApiV1Controller@add')->middleware($middleware);
Route::post('publish', 'Stories\StoryApiV1Controller@publish')->middleware($middleware);
Route::post('seen', 'Stories\StoryApiV1Controller@viewed')->middleware($middleware);
Route::post('self-expire/{id}', 'Stories\StoryApiV1Controller@delete')->middleware($middleware);
Route::post('comment', 'Stories\StoryApiV1Controller@comment')->middleware($middleware);
});
});
});
});