mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-11-18 12:31:27 +00:00
Merge pull request #521 from pixelfed/frontend-ui-refactor
Frontend ui refactor
This commit is contained in:
commit
9352413ef2
9 changed files with 175 additions and 5 deletions
|
@ -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);
|
||||
}
|
||||
|
|
60
app/Console/Commands/MediaGarbageCollector.php
Normal file
60
app/Console/Commands/MediaGarbageCollector.php
Normal file
|
@ -0,0 +1,60 @@
|
|||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use App\{Media, Status};
|
||||
use Carbon\Carbon;
|
||||
|
||||
class MediaGarbageCollector extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'media:gc';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Delete media uploads not attached to any active statuses';
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$gc = Media::whereNull('status_id')
|
||||
->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();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -27,6 +27,8 @@ class Kernel extends ConsoleKernel
|
|||
{
|
||||
$schedule->command('media:optimize')
|
||||
->hourly();
|
||||
$schedule->command('media:gc')
|
||||
->hourly();
|
||||
$schedule->command('horizon:snapshot')->everyFiveMinutes();
|
||||
}
|
||||
|
||||
|
|
|
@ -82,6 +82,7 @@ class DiscoverController extends Controller
|
|||
->firstOrFail();
|
||||
|
||||
$posts = $tag->posts()
|
||||
->withCount(['likes', 'comments'])
|
||||
->whereIsNsfw(false)
|
||||
->whereVisibility('public')
|
||||
->has('media')
|
||||
|
|
|
@ -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];
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class UpdateMediaAddAltText extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('media', function (Blueprint $table) {
|
||||
$table->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');
|
||||
});
|
||||
}
|
||||
}
|
|
@ -61,7 +61,7 @@
|
|||
<div class="cwrapper d-none">
|
||||
<p class="mb-1 text-center load-more-link"><a href="#" class="text-muted" v-on:click="loadMore">Load more comments</a></p>
|
||||
<div class="comments" data-min-id="0" data-max-id="0">
|
||||
<p class="mb-2 d-flex justify-content-between align-items-center" v-for="(comment, index) in results" :data-id="comment.id" v-bind:key="comment.id">
|
||||
<p class="mb-0 d-flex justify-content-between align-items-center" v-for="(comment, index) in results" :data-id="comment.id" v-bind:key="comment.id">
|
||||
<span class="pr-3">
|
||||
<span class="font-weight-bold pr-1"><bdi><a class="text-dark" :href="comment.account.url">{{comment.account.username}}</a></bdi></span>
|
||||
<span class="comment-text" v-html="comment.content"></span>
|
||||
|
|
|
@ -35,7 +35,7 @@ $(document).ready(function() {
|
|||
var comments = el.parents().eq(1).find('.comments');
|
||||
}
|
||||
|
||||
var comment = '<p class="mb-2"><span class="font-weight-bold pr-1"><bdi><a class="text-dark" href="' + profile + '">' + username + '</a></bdi></span><span class="comment-text">'+ reply + '</span></p>';
|
||||
var comment = '<p class="mb-0"><span class="font-weight-bold pr-1"><bdi><a class="text-dark" href="' + profile + '">' + username + '</a></bdi></span><span class="comment-text">'+ reply + '</span></p>';
|
||||
|
||||
comments.prepend(comment);
|
||||
|
||||
|
|
|
@ -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');
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue