mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-11-22 06:21:27 +00:00
Add archive api endpoints
This commit is contained in:
parent
f0e648b7b8
commit
94395be9c4
3 changed files with 152 additions and 0 deletions
|
@ -14,6 +14,7 @@ use App\EmailVerification;
|
||||||
use App\Status;
|
use App\Status;
|
||||||
use App\Report;
|
use App\Report;
|
||||||
use App\Profile;
|
use App\Profile;
|
||||||
|
use App\StatusArchived;
|
||||||
use App\User;
|
use App\User;
|
||||||
use App\Services\AccountService;
|
use App\Services\AccountService;
|
||||||
use App\Services\StatusService;
|
use App\Services\StatusService;
|
||||||
|
@ -26,6 +27,7 @@ use Jenssegers\Agent\Agent;
|
||||||
use Mail;
|
use Mail;
|
||||||
use App\Mail\PasswordChange;
|
use App\Mail\PasswordChange;
|
||||||
use App\Mail\ConfirmAppEmail;
|
use App\Mail\ConfirmAppEmail;
|
||||||
|
use App\Http\Resources\StatusStateless;
|
||||||
|
|
||||||
class ApiV1Dot1Controller extends Controller
|
class ApiV1Dot1Controller extends Controller
|
||||||
{
|
{
|
||||||
|
@ -563,4 +565,72 @@ class ApiV1Dot1Controller extends Controller
|
||||||
'access_token' => $token->accessToken
|
'access_token' => $token->accessToken
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function archive(Request $request, $id)
|
||||||
|
{
|
||||||
|
abort_if(!$request->user(), 403);
|
||||||
|
|
||||||
|
$status = Status::whereNull('in_reply_to_id')
|
||||||
|
->whereNull('reblog_of_id')
|
||||||
|
->whereProfileId($request->user()->profile_id)
|
||||||
|
->findOrFail($id);
|
||||||
|
|
||||||
|
if($status->scope === 'archived') {
|
||||||
|
return [200];
|
||||||
|
}
|
||||||
|
|
||||||
|
$archive = new StatusArchived;
|
||||||
|
$archive->status_id = $status->id;
|
||||||
|
$archive->profile_id = $status->profile_id;
|
||||||
|
$archive->original_scope = $status->scope;
|
||||||
|
$archive->save();
|
||||||
|
|
||||||
|
$status->scope = 'archived';
|
||||||
|
$status->visibility = 'draft';
|
||||||
|
$status->save();
|
||||||
|
StatusService::del($status->id, true);
|
||||||
|
AccountService::syncPostCount($status->profile_id);
|
||||||
|
|
||||||
|
return [200];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function unarchive(Request $request, $id)
|
||||||
|
{
|
||||||
|
abort_if(!$request->user(), 403);
|
||||||
|
|
||||||
|
$status = Status::whereNull('in_reply_to_id')
|
||||||
|
->whereNull('reblog_of_id')
|
||||||
|
->whereProfileId($request->user()->profile_id)
|
||||||
|
->findOrFail($id);
|
||||||
|
|
||||||
|
if($status->scope !== 'archived') {
|
||||||
|
return [200];
|
||||||
|
}
|
||||||
|
|
||||||
|
$archive = StatusArchived::whereStatusId($status->id)
|
||||||
|
->whereProfileId($status->profile_id)
|
||||||
|
->firstOrFail();
|
||||||
|
|
||||||
|
$status->scope = $archive->original_scope;
|
||||||
|
$status->visibility = $archive->original_scope;
|
||||||
|
$status->save();
|
||||||
|
$archive->delete();
|
||||||
|
StatusService::del($status->id, true);
|
||||||
|
AccountService::syncPostCount($status->profile_id);
|
||||||
|
|
||||||
|
return [200];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function archivedPosts(Request $request)
|
||||||
|
{
|
||||||
|
abort_if(!$request->user(), 403);
|
||||||
|
|
||||||
|
$statuses = Status::whereProfileId($request->user()->profile_id)
|
||||||
|
->whereScope('archived')
|
||||||
|
->orderByDesc('id')
|
||||||
|
->cursorPaginate(10);
|
||||||
|
|
||||||
|
return StatusStateless::collection($statuses);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
76
app/Http/Resources/StatusStateless.php
Normal file
76
app/Http/Resources/StatusStateless.php
Normal file
|
@ -0,0 +1,76 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Resources;
|
||||||
|
|
||||||
|
use Illuminate\Http\Resources\Json\JsonResource;
|
||||||
|
use Cache;
|
||||||
|
use App\Services\AccountService;
|
||||||
|
use App\Services\HashidService;
|
||||||
|
use App\Services\LikeService;
|
||||||
|
use App\Services\MediaService;
|
||||||
|
use App\Services\MediaTagService;
|
||||||
|
use App\Services\StatusHashtagService;
|
||||||
|
use App\Services\StatusLabelService;
|
||||||
|
use App\Services\StatusMentionService;
|
||||||
|
use App\Services\PollService;
|
||||||
|
use App\Models\CustomEmoji;
|
||||||
|
|
||||||
|
class StatusStateless extends JsonResource
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Transform the resource into an array.
|
||||||
|
*
|
||||||
|
* @param \Illuminate\Http\Request $request
|
||||||
|
* @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
|
||||||
|
*/
|
||||||
|
public function toArray($request)
|
||||||
|
{
|
||||||
|
$status = $this;
|
||||||
|
$taggedPeople = MediaTagService::get($status->id);
|
||||||
|
$poll = $status->type === 'poll' ? PollService::get($status->id) : null;
|
||||||
|
|
||||||
|
return [
|
||||||
|
'_v' => 1,
|
||||||
|
'id' => (string) $status->id,
|
||||||
|
//'gid' => $status->group_id ? (string) $status->group_id : null,
|
||||||
|
'shortcode' => HashidService::encode($status->id),
|
||||||
|
'uri' => $status->url(),
|
||||||
|
'url' => $status->url(),
|
||||||
|
'in_reply_to_id' => $status->in_reply_to_id ? (string) $status->in_reply_to_id : null,
|
||||||
|
'in_reply_to_account_id' => $status->in_reply_to_profile_id ? (string) $status->in_reply_to_profile_id : null,
|
||||||
|
'reblog' => null,
|
||||||
|
'content' => $status->rendered ?? $status->caption,
|
||||||
|
'content_text' => $status->caption,
|
||||||
|
// 'created_at' => str_replace('+00:00', 'Z', $status->created_at->format(DATE_RFC3339_EXTENDED)),
|
||||||
|
'emojis' => CustomEmoji::scan($status->caption),
|
||||||
|
'reblogs_count' => $status->reblogs_count ?? 0,
|
||||||
|
'favourites_count' => $status->likes_count ?? 0,
|
||||||
|
'reblogged' => null,
|
||||||
|
'favourited' => null,
|
||||||
|
'muted' => null,
|
||||||
|
'sensitive' => (bool) $status->is_nsfw,
|
||||||
|
'spoiler_text' => $status->cw_summary ?? '',
|
||||||
|
'visibility' => $status->scope ?? $status->visibility,
|
||||||
|
'application' => [
|
||||||
|
'name' => 'web',
|
||||||
|
'website' => null
|
||||||
|
],
|
||||||
|
'language' => null,
|
||||||
|
'mentions' => StatusMentionService::get($status->id),
|
||||||
|
'pf_type' => $status->type ?? $status->setType(),
|
||||||
|
'reply_count' => (int) $status->reply_count,
|
||||||
|
'comments_disabled' => (bool) $status->comments_disabled,
|
||||||
|
'thread' => false,
|
||||||
|
'replies' => [],
|
||||||
|
'parent' => [],
|
||||||
|
'place' => $status->place,
|
||||||
|
'local' => (bool) $status->local,
|
||||||
|
'taggedPeople' => $taggedPeople,
|
||||||
|
'liked_by' => LikeService::likedBy($status),
|
||||||
|
'media_attachments' => MediaService::get($status->id),
|
||||||
|
'account' => AccountService::get($status->profile_id, true),
|
||||||
|
'tags' => StatusHashtagService::statusTags($status->id),
|
||||||
|
'poll' => $poll
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
|
@ -131,6 +131,12 @@ Route::group(['prefix' => 'api'], function() use($middleware) {
|
||||||
Route::post('lookup', 'DirectMessageController@composeLookup')->middleware($middleware);
|
Route::post('lookup', 'DirectMessageController@composeLookup')->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' => 'stories'], function () use($middleware) {
|
Route::group(['prefix' => 'stories'], function () use($middleware) {
|
||||||
Route::get('recent', 'StoryController@recent')->middleware($middleware);
|
Route::get('recent', 'StoryController@recent')->middleware($middleware);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue