Merge pull request #3117 from pixelfed/staging

Staging
This commit is contained in:
daniel 2022-01-03 00:00:14 -07:00 committed by GitHub
commit 5fc83beb2c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 114 additions and 18 deletions

View file

@ -79,6 +79,7 @@
- Updated RemoteAvatarFetch job, fixed bug preventing new avatars from being stored. ([92bc2845](https://github.com/pixelfed/pixelfed/commit/92bc2845))
- Updated AccountService, fix json casting. ([e5f8f344](https://github.com/pixelfed/pixelfed/commit/e5f8f344))
- Updated ApiV1Controller, fix illegal operator bug by setting default min_id. ([415826f2](https://github.com/pixelfed/pixelfed/commit/415826f2))
- Updated StatusService, add getMastodon method for mastoapi compatibility. ([36a129fe](https://github.com/pixelfed/pixelfed/commit/36a129fe))
- ([](https://github.com/pixelfed/pixelfed/commit/))
## [v0.11.1 (2021-09-07)](https://github.com/pixelfed/pixelfed/compare/v0.11.0...v0.11.1)

View file

@ -89,6 +89,26 @@ class PublicApiController extends Controller
}
}
public function getStatus(Request $request, $id)
{
abort_if(!$request->user(), 403);
$status = StatusService::get($id, false);
abort_if(!$status, 404);
if(in_array($status['visibility'], ['public', 'unlisted'])) {
return $status;
}
$pid = $request->user()->profile_id;
if($status['account']['id'] == $pid) {
return $status;
}
if($status['visibility'] == 'private') {
if(FollowerService::follows($pid, $status['account']['id'])) {
return $status;
}
}
abort(404);
}
public function status(Request $request, $username, int $postid)
{
$profile = Profile::whereUsername($username)->whereNull('status')->firstOrFail();

View file

@ -21,7 +21,8 @@ class Profile extends Model
protected $dates = [
'deleted_at',
'last_fetched_at'
'last_fetched_at',
'last_status_at'
];
protected $hidden = ['private_key'];
protected $visible = ['id', 'user_id', 'username', 'name'];

View file

@ -6,7 +6,6 @@ use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Redis;
use DB;
use App\Status;
//use App\Transformer\Api\v3\StatusTransformer;
use App\Transformer\Api\StatusStatelessTransformer;
use App\Transformer\Api\StatusTransformer;
use League\Fractal;
@ -41,6 +40,49 @@ class StatusService
});
}
public static function getMastodon($id, $publicOnly = true)
{
$status = self::get($id, $publicOnly);
if(!$status) {
return null;
}
$status['replies_count'] = $status['reply_count'];
unset(
$status['_v'],
$status['comments_disabled'],
$status['content_text'],
$status['gid'],
$status['label'],
$status['liked_by'],
$status['local'],
$status['parent'],
$status['pf_type'],
$status['place'],
$status['replies'],
$status['reply_count'],
$status['shortcode'],
$status['taggedPeople'],
$status['thread'],
$status['account']['header_bg'],
$status['account']['is_admin'],
$status['account']['last_fetched_at'],
$status['account']['local'],
$status['account']['location'],
$status['account']['note_text'],
$status['account']['pronouns'],
$status['account']['website'],
);
$status['account']['avatar_static'] = $status['account']['avatar'];
$status['account']['bot'] = false;
$status['account']['emojis'] = [];
$status['account']['fields'] = [];
$status['account']['header'] = url('/storage/headers/missing.png');
$status['account']['header_static'] = url('/storage/headers/missing.png');
$status['account']['last_status_at'] = null;
return $status;
}
public static function getState($id, $pid)
{
$status = self::get($id, false);

View file

@ -11,7 +11,6 @@ class AccountTransformer extends Fractal\TransformerAbstract
public function transform(Profile $profile)
{
$local = $profile->domain == null;
$is_admin = !$local ? false : $profile->user->is_admin;
$username = $local ? $profile->username : explode('@', substr($profile->username, 1))[0];
return [
'id' => (string) $profile->id,
@ -19,22 +18,21 @@ class AccountTransformer extends Fractal\TransformerAbstract
'acct' => $username,
'display_name' => $profile->name,
'locked' => (bool) $profile->is_private,
'bot' => false,
'created_at' => $profile->created_at->toJSON(),
'followers_count' => $profile->followerCount(),
'following_count' => $profile->followingCount(),
'statuses_count' => (int) $profile->statusCount(),
'note' => $profile->bio ?? '',
'url' => $profile->url(),
'avatar' => $profile->avatarUrl(),
'avatar_static' => $profile->avatarUrl(),
'header' => '',
'header_static' => '',
'followers_count' => (int) $profile->followerCount(),
'following_count' => (int) $profile->followingCount(),
'statuses_count' => (int) $profile->statusCount(),
'last_status_at' => optional($profile->last_status_at)->toJSON(),
'emojis' => [],
'moved' => null,
'fields' => null,
'bot' => false,
'software' => 'pixelfed',
'is_admin' => (bool) $is_admin,
'fields' => [],
];
}
}

View file

@ -13,10 +13,9 @@ class MediaTransformer extends Fractal\TransformerAbstract
'id' => (string) $media->id,
'type' => lcfirst($media->activityVerb()),
'url' => $media->url(),
'remote_url' => null,
'preview_url' => $media->thumbnailUrl(),
'text_url' => null,
'meta' => null,
'remote_url' => $media->remote_url,
'text_url' => $media->url(),
'description' => $media->caption,
'blurhash' => $media->blurhash ?? 'U4Rfzst8?bt7ogayj[j[~pfQ9Goe%Mj[WBay'
];
@ -38,4 +37,4 @@ class MediaTransformer extends Fractal\TransformerAbstract
return $res;
}
}
}

View file

@ -9,11 +9,13 @@ class MentionTransformer extends Fractal\TransformerAbstract
{
public function transform(Profile $profile)
{
$local = $profile->domain == null;
$username = $local ? $profile->username : explode('@', substr($profile->username, 1))[0];
return [
'id' => (string) $profile->id,
'url' => $profile->url(),
'username' => $profile->username,
'acct' => $profile->username,
'acct' => $username,
];
}
}

View file

@ -17,14 +17,14 @@ class StatusTransformer extends Fractal\TransformerAbstract
'id' => (string) $status->id,
'created_at' => $status->created_at->toJSON(),
'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,
'in_reply_to_account_id' => $status->in_reply_to_profile_id ? (string) $status->in_reply_to_profile_id : null,
'sensitive' => (bool) $status->is_nsfw,
'spoiler_text' => $status->cw_summary ?? '',
'visibility' => $status->visibility ?? $status->scope,
'language' => 'en',
'uri' => $status->url(),
'uri' => $status->permalink(''),
'url' => $status->url(),
'replies_count' => 0,
'replies_count' => $status->reply_count ?? 0,
'reblogs_count' => $status->reblogs_count ?? 0,
'favourites_count' => $status->likes_count ?? 0,
'reblogged' => $status->shared(),

View file

@ -0,0 +1,32 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class AddLastStatusAtToProfilesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('profiles', function (Blueprint $table) {
$table->timestamp('last_status_at')->nullable();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('profiles', function (Blueprint $table) {
$table->dropColumn('last_status_at');
});
}
}

BIN
public/js/spa.js vendored

Binary file not shown.

Binary file not shown.

View file

@ -163,6 +163,7 @@ Route::domain(config('pixelfed.domain.app'))->middleware(['validemail', 'twofact
Route::get('accounts/{id}/followers', 'PublicApiController@accountFollowers');
Route::post('accounts/{id}/block', 'Api\ApiV1Controller@accountBlockById');
Route::post('accounts/{id}/unblock', 'Api\ApiV1Controller@accountUnblockById');
Route::get('statuses/{id}', 'PublicApiController@getStatus');
Route::get('accounts/{id}', 'PublicApiController@account');
Route::post('avatar/update', 'ApiController@avatarUpdate');
Route::get('custom_emojis', 'Api\ApiV1Controller@customEmojis');