mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-12-22 07:42:41 +00:00
Update StoryApiV1Controller, add viewers route to view story viewers
This commit is contained in:
parent
c4843e823e
commit
941736ce6c
4 changed files with 64 additions and 0 deletions
|
@ -20,6 +20,7 @@ use App\Jobs\StoryPipeline\StoryViewDeliver;
|
|||
use App\Services\AccountService;
|
||||
use App\Services\MediaPathService;
|
||||
use App\Services\StoryService;
|
||||
use App\Http\Resources\StoryView as StoryViewResource;
|
||||
|
||||
class StoryApiV1Controller extends Controller
|
||||
{
|
||||
|
@ -355,4 +356,26 @@ class StoryApiV1Controller extends Controller
|
|||
$path = $photo->storePubliclyAs($storagePath, Str::random(random_int(2, 12)) . '_' . Str::random(random_int(32, 35)) . '_' . Str::random(random_int(1, 14)) . '.' . $photo->extension());
|
||||
return $path;
|
||||
}
|
||||
|
||||
public function viewers(Request $request)
|
||||
{
|
||||
abort_if(!config_cache('instance.stories.enabled') || !$request->user(), 404);
|
||||
|
||||
$this->validate($request, [
|
||||
'sid' => 'required|string|min:1|max:50'
|
||||
]);
|
||||
|
||||
$pid = $request->user()->profile_id;
|
||||
$sid = $request->input('sid');
|
||||
|
||||
$story = Story::whereProfileId($pid)
|
||||
->whereActive(true)
|
||||
->findOrFail($sid);
|
||||
|
||||
$viewers = StoryView::whereStoryId($story->id)
|
||||
->orderByDesc('id')
|
||||
->cursorPaginate(10);
|
||||
|
||||
return StoryViewResource::collection($viewers);
|
||||
}
|
||||
}
|
||||
|
|
20
app/Http/Resources/StoryView.php
Normal file
20
app/Http/Resources/StoryView.php
Normal file
|
@ -0,0 +1,20 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
use App\Services\AccountService;
|
||||
|
||||
class StoryView extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function toArray(Request $request)
|
||||
{
|
||||
return AccountService::get($this->profile_id, true);
|
||||
}
|
||||
}
|
20
app/Http/Resources/StoryViewerResource.php
Normal file
20
app/Http/Resources/StoryViewerResource.php
Normal file
|
@ -0,0 +1,20 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
use App\Services\AccountService;
|
||||
|
||||
class StoryViewerResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
return AccountService::get($this->profile_id, false);
|
||||
}
|
||||
}
|
|
@ -316,6 +316,7 @@ Route::group(['prefix' => 'api'], function() use($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);
|
||||
Route::get('viewers', 'Stories\StoryApiV1Controller@viewers')->middleware($middleware);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue