diff --git a/.gitea/workflows/deploy-staging.yml b/.gitea/workflows/deploy-staging.yml new file mode 100644 index 0000000..c56c2e7 --- /dev/null +++ b/.gitea/workflows/deploy-staging.yml @@ -0,0 +1,52 @@ +name: Deploy Laravel Staging + +on: + push: + branches: [staging] + +jobs: + deploy: + runs-on: self-hosted + + steps: + - name: Configure Git credentials + run: | + git config --global credential.helper store + echo "https://staging-runner:${{ env.GITEA_TOKEN }}@code.romhackplaza.org" \ + > /root/.git-credentials + + - name: Mark Git Folder as safe + run: git config --global --add safe.directory /deploy/laravel + + - name: Code pull + run: | + git -C /deploy/laravel fetch origin staging + git -C /deploy/laravel reset --hard origin/staging + + - name: Storage Link + run: | + docker exec staging_rhpz_web \ + php /sites/laravel/artisan storage:link --force + + - name: Composer Dependencies + run: | + docker exec staging_rhpz_web composer install \ + --no-dev \ + --optimize-autoloader \ + --working-dir=/sites/laravel + + - name: JS Dependencies + run: cd /deploy/laravel && npm ci + + - name: Build JS/CSS + run: cd /deploy/laravel && npm run build + + - name: Migrations + run: | + docker exec staging_rhpz_web \ + php /sites/laravel/artisan migrate --force + + - name: Opti Laravel + run: | + docker exec staging_rhpz_web \ + php /sites/laravel/artisan optimize diff --git a/app/Helpers/EntryHelpers.php b/app/Helpers/EntryHelpers.php index 0d50789..603673a 100644 --- a/app/Helpers/EntryHelpers.php +++ b/app/Helpers/EntryHelpers.php @@ -90,4 +90,9 @@ class EntryHelpers { }); } + + public static function enableOnlinePatcherBasedOnExtension(string $filename): bool + { + return Str::endsWith(Str::lower($filename), ['.ips', '.bps', '.xdelta', '.zip' ]); + } } diff --git a/app/Helpers/FormHelpers.php b/app/Helpers/FormHelpers.php index 9227063..b8aac16 100644 --- a/app/Helpers/FormHelpers.php +++ b/app/Helpers/FormHelpers.php @@ -41,6 +41,22 @@ class FormHelpers { 'release_site_helper' => "Project entry on site/blog/forum/Github.", 'youtube_video' => "YouTube video", ], + 'homebrew' => [ + 'page_title' => "Submit an homebrew", + 'about_the' => "About the homebrew", + 'version' => "Patch version", + 'status' => "Status", + 'release_date' => "Release date", + 'release_date_helper' => "If only initial release exist, the release date.", + 'description' => "Description", + 'about_game' => "Game Information", + 'attachments' => "Attachments", + 'authors' => "Team members", + 'related_links' => "Related links", + 'release_site' => "Release site", + 'release_site_helper' => "Project entry on site/blog/forum/Github.", + 'youtube_video' => "YouTube video", + ], ]; public static function getEntryFormWords( string $section ){ diff --git a/app/Http/Controllers/FileServerController.php b/app/Http/Controllers/FileServerController.php index f8c71f3..c1bea53 100644 --- a/app/Http/Controllers/FileServerController.php +++ b/app/Http/Controllers/FileServerController.php @@ -2,6 +2,7 @@ namespace App\Http\Controllers; +use App\Helpers\EntryHelpers; use App\Models\EntryFile; use App\Services\FileServersService; use Illuminate\Http\Client\ConnectionException; @@ -52,7 +53,7 @@ class FileServerController extends Controller { 'filesize' => $data['file']['size'], 'favorite_server' => $data['favorite_server'], 'favorite_at' => time(), - 'state' => 'public' + 'state' => 'public', ], now()->addHours(2) ); $data['finished'] = true; diff --git a/app/Http/Controllers/SubmissionController.php b/app/Http/Controllers/SubmissionController.php index a8ee83d..2f1f7f1 100644 --- a/app/Http/Controllers/SubmissionController.php +++ b/app/Http/Controllers/SubmissionController.php @@ -49,7 +49,7 @@ class SubmissionController extends Controller if( section_must_be( 'romhacks', $section ) ){ $data['modifications'] = Modification::orderBy('name')->get(); } - if( section_must_be( [ 'romhacks', 'translations' ], $section ) ){ + if( section_must_be( [ 'romhacks', 'translations', 'homebrew' ], $section ) ){ $data['statuses'] = Status::orderBy('id')->get(); } diff --git a/app/Http/Controllers/ToolsController.php b/app/Http/Controllers/ToolsController.php index 4502744..ef2180f 100644 --- a/app/Http/Controllers/ToolsController.php +++ b/app/Http/Controllers/ToolsController.php @@ -2,6 +2,8 @@ namespace App\Http\Controllers; +use App\Models\EntryFile; +use App\Services\FileServersService; use Illuminate\Http\Request; class ToolsController extends Controller @@ -10,11 +12,21 @@ class ToolsController extends Controller public function patcher() { + return view('tools.patcher'); + } + + public function directPatch( Request $request, int $entry_id, EntryFile $file ) + { + if( $file->entry_id != $entry_id ) { + abort(404); + } + + $service = app(FileServersService::class); + $patches = [ - 'file' => 'ZELDA.ips', - 'name' => "Meltin", - 'description' => 'Blablabla', - 'outputName' => 'Game...' + 'file' => $service->getDownloadFileUrl( $file ), + 'name' => $file->entry->title, + 'outputName' => $file->filename ]; return view('tools.patcher', compact('patches')); diff --git a/app/Http/Requests/StoreEntryRequest.php b/app/Http/Requests/StoreEntryRequest.php index 2652b6f..10b73ef 100644 --- a/app/Http/Requests/StoreEntryRequest.php +++ b/app/Http/Requests/StoreEntryRequest.php @@ -64,7 +64,7 @@ class StoreEntryRequest extends FormRequest $rules['files_state.*'] = 'string|in:public,private,archived'; } - if( section_must_not_be( 'translations', $section ) ){ + if( section_must_not_be( ['translations','homebrew'], $section ) ){ $rules['entry_title'] = "required|string|max:255"; } else { $rules['entry_title'] = "nullable|string|max:255"; @@ -124,6 +124,12 @@ class StoreEntryRequest extends FormRequest } } + if( $isEdit ){ + $rules['files_metadata'] = 'array|nullable'; + $rules['files_metadata.*.online_patcher'] = 'nullable|boolean'; + $rules['files_metadata.*.secondary_online_patcher'] = 'nullable|boolean|required_with:files_metadata.*.online_patcher'; + } + if( $isEdit && $this->user()->can('moderate', $this->route('entry') ) ){ $rules['staff_comment'] = 'nullable|string'; $rules['owner_user_id'] = [ 'required', 'integer', new XfUserExists ]; diff --git a/app/Services/SubmissionsService.php b/app/Services/SubmissionsService.php index 11ad10e..c397316 100644 --- a/app/Services/SubmissionsService.php +++ b/app/Services/SubmissionsService.php @@ -162,7 +162,7 @@ class SubmissionsService { $entry = Entry::create( $fields ); // STEP 7 : Save entry fields. - $this->Step7_SaveEntryFiles( $entry->id ); + $this->Step7_SaveEntryFiles( $entry ); // STEP 8 : Save hashes. $this->Step8_SaveHashes( $entry->id ); @@ -275,25 +275,35 @@ class SubmissionsService { * @return void * @throws SubmissionException */ - private function Step7_SaveEntryFiles( int $entryId, ?array $uuidData = null ): void + private function Step7_SaveEntryFiles( Entry $entry, ?array $uuidData = null ): void { if( !$uuidData ) $uuidData = $this->request->input('files_uuid', [] ); + $metadataArray = $this->request->input('files_metadata', []); + foreach ( $uuidData ?? [] as $uuid ) { $fileData = Cache::pull("uploaded_file_{$uuid}"); if( !$fileData ) throw new SubmissionException( "File {$uuid} has expired. Please delete all your files and retry. If it's an edition, delete all your new files and retry." ); + $onlinePatcher = (bool)($metadataArray[$uuid]['online_patcher'] ?? false); + if( !$onlinePatcher ) + $onlinePatcher = EntryHelpers::enableOnlinePatcherBasedOnExtension( $fileData['filename'] ); + + $secondaryOnlinePatcher = (bool)($metadataArray[$uuid]['secondary_online_patcher'] ?? false); + EntryFile::create([ - 'entry_id' => $entryId, + 'entry_id' => $entry->id, 'file_uuid' => $uuid, 'filename' => $fileData['filename'], 'filepath' => $fileData['filepath'], 'favorite_server' => $fileData['favorite_server'], 'favorite_at' => \DateTimeImmutable::createFromTimestamp( $fileData['favorite_at'] ), 'filesize' => $fileData['filesize'], - 'state' => 'public' + 'state' => 'public', + 'online_patcher' => $onlinePatcher, + 'secondary_online_patcher' => $secondaryOnlinePatcher, ]); } @@ -361,7 +371,6 @@ class SubmissionsService { */ private function Step10_SaveRomhacksModifications( Entry $entry ): void { - // TODO: Replace by edit version foreach ( $this->request->input('modifications', [] ) ?? [] as $modificationId ) { @@ -494,7 +503,7 @@ class SubmissionsService { 'user_id' => $user_id, 'complete_title' => $completeTitle, 'comments_thread_id' => $this->request->input('comments_thread_id'), - 'featured' => $this->request->input('featured'), + 'featured' => $this->request->input('featured') ?? false, ]; if( \Auth::user()->can('moderate', $this->entry) ){ @@ -600,12 +609,23 @@ class SubmissionsService { $needAddition = array_diff( $requestUuids, $existingUuids ); if( !empty( $needAddition ) ){ - $this->Step7_SaveEntryFiles( $this->entry->id, $needAddition ); // Same code. + $this->Step7_SaveEntryFiles( $this->entry, $needAddition ); // Same code. } + $metadataArray = $this->request->input('files_metadata', []); $stateMap = array_combine( $requestUuids, $requestStates ); + foreach( $stateMap as $uuid => $state ){ - EntryFile::where('file_uuid', $uuid)->where('entry_id', $entryId)->where('state', '!=', 'archived')->update(['state' => $state]); + + $onlinePatcher = (bool)($metadataArray[$uuid]['online_patcher'] ?? false); + $secondaryOnlinePatcher = (bool)($metadataArray[$uuid]['secondary_online_patcher'] ?? false); + + EntryFile::where('file_uuid', $uuid)->where('entry_id', $entryId)->where('state', '!=', 'archived') + ->update([ + 'state' => $state, + 'online_patcher' => $onlinePatcher, + 'secondary_online_patcher' => $secondaryOnlinePatcher, + ]); } } diff --git a/config/menu.php b/config/menu.php index 9941ab2..18f3fc1 100644 --- a/config/menu.php +++ b/config/menu.php @@ -27,7 +27,7 @@ return [ 'name' => "My Drafts", 'icon' => 'scissors', 'route' => 'entries.drafts', - 'condition' => (fn() => !\Auth::guest()) + 'auth' => true ] ] ], @@ -63,7 +63,7 @@ return [ [ 'name' => 'ROM Patcher', 'icon' => 'stamp', - 'route' => 'home' + 'route' => 'tools.patcher' ], [ 'name' => 'ROM Hasher', diff --git a/resources/views/components/menu.blade.php b/resources/views/components/menu.blade.php index c19add6..c7a1228 100644 --- a/resources/views/components/menu.blade.php +++ b/resources/views/components/menu.blade.php @@ -15,7 +15,7 @@
- Download + @empty No files found diff --git a/resources/views/submissions/form.blade.php b/resources/views/submissions/form.blade.php index 6293f7c..80b930b 100644 --- a/resources/views/submissions/form.blade.php +++ b/resources/views/submissions/form.blade.php @@ -29,7 +29,7 @@