Przeglądaj źródła

Update Api Transformers, force string type for ids

Daniel Supernault 6 lat temu
rodzic
commit
261c33e7d8

+ 4 - 2
app/Transformer/Api/AccountTransformer.php

@@ -9,8 +9,9 @@ class AccountTransformer extends Fractal\TransformerAbstract
 {
 	public function transform(Profile $profile)
 	{
+		$is_admin = $profile->domain ? false : $profile->user->is_admin;
 		return [
-			'id' => $profile->id,
+			'id' => (string) $profile->id,
 			'username' => $profile->username,
 			'acct' => $profile->username,
 			'display_name' => $profile->name,
@@ -28,7 +29,8 @@ class AccountTransformer extends Fractal\TransformerAbstract
 			'moved' => null,
 			'fields' => null,
 			'bot' => null,
-			'software' => 'pixelfed'
+			'software' => 'pixelfed',
+			'is_admin' => (bool) $is_admin
 		];
 	}
 }

+ 1 - 1
app/Transformer/Api/AttachmentTransformer.php

@@ -9,7 +9,7 @@ class AttachmentTransformer extends Fractal\TransformerAbstract
 	public function transform(Media $media)
 	{
 		return [
-			'id'			=> $media->id,
+			'id'			=> (string) $media->id,
 			'type'			=> $media->activityVerb(),
 			'url'			=> $media->url(),
 			'remote_url' 	=> null,

+ 1 - 1
app/Transformer/Api/MediaTransformer.php

@@ -10,7 +10,7 @@ class MediaTransformer extends Fractal\TransformerAbstract
     public function transform(Media $media)
     {
         return [
-            'id'            => $media->id,
+            'id'            => (string) $media->id,
             'type'          => $media->activityVerb(),
             'url'           => $media->url(),
             'remote_url'    => null,

+ 1 - 1
app/Transformer/Api/MentionTransformer.php

@@ -10,7 +10,7 @@ class MentionTransformer extends Fractal\TransformerAbstract
     public function transform(Profile $profile)
     {
         return [
-            'id'       => $profile->id,
+            'id'       => (string) $profile->id,
             'url'      => $profile->url(),
             'username' => $profile->username,
             'acct'     => $profile->username,

+ 1 - 1
app/Transformer/Api/NotificationTransformer.php

@@ -15,7 +15,7 @@ class NotificationTransformer extends Fractal\TransformerAbstract
 	public function transform(Notification $notification)
 	{
 		return [
-			'id'       		=> $notification->id,
+			'id'       		=> (string) $notification->id,
 			'type'       	=> $this->replaceTypeVerb($notification->action),
 			'created_at' 	=> (string) $notification->created_at,
 			'account' 		=> null,

+ 6 - 4
app/Transformer/Api/RelationshipTransformer.php

@@ -2,6 +2,7 @@
 
 namespace App\Transformer\Api;
 
+use Auth;
 use App\Profile;
 use League\Fractal;
 
@@ -9,17 +10,18 @@ class RelationshipTransformer extends Fractal\TransformerAbstract
 {
     public function transform(Profile $profile)
     {
+        $user = Auth::user()->profile;
         return [
-            'id' => $profile->id,
-            'following' => null,
-            'followed_by' => null,
+            'id' => (string) $profile->id,
+            'following' => $user->follows($profile),
+            'followed_by' => $user->followedBy($profile),
             'blocking' => null,
             'muting' => null,
             'muting_notifications' => null,
             'requested' => null,
             'domain_blocking' => null,
             'showing_reblogs' => null,
-            'endorsed' => null
+            'endorsed' => false
         ];
     }
 }

+ 1 - 1
app/Transformer/Api/StatusTransformer.php

@@ -17,7 +17,7 @@ class StatusTransformer extends Fractal\TransformerAbstract
     public function transform(Status $status)
     {
         return [
-            'id'                        => $status->id,
+            'id'                        => (string) $status->id,
             'uri'                       => $status->url(),
             'url'                       => $status->url(),
             'in_reply_to_id'            => $status->in_reply_to_id,

+ 1 - 1
app/Transformer/Api/StoryTransformer.php

@@ -14,7 +14,7 @@ class StoryTransformer extends Fractal\TransformerAbstract
     public function transform(Story $story)
     {
         return [
-            'id'                        => $story->id,
+            'id'                        => (string) $story->id,
             'photo'                     => $story->profile->avatarUrl(),
             'name'                      => '',
             'link'                      => '',