diff --git a/app/Console/Commands/CatchUnoptimizedMedia.php b/app/Console/Commands/CatchUnoptimizedMedia.php index 0ca48b850..22ae56be1 100644 --- a/app/Console/Commands/CatchUnoptimizedMedia.php +++ b/app/Console/Commands/CatchUnoptimizedMedia.php @@ -39,7 +39,7 @@ class CatchUnoptimizedMedia extends Command */ public function handle() { - $medias = Media::whereNull('processed_at')->take(50)->get(); + $medias = Media::whereNotNull('status_id')->whereNull('processed_at')->take(250)->get(); foreach ($medias as $media) { ImageOptimize::dispatch($media); } diff --git a/app/Console/Commands/MediaGarbageCollector.php b/app/Console/Commands/MediaGarbageCollector.php new file mode 100644 index 000000000..2a91c5148 --- /dev/null +++ b/app/Console/Commands/MediaGarbageCollector.php @@ -0,0 +1,60 @@ +where('created_at', '<', Carbon::now()->subHours(6)->toDateTimeString()) + ->orderBy('created_at','asc') + ->take(500) + ->get(); + + foreach($gc as $media) { + $path = storage_path("app/$media->media_path"); + $thumb = storage_path("app/$media->thumbnail_path"); + if(is_file($path)) { + unlink($path); + } + if(is_file($thumb)) { + unlink($thumb); + } + $media->forceDelete(); + } + } +} diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index 37dfa92db..18057725e 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -27,6 +27,8 @@ class Kernel extends ConsoleKernel { $schedule->command('media:optimize') ->hourly(); + $schedule->command('media:gc') + ->hourly(); $schedule->command('horizon:snapshot')->everyFiveMinutes(); } diff --git a/app/Http/Controllers/DiscoverController.php b/app/Http/Controllers/DiscoverController.php index f991e4f04..f4b0097ca 100644 --- a/app/Http/Controllers/DiscoverController.php +++ b/app/Http/Controllers/DiscoverController.php @@ -82,6 +82,7 @@ class DiscoverController extends Controller ->firstOrFail(); $posts = $tag->posts() + ->withCount(['likes', 'comments']) ->whereIsNsfw(false) ->whereVisibility('public') ->has('media') diff --git a/app/Status.php b/app/Status.php index 70095d3f6..a3a14dd38 100644 --- a/app/Status.php +++ b/app/Status.php @@ -218,4 +218,71 @@ class Status extends Model { return $this->comments()->orderBy('created_at', 'desc')->take(3); } + + public function toActivityPubObject() + { + if($this->local == false) { + return; + } + $profile = $this->profile; + $to = $this->scopeToAudience('to'); + $cc = $this->scopeToAudience('cc'); + return [ + '@context' => 'https://www.w3.org/ns/activitystreams', + 'id' => $this->permalink(), + 'type' => 'Create', + 'actor' => $profile->permalink(), + 'published' => $this->created_at->format('c'), + 'to' => $to, + 'cc' => $cc, + 'object' => [ + 'id' => $this->url(), + 'type' => 'Note', + 'summary' => null, + 'inReplyTo' => null, + 'published' => $this->created_at->format('c'), + 'url' => $this->url(), + 'attributedTo' => $this->profile->url(), + 'to' => $to, + 'cc' => $cc, + 'sensitive' => (bool) $this->is_nsfw, + 'content' => $this->rendered, + 'attachment' => $this->media->map(function($media) { + return [ + 'type' => 'Document', + 'mediaType' => $media->mime, + 'url' => $media->url(), + 'name' => null + ]; + }) + ] + ]; + } + + public function scopeToAudience($audience) + { + if(!in_array($audience, ['to', 'cc']) || $this->local == false) { + return; + } + $res = []; + $res['to'] = []; + $res['cc'] = []; + $scope = $this->scope; + switch ($scope) { + case 'public': + $res['to'] = [ + "https://www.w3.org/ns/activitystreams#Public" + ]; + $res['cc'] = [ + $this->profile->permalink('/followers') + ]; + break; + + default: + # code... + break; + } + return $res[$audience]; + } + } diff --git a/database/migrations/2018_10_18_035552_update_media_add_alt_text.php b/database/migrations/2018_10_18_035552_update_media_add_alt_text.php new file mode 100644 index 000000000..b671b5fcd --- /dev/null +++ b/database/migrations/2018_10_18_035552_update_media_add_alt_text.php @@ -0,0 +1,40 @@ +string('license')->nullable()->after('filter_class'); + $table->boolean('is_nsfw')->default(false)->after('user_id'); + $table->tinyInteger('version')->default(1); + $table->boolean('remote_media')->default(false)->after('is_nsfw'); + $table->string('remote_url')->nullable()->after('thumbnail_url'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('media', function (Blueprint $table) { + $table->dropColumn('license'); + $table->dropColumn('is_nsfw'); + $table->dropColumn('version'); + $table->dropColumn('remote_media'); + $table->dropColumn('remote_url'); + }); + } +} diff --git a/resources/assets/js/components/PostComments.vue b/resources/assets/js/components/PostComments.vue index a75bda6cf..25ed738f7 100644 --- a/resources/assets/js/components/PostComments.vue +++ b/resources/assets/js/components/PostComments.vue @@ -61,7 +61,7 @@
-

+

{{comment.account.username}} diff --git a/resources/assets/js/components/commentform.js b/resources/assets/js/components/commentform.js index 3f0482718..0563fecc9 100644 --- a/resources/assets/js/components/commentform.js +++ b/resources/assets/js/components/commentform.js @@ -35,7 +35,7 @@ $(document).ready(function() { var comments = el.parents().eq(1).find('.comments'); } - var comment = '

' + username + ''+ reply + '

'; + var comment = '

' + username + ''+ reply + '

'; comments.prepend(comment); diff --git a/routes/web.php b/routes/web.php index bca457676..5bd5b628c 100644 --- a/routes/web.php +++ b/routes/web.php @@ -178,7 +178,7 @@ Route::domain(config('pixelfed.domain.app'))->middleware(['validemail', 'twofact Route::post('p/{username}/{id}/edit', 'StatusController@editStore'); Route::get('p/{username}/{id}', 'StatusController@show'); Route::get('{username}/saved', 'ProfileController@savedBookmarks'); - Route::get('{username}/followers', 'ProfileController@followers'); - Route::get('{username}/following', 'ProfileController@following'); + Route::get('{username}/followers', 'ProfileController@followers')->middleware('auth'); + Route::get('{username}/following', 'ProfileController@following')->middleware('auth'); Route::get('{username}', 'ProfileController@show'); });