Преглед на файлове

Merge pull request #2181 from pixelfed/staging

Add bookmarks to v1 api
daniel преди 5 години
родител
ревизия
ea57279a01
променени са 3 файла, в които са добавени 51 реда и са изтрити 2 реда
  1. 2 1
      CHANGELOG.md
  2. 47 0
      app/Http/Controllers/Api/ApiV1Controller.php
  3. 2 1
      routes/api.php

+ 2 - 1
CHANGELOG.md

@@ -4,7 +4,8 @@
 ### Added
 - ActivityPubFetchService for signed GET requests ([8763bfc5](https://github.com/pixelfed/pixelfed/commit/8763bfc5))
 - Custom content warnings for remote posts ([6afc61a4](https://github.com/pixelfed/pixelfed/commit/6afc61a4))
-- Thai translations ([https://github.com/pixelfed/pixelfed/commit/74cd536](https://github.com/pixelfed/pixelfed/commit/74cd536))
+- Thai translations ([74cd536](https://github.com/pixelfed/pixelfed/commit/74cd536))
+- Added Bookmarks to v1 api ([99cb48c5](https://github.com/pixelfed/pixelfed/commit/99cb48c5))
 
 ### Updated
 - Updated PostComponent, fix remote urls ([42716ccc](https://github.com/pixelfed/pixelfed/commit/42716ccc))

+ 47 - 0
app/Http/Controllers/Api/ApiV1Controller.php

@@ -10,6 +10,7 @@ use App\Util\Media\Filter;
 use Laravel\Passport\Passport;
 use Auth, Cache, DB, URL;
 use App\{
+    Bookmark,
     Follower,
     FollowRequest,
     Like,
@@ -1854,6 +1855,52 @@ class ApiV1Controller extends Controller
         return response()->json($res);
     }
 
+    /**
+     * GET /api/v1/bookmarks
+     *
+     *
+     *
+     * @return StatusTransformer
+     */
+    public function bookmarks(Request $request)
+    {
+        abort_if(!$request->user(), 403);
+
+        $this->validate($request, [
+            'limit' => 'nullable|integer|min:1|max:40',
+            'max_id' => 'nullable|integer|min:0',
+            'since_id' => 'nullable|integer|min:0',
+            'min_id' => 'nullable|integer|min:0'
+        ]);
+
+        $pid = $request->user()->profile_id;
+        $limit = $request->input('limit') ?? 20;
+        $max_id = $request->input('max_id');
+        $since_id = $request->input('since_id');
+        $min_id = $request->input('min_id');
+
+        $dir = $min_id ? '>' : '<';
+        $id = $min_id ?? $max_id;
+
+        if($id) {
+            $bookmarks = Bookmark::whereProfileId($pid)
+                ->where('status_id', $dir, $id)
+                ->limit($limit)
+                ->pluck('status_id');
+        } else {
+            $bookmarks = Bookmark::whereProfileId($pid)
+                ->latest()
+                ->limit($limit)
+                ->pluck('status_id');
+        }
+
+        $res = [];
+        foreach($bookmarks as $id) {
+            $res[] = \App\Services\StatusService::get($id);
+        }
+        return response()->json($res, 200, [], JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES);
+    }
+
     /**
      * GET /api/v2/search
      *

+ 2 - 1
routes/api.php

@@ -11,6 +11,7 @@ Route::group(['prefix' => 'api'], function() use($middleware) {
 	Route::group(['prefix' => 'v1'], function() use($middleware) {
 		Route::post('apps', 'Api\ApiV1Controller@apps');
 		Route::get('instance', 'Api\ApiV1Controller@instance');
+		Route::get('bookmarks', 'Api\ApiV1Controller@bookmarks')->middleware($middleware);
 		
 		Route::get('accounts/verify_credentials', 'Api\ApiV1Controller@verifyCredentials')->middleware($middleware);
 		Route::patch('accounts/update_credentials', 'Api\ApiV1Controller@accountUpdateCredentials')->middleware($middleware);
@@ -82,5 +83,5 @@ Route::group(['prefix' => 'api'], function() use($middleware) {
 	Route::group(['prefix' => 'v2'], function() use($middleware) {
 		Route::get('search', 'Api\ApiV1Controller@searchV2')->middleware($middleware);
 	});
-	
+
 });