mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-11-10 00:34:50 +00:00
Merge pull request #1576 from pixelfed/frontend-ui-refactor
Frontend ui refactor
This commit is contained in:
commit
450492db53
9 changed files with 773298 additions and 305 deletions
78
app/Console/Commands/ImportCities.php
Normal file
78
app/Console/Commands/ImportCities.php
Normal file
|
@ -0,0 +1,78 @@
|
|||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use App\Place;
|
||||
use DB;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class ImportCities extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'import:cities';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Import Cities to database';
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$path = storage_path('app/cities.json');
|
||||
if(!is_file($path)) {
|
||||
$this->error('Missing storage/app/cities.json file!');
|
||||
return;
|
||||
}
|
||||
|
||||
if(Place::count() > 10) {
|
||||
$this->error('Cities already imported, aborting operation...');
|
||||
return;
|
||||
}
|
||||
$this->info('Importing city data into database ...');
|
||||
|
||||
$cities = file_get_contents($path);
|
||||
$cities = json_decode($cities);
|
||||
$count = count($cities);
|
||||
$this->info("Found {$count} cities to insert ...");
|
||||
$bar = $this->output->createProgressBar($count);
|
||||
$bar->start();
|
||||
|
||||
foreach ($cities as $city) {
|
||||
$country = $city->country == 'XK' ? 'Kosovo' : (new \League\ISO3166\ISO3166)->alpha2($city->country)['name'];
|
||||
DB::transaction(function () use ($city, $country) {
|
||||
$place = new Place();
|
||||
$place->name = $city->name;
|
||||
$place->slug = Str::slug($city->name);
|
||||
$place->country = $country;
|
||||
$place->lat = $city->lat;
|
||||
$place->long = $city->lng;
|
||||
$place->save();
|
||||
});
|
||||
$bar->advance();
|
||||
}
|
||||
$bar->finish();
|
||||
return;
|
||||
}
|
||||
}
|
|
@ -39,12 +39,16 @@ class MediaGarbageCollector extends Command
|
|||
*/
|
||||
public function handle()
|
||||
{
|
||||
$gc = Media::whereNull('status_id')
|
||||
->where('created_at', '<', Carbon::now()->subHours(6)->toDateTimeString())
|
||||
$limit = 20000;
|
||||
|
||||
$gc = Media::doesntHave('status')
|
||||
->where('created_at', '<', Carbon::now()->subHours(1)->toDateTimeString())
|
||||
->orderBy('created_at','asc')
|
||||
->take(500)
|
||||
->take($limit)
|
||||
->get();
|
||||
|
||||
$bar = $this->output->createProgressBar($gc->count());
|
||||
$bar->start();
|
||||
foreach($gc as $media) {
|
||||
$path = storage_path("app/$media->media_path");
|
||||
$thumb = storage_path("app/$media->thumbnail_path");
|
||||
|
@ -55,6 +59,8 @@ class MediaGarbageCollector extends Command
|
|||
unlink($thumb);
|
||||
}
|
||||
$media->forceDelete();
|
||||
$bar->advance();
|
||||
}
|
||||
$bar->finish();
|
||||
}
|
||||
}
|
||||
|
|
23
app/Http/Controllers/PlaceController.php
Normal file
23
app/Http/Controllers/PlaceController.php
Normal file
|
@ -0,0 +1,23 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use App\{
|
||||
Place,
|
||||
Status
|
||||
};
|
||||
|
||||
class PlaceController extends Controller
|
||||
{
|
||||
public function show(Request $request, $id, $slug)
|
||||
{
|
||||
// TODO: Replace with vue component + apis
|
||||
$place = Place::whereSlug($slug)->findOrFail($id);
|
||||
$posts = Status::wherePlaceId($place->id)
|
||||
->whereScope('public')
|
||||
->orderByDesc('created_at')
|
||||
->paginate(10);
|
||||
return view('discover.places.show', compact('place', 'posts'));
|
||||
}
|
||||
}
|
33
app/Place.php
Normal file
33
app/Place.php
Normal file
|
@ -0,0 +1,33 @@
|
|||
<?php
|
||||
|
||||
namespace App;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Pixelfed\Snowflake\HasSnowflakePrimary;
|
||||
|
||||
class Place extends Model
|
||||
{
|
||||
use HasSnowflakePrimary;
|
||||
|
||||
/**
|
||||
* Indicates if the IDs are auto-incrementing.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $incrementing = false;
|
||||
|
||||
public function url()
|
||||
{
|
||||
return url('/discover/places/' . $this->id . '/' . $this->slug);
|
||||
}
|
||||
|
||||
public function posts()
|
||||
{
|
||||
return $this->hasMany(Status::class);
|
||||
}
|
||||
|
||||
public function postCount()
|
||||
{
|
||||
return $this->posts()->count();
|
||||
}
|
||||
}
|
|
@ -23,6 +23,7 @@
|
|||
"laravel/tinker": "^1.0",
|
||||
"league/flysystem-aws-s3-v3": "~1.0",
|
||||
"league/flysystem-cached-adapter": "~1.0",
|
||||
"league/iso3166": "^2.1",
|
||||
"moontoast/math": "^1.1",
|
||||
"pbmedia/laravel-ffmpeg": "4.0.0",
|
||||
"phpseclib/phpseclib": "~2.0",
|
||||
|
@ -38,6 +39,7 @@
|
|||
"stevebauman/purify": "2.0.*"
|
||||
},
|
||||
"require-dev": {
|
||||
"barryvdh/laravel-debugbar": "dev-master",
|
||||
"filp/whoops": "^2.0",
|
||||
"fzaninotto/faker": "^1.4",
|
||||
"mockery/mockery": "^1.0",
|
||||
|
|
793
composer.lock
generated
793
composer.lock
generated
File diff suppressed because it is too large
Load diff
|
@ -0,0 +1,45 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class CreatePlacesTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('places', function (Blueprint $table) {
|
||||
$table->bigIncrements('id');
|
||||
$table->string('slug')->index();
|
||||
$table->string('name')->index();
|
||||
$table->string('country')->index();
|
||||
$table->json('aliases')->nullable();
|
||||
$table->decimal('lat', 9, 6)->nullable();
|
||||
$table->decimal('long', 9, 6)->nullable();
|
||||
$table->unique(['slug', 'country', 'lat', 'long']);
|
||||
$table->timestamps();
|
||||
});
|
||||
|
||||
Schema::table('statuses', function (Blueprint $table) {
|
||||
$table->bigInteger('place_id')->unsigned()->nullable()->index();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('places');
|
||||
Schema::table('statuses', function (Blueprint $table) {
|
||||
$table->dropColumn('place_id');
|
||||
});
|
||||
}
|
||||
}
|
1
storage/app/.gitignore
vendored
1
storage/app/.gitignore
vendored
|
@ -1,3 +1,4 @@
|
|||
*
|
||||
!public/
|
||||
!cities.json
|
||||
!.gitignore
|
||||
|
|
772616
storage/app/cities.json
Executable file
772616
storage/app/cities.json
Executable file
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue