Jelajahi Sumber

Postgres fixes

Daniel Supernault 6 bulan lalu
induk
melakukan
1d2f76c8e5

+ 7 - 1
app/Http/Controllers/Api/ApiV1Controller.php

@@ -3494,7 +3494,8 @@ class ApiV1Controller extends Controller
             return [];
         }
 
-        $content = $request->filled('status') ? strip_tags($request->input('status')) : null;
+        $defaultCaption = config_cache('database.default') === 'mysql' ? null : "";
+        $content = $request->filled('status') ? strip_tags($request->input('status')) : $defaultCaption;
         $cw = $user->profile->cw == true ? true : $request->boolean('sensitive', false);
         $spoilerText = $cw && $request->filled('spoiler_text') ? $request->input('spoiler_text') : null;
 
@@ -3508,6 +3509,7 @@ class ApiV1Controller extends Controller
 
             $status = new Status;
             $status->caption = $content;
+            $status->rendered = $defaultCaption;
             $status->scope = $visibility;
             $status->visibility = $visibility;
             $status->profile_id = $user->profile_id;
@@ -3532,6 +3534,7 @@ class ApiV1Controller extends Controller
             if (! $in_reply_to_id) {
                 $status = new Status;
                 $status->caption = $content;
+                $status->rendered = $defaultCaption;
                 $status->profile_id = $user->profile_id;
                 $status->is_nsfw = $cw;
                 $status->cw_summary = $spoilerText;
@@ -3684,7 +3687,10 @@ class ApiV1Controller extends Controller
             }
         }
 
+        $defaultCaption = config_cache('database.default') === 'mysql' ? null : "";
         $share = Status::firstOrCreate([
+            'caption' => $defaultCaption,
+            'rendered' => $defaultCaption,
             'profile_id' => $user->profile_id,
             'reblog_of_id' => $status->id,
             'type' => 'share',

+ 3 - 2
app/Http/Controllers/Api/ApiV1Dot1Controller.php

@@ -1292,13 +1292,14 @@ class ApiV1Dot1Controller extends Controller
         if ($user->last_active_at == null) {
             return [];
         }
-
-        $content = $request->filled('status') ? strip_tags(Purify::clean($request->input('status'))) : null;
+        $defaultCaption = config_cache('database.default') === 'mysql' ? null : "";
+        $content = $request->filled('status') ? strip_tags(Purify::clean($request->input('status'))) : $defaultCaption;
         $cw = $user->profile->cw == true ? true : $request->boolean('sensitive', false);
         $spoilerText = $cw && $request->filled('spoiler_text') ? $request->input('spoiler_text') : null;
 
         $status = new Status;
         $status->caption = $content;
+        $status->rendered = $defaultCaption;
         $status->profile_id = $user->profile_id;
         $status->is_nsfw = $cw;
         $status->cw_summary = $spoilerText;

+ 3 - 0
app/Http/Controllers/CommentController.php

@@ -55,11 +55,14 @@ class CommentController extends Controller
         }
 
         $reply = DB::transaction(function () use ($comment, $status, $profile, $nsfw) {
+            $defaultCaption = config_cache('database.default') === 'mysql' ? null : "";
+
             $scope = $profile->is_private == true ? 'private' : 'public';
             $reply = new Status;
             $reply->profile_id = $profile->id;
             $reply->is_nsfw = $nsfw;
             $reply->caption = Purify::clean($comment);
+            $reply->rendered = $defaultCaption;
             $reply->in_reply_to_id = $status->id;
             $reply->in_reply_to_profile_id = $status->profile_id;
             $reply->scope = $scope;

+ 7 - 2
app/Http/Controllers/ComposeController.php

@@ -30,6 +30,7 @@ use App\Util\Media\License;
 use Auth;
 use Cache;
 use DB;
+use Purify;
 use Illuminate\Http\Request;
 use Illuminate\Support\Str;
 use League\Fractal;
@@ -569,7 +570,9 @@ class ComposeController extends Controller
             $status->cw_summary = $request->input('spoiler_text');
         }
 
-        $status->caption = strip_tags($request->caption);
+        $defaultCaption = config_cache('database.default') === 'mysql' ? null : "";
+        $status->caption = strip_tags($request->input('caption')) ?? $defaultCaption;
+        $status->rendered = $defaultCaption;
         $status->scope = 'draft';
         $status->visibility = 'draft';
         $status->profile_id = $profile->id;
@@ -673,6 +676,7 @@ class ComposeController extends Controller
         $place = $request->input('place');
         $cw = $request->input('cw');
         $tagged = $request->input('tagged');
+        $defaultCaption = config_cache('database.default') === 'mysql' ? null : "";
 
         if ($place && is_array($place)) {
             $status->place_id = $place['id'];
@@ -682,7 +686,8 @@ class ComposeController extends Controller
             $status->comments_disabled = (bool) $request->input('comments_disabled');
         }
 
-        $status->caption = strip_tags($request->caption);
+        $status->caption = $request->filled('caption') ? strip_tags($request->caption) : $defaultCaption;
+        $status->rendered = $defaultCaption;
         $status->profile_id = $profile->id;
         $entities = [];
         $visibility = $profile->unlisted == true && $visibility == 'public' ? 'unlisted' : $visibility;

+ 3 - 1
app/Http/Controllers/StatusController.php

@@ -309,7 +309,7 @@ class StatusController extends Controller
         abort_if(! $statusAccount || isset($statusAccount['moved'], $statusAccount['moved']['id']), 422, 'Account moved');
 
         $count = $status->reblogs_count;
-
+        $defaultCaption = config_cache('database.default') === 'mysql' ? null : "";
         $exists = Status::whereProfileId(Auth::user()->profile->id)
             ->whereReblogOfId($status->id)
             ->exists();
@@ -324,6 +324,8 @@ class StatusController extends Controller
             }
         } else {
             $share = new Status;
+            $share->caption = $defaultCaption;
+            $share->rendered = $defaultCaption;
             $share->profile_id = $profile->id;
             $share->reblog_of_id = $status->id;
             $share->in_reply_to_profile_id = $status->profile_id;

+ 5 - 3
app/Util/ActivityPub/Helpers.php

@@ -543,7 +543,7 @@ class Helpers
                 $scope = 'unlisted';
             }
         }
-
+        $defaultCaption = config_cache('database.default') === 'mysql' ? null : "";
         $status = Status::updateOrCreate(
             [
                 'uri' => $url,
@@ -551,7 +551,8 @@ class Helpers
                 'profile_id' => $pid,
                 'url' => $url,
                 'object_url' => $id,
-                'caption' => isset($activity['content']) ? Purify::clean(strip_tags($activity['content'])) : null,
+                'caption' => isset($activity['content']) ? Purify::clean(strip_tags($activity['content'])) : $defaultCaption,
+                'rendered' => $defaultCaption,
                 'created_at' => Carbon::parse($ts)->tz('UTC'),
                 'in_reply_to_id' => $reply_to,
                 'local' => false,
@@ -693,7 +694,8 @@ class Helpers
         $status->url = isset($res['url']) ? $res['url'] : $url;
         $status->uri = isset($res['url']) ? $res['url'] : $url;
         $status->object_url = $id;
-        $status->caption = strip_tags(Purify::clean($res['content']));
+        $status->caption = strip_tags(Purify::clean($res['content'])) ?? "";
+        $status->rendered = "";
         $status->created_at = Carbon::parse($ts)->tz('UTC');
         $status->in_reply_to_id = null;
         $status->local = false;

+ 8 - 3
app/Util/ActivityPub/HttpSignature.php

@@ -71,9 +71,14 @@ class HttpSignature
     public static function instanceActorSign($url, $body = false, $addlHeaders = [], $method = 'post')
     {
         $keyId = config('app.url').'/i/actor#main-key';
-        $privateKey = Cache::rememberForever(InstanceActor::PKI_PRIVATE, function () {
-            return InstanceActor::first()->private_key;
-        });
+        if(config_cache('database.default') === 'mysql') {
+            $privateKey = Cache::rememberForever(InstanceActor::PKI_PRIVATE, function () {
+                return InstanceActor::first()->private_key;
+            });
+        } else {
+            $privateKey = InstanceActor::first()?->private_key;
+        }
+        abort_if(!$privateKey || empty($privateKey), 400, 'Missing instance actor key, please run php artisan instance:actor');
         if ($body) {
             $digest = self::_digest($body);
         }