Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resource Files #106

Merged
merged 38 commits into from
Feb 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
31ced4e
Installed spatie/laravel-medialibrary
dsbilling Jan 25, 2022
24d8a8a
Updated styling for breif
dsbilling Jan 26, 2022
39e38a5
Config and migration for spatie/laravel-medialibrary
dsbilling Jan 27, 2022
c49baa1
WIP Livewire Modal for resource updates
dsbilling Jan 27, 2022
2e739df
Create 2022_01_27_152349_create_resource_updates_table.php
dsbilling Jan 27, 2022
bb58687
Create ResourceUpdate.php
dsbilling Jan 27, 2022
3398629
Updated github api repo url
dsbilling Jan 27, 2022
fa029b6
Create GameVersion.php
dsbilling Jan 27, 2022
cb4a64d
Update GameVersion.php
dsbilling Jan 27, 2022
0f006b2
Create 2022_01_27_153328_create_game_versions_table.php
dsbilling Jan 27, 2022
b3ea882
Added latest to game version
dsbilling Jan 27, 2022
9a4a13f
Create SyncGameVersion.php
dsbilling Jan 27, 2022
d68be1b
Updated download url name
dsbilling Jan 27, 2022
6ba7ead
Updated latest function
dsbilling Jan 27, 2022
8583fa8
Get latest release from model
dsbilling Jan 27, 2022
b2f9ac7
Delete GitHubHelper.php
dsbilling Jan 27, 2022
1067fb1
Remove GitHubHelper
dsbilling Jan 27, 2022
48fca7d
Show date when over a year since date
dsbilling Jan 27, 2022
65c3aaa
Sync github releases daily
dsbilling Jan 27, 2022
bc30f88
Merge pull request #107 from P3D-Legacy/github-game-version
dsbilling Jan 27, 2022
be21c86
Properly update or create a model entry
dsbilling Jan 27, 2022
f6a5054
Add some fields to update modal
dsbilling Feb 2, 2022
9407c3c
Update app.blade.php
dsbilling Feb 2, 2022
377c68f
Add FilePond cdn
dsbilling Feb 2, 2022
fa28e19
Add media to ResourceUpdate model
dsbilling Feb 2, 2022
1ada762
Pass resource to modal
dsbilling Feb 2, 2022
6a97a80
Add FilePond to modal
dsbilling Feb 2, 2022
ef444e7
WIP file upload
dsbilling Feb 2, 2022
da0a47a
Added relation
dsbilling Feb 6, 2022
cab4be0
Update resource-show.blade.php
dsbilling Feb 6, 2022
9d44315
Update ResourceEdit.php
dsbilling Feb 6, 2022
5e5bf29
Description
dsbilling Feb 6, 2022
45720cf
Add our own easymde editor component
dsbilling Feb 6, 2022
80fa493
Using our own easymde component
dsbilling Feb 6, 2022
0bb4fc7
Add validation
dsbilling Feb 6, 2022
c88c4bb
Pretty
dsbilling Feb 6, 2022
273c617
Update UpdateCreate.php
dsbilling Feb 6, 2022
dc1b107
Add game version to resource update
dsbilling Feb 7, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ GAMEJOLT_GAME_PRIVATE_KEY=null

GAMEJOLT_USER_ID_SUPERADMIN=null

GITHUB_API_REPO=https://api.github.com/repos/P3D-Legacy/P3D-Legacy/releases/latest
GITHUB_API_REPO=https://api.github.com/repos/P3D-Legacy/P3D-Legacy

SKIN_MAX_UPLOAD=10

Expand Down
64 changes: 64 additions & 0 deletions app/Console/Commands/SyncGameVersion.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php

namespace App\Console\Commands;

use App\Models\GameVersion;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Http;

class SyncGameVersion extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'github:syncrelease';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Sync the latest release from GitHub';

/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}

/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
$api_url = env('GITHUB_API_REPO');
if(!$api_url) {
$this->error("GitHub API URL is not set.");
return 1;
}
$release_url = env('GITHUB_API_REPO').'/releases';
$response = Http::get($release_url)->json();

foreach ($response as $release) {
$date = new \DateTime($release['published_at']);
$data = [
'version' => $release['tag_name'],
'title' => $release['name'],
'release_date' => $date,
'page_url' => $release['html_url'],
'download_url' => $release['assets'][0]['browser_download_url'],
];
$version = GameVersion::updateOrCreate(['version' => $release['tag_name']], $data);
$this->info("Updated or created release: ".$version->version);
}
$this->info('Done.');
}
}
1 change: 1 addition & 0 deletions app/Console/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ protected function schedule(Schedule $schedule)
$schedule->command('p3d:skinuserupdate')->hourlyAt(10);
$schedule->command('server:pingall')->hourly();
$schedule->command('gj:update-trophies')->hourly();
$schedule->command('github:syncrelease')->daily();
$schedule->command(RunHealthChecksCommand::class)->everyMinute();
}

Expand Down
83 changes: 0 additions & 83 deletions app/Helpers/GitHubHelper.php

This file was deleted.

5 changes: 3 additions & 2 deletions app/Http/Livewire/Resource/ResourceEdit.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ public function mount(Resource $resource)
$this->categories = Category::all();
}

public function save() {
public function save()
{
$this->validate([
'name' => [
'required',
Expand Down Expand Up @@ -57,7 +58,7 @@ public function save() {
$this->resource->syncCategories($category);

$this->emit('resourceUpdated', $this->resource->id);

$this->closeModal();
}

Expand Down
69 changes: 69 additions & 0 deletions app/Http/Livewire/Resource/UpdateCreate.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php

namespace App\Http\Livewire\Resource;

use App\Models\GameVersion;
use App\Models\Resource;
use Livewire\WithFileUploads;
use App\Models\ResourceUpdate;
use LivewireUI\Modal\ModalComponent;

class UpdateCreate extends ModalComponent
{
use WithFileUploads;

public ResourceUpdate $resourceUpdate;
public int|Resource $resource;
public $file;
public $version;
public $description;
public $gameversion;
public $gameversions;

protected array $rules = [
'version' => [
'required',
'string',
],
'description' => [
'required',
'string',
],
'file' => [
'required',
'file',
'mimes:zip'
],
'gameversion' => [
'required',
],
];

public function mount(int|Resource $resource)
{
$this->resource = $resource;
$this->gameversions = GameVersion::all();
}

public function save()
{
$this->validate();

$this->resourceUpdate = ResourceUpdate::create([
'title' => $this->version,
'description' => $this->description,
'resource_id' => $this->resource,
'game_version_id' => $this->gameversion,
]);

$this->resourceUpdate->clearMediaCollection('resource_update_file');
$this->resourceUpdate->addMedia($this->file->getRealPath())->toMediaCollection('resource_update_file');

return redirect()->route('posts.index');
}

public function render()
{
return view('livewire.resource.update-create');
}
}
29 changes: 29 additions & 0 deletions app/Models/GameVersion.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class GameVersion extends Model
{
use HasFactory;

protected $fillable = [
'version',
'title',
'release_date',
'page_url',
'download_url',
];

protected $dates = [
'release_date',
];

public static function latest()
{
return self::query()->orderBy('release_date', 'desc')->first();
}

}
10 changes: 9 additions & 1 deletion app/Models/Resource.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,20 @@ public static function boot()
'description',
'user_id',
];

/**
* Get the user that made this post.
*/
public function user()
{
return $this->belongsTo(User::class);
}

/**
* Get the updates related to this resource.
*/
public function updates()
{
return $this->hasMany(ResourceUpdate::class);
}
}
28 changes: 28 additions & 0 deletions app/Models/ResourceUpdate.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace App\Models;

use Spatie\MediaLibrary\HasMedia;
use Illuminate\Database\Eloquent\Model;
use Spatie\MediaLibrary\InteractsWithMedia;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Spatie\MediaLibrary\MediaCollections\Models\Media;

class ResourceUpdate extends Model implements HasMedia
{
use HasFactory;
use InteractsWithMedia;

protected $guarded = [];

public function resource()
{
return $this->belongsTo(Resource::class);
}

public function registerMediaCollections(Media $media = null): void
{
$this->addMediaCollection('resource_update_file')
->singleFile();
}
}
50 changes: 50 additions & 0 deletions app/View/Components/EasyMdeEditor.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

declare(strict_types=1);

namespace App\View\Components;

use Illuminate\View\Component;
use Illuminate\Contracts\View\View;

class EasyMdeEditor extends Component
{
/** @var string */
public $name;

/** @var string */
public $id;

/** @var array */
public $options;

protected static $assets = ['alpine', 'easy-mde'];

public function __construct(string $name, string $id = null, array $options = [])
{
$this->name = $name;
$this->id = $id ?? $name;
$this->options = $options;
}

public function options(): array
{
return array_merge([
'forceSync' => true,
], $this->options);
}

public function jsonOptions(): string
{
if (empty($this->options())) {
return '';
}

return ', ...' . json_encode((object) $this->options());
}

public function render(): View
{
return view('components.easy-mde-editor');
}
}
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
"spatie/laravel-activitylog": "^3.16",
"spatie/laravel-cookie-consent": "^2.12",
"spatie/laravel-health": "^1.3",
"spatie/laravel-medialibrary": "9.*",
"spatie/laravel-permission": "^4.2",
"spatie/laravel-tags": "^3.1",
"touhidurabir/laravel-multi-key-route-binding": "^1.0",
Expand Down
Loading