Added Download file, play for homebrews and ZIP explorer.

This commit is contained in:
2026-06-16 18:35:01 +02:00
parent 7e1e26f20b
commit 279160c1cb
12 changed files with 215 additions and 24 deletions

View File

@@ -77,9 +77,11 @@ class FileServerController extends Controller {
abort(404);
}
if( !EntryHelpers::fileAlreadyDownloaded($file) ) {
EntryHelpers::markFileAsDownloaded($file);
$file->increaseDownloadCount();
if($request->input('count_download', true)) {
if (!EntryHelpers::fileAlreadyDownloaded($file)) {
EntryHelpers::markFileAsDownloaded($file);
$file->increaseDownloadCount();
}
}
return redirect( $this->fs->getDownloadFileUrl( $file) );

View File

@@ -12,13 +12,12 @@ class ToolsController extends Controller
public function patcher()
{
return view('tools.patcher');
}
public function directPatch( Request $request, int $entryId, EntryFile $file )
{
if( $file->entry_id != $entryId ) {
if( $file->entry_id != $entryId || $file->state === 'private' ) {
abort(404);
}
@@ -38,22 +37,28 @@ class ToolsController extends Controller
public function play( Request $request, int $entryId, EntryFile $file )
{
if( $file->entry_id != $entryId ) {
if( $file->entry_id != $entryId || $file->state === 'private' ) {
abort(404);
}
$service = app(FileServersService::class);
$patches = [
'file' => $service->getDownloadFileUrl( $file ),
'name' => $file->entry->title,
'outputName' => $file->filename
];
$emuConfig = [
'core' => $file->playOnlineSetting?->core,
'threads' => $file->playOnlineSetting?->threads,
];
if( $file->entry->type === 'homebrew' ){
$filePath = $service->getDownloadFileUrl( $file );
return view('tools.play-homebrew', compact('filePath', 'emuConfig'));
}
$patches = [
'file' => $service->getDownloadFileUrl( $file ),
'name' => $file->entry->title,
'outputName' => $file->filename
];
return view('tools.play', compact('patches', 'emuConfig'));
}
}

View File

@@ -62,6 +62,23 @@ class EntryFile extends Model
return $this->hasOne(PlayOnlineSetting::class,'file_id');
}
public function prettyFileSize(): string
{
$bytes = $this->filesize;
if ($bytes >= 1073741824) {
$bytes = number_format($bytes / 1073741824, 2) . ' GB';
} elseif ($bytes >= 1048576) {
$bytes = number_format($bytes / 1048576, 2) . ' MB';
} elseif ($bytes >= 1024) {
$bytes = number_format($bytes / 1024, 2) . ' KB';
} else {
$bytes = ($bytes == 0) ? '0 bytes' : $bytes . ' bytes';
}
return $bytes;
}
public function increaseDownloadCount(): void
{
$this->download_count++;

View File

@@ -8,6 +8,8 @@ use Illuminate\Http\Client\ConnectionException;
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Str;
class FileServersService {
@@ -69,15 +71,38 @@ class FileServersService {
* @param EntryFile $file
* @return string
*/
public function getDownloadFileUrl( EntryFile $file ): string
public function getDownloadFileUrl( EntryFile $file, bool $countDownload = true ): string
{
$serverKey = $this->getEntryFileServerKey( $file );
$url = $this->servers[$serverKey]['download'] ?? "#";
if( $url === "#" )
return $url;
return $url . "&" . http_build_query( [ 'filename' => $file->filename, 'filepath' => $file->filepath ] );
$args = [ 'filename' => $file->filename, 'filepath' => $file->filepath ];
if( !$countDownload )
$args['count_download'] = false;
return $url . "&" . http_build_query( $args );
}
public function getArchiveExplorerUrl( EntryFile $file ): ?string
{
if( !Str::endsWith( $file->filename, ['zip', 'rar', '7z'] ) )
return null;
$serverKey = $this->getEntryFileServerKey( $file );
$url = $this->servers[$serverKey]['file_explorer'] ?? "#";
if( $url === "#" )
return null;
$args = [ 'filename' => $file->filename, 'filepath' => $file->filepath,
'zeus' => $this->generateZeusToken(\Auth::user()->user_id ?? 0, $this->servers[$serverKey]['base_url'], 'Fileexplorer')
];
return $url . "&" . http_build_query( $args );
}
/**
@@ -137,11 +162,13 @@ class FileServersService {
foreach( $this->servers as $serverKey => $server ){
$response = Http::withHeaders([])
$token = $this->generateZeusToken( $userId, $server['base_url'], "Deletefile" );
$response = Http::asForm()->withHeaders([])
->post( $server['delete_file'], [
'filepath' => $filePath,
'filename' => $fileName,
'zeus' => $this->generateZeusToken( $userId, $server['base_url'], "Deletefile" ),
'zeus' => $token,
]);
if (!$response->successful()) {

View File

@@ -63,8 +63,10 @@ class SubmissionsService {
if( $files === [] )
return [];
$service = app(FileServersService::class);
return array_map(
function( string $uuid ) {
function( string $uuid ) use ($service) {
$file = EntryFile::where('file_uuid', $uuid)->first();
if( $file )
@@ -78,6 +80,9 @@ class SubmissionsService {
'error' => null,
'uuid' => $uuid,
'state' => $file->state,
'file_explorer' => $service->getArchiveExplorerUrl($file),
'file_explorer_files' => null,
'download_url' => $service->getDownloadFileUrl($file, false),
'can_be_online_patched' => EntryHelpers::enableOnlinePatcherBasedOnExtension($file['filename']),
'meta_online_patcher' => $file->online_patcher,
'meta_secondary_online_patcher' => $file->secondary_online_patcher,
@@ -98,6 +103,9 @@ class SubmissionsService {
'error' => null,
'uuid' => $uuid,
'state' => $file['state'],
'file_explorer' => null,
'file_explorer_files' => null,
'download_url' => null,
'can_be_online_patched' => EntryHelpers::enableOnlinePatcherBasedOnExtension($file['filename']),
'meta_online_patcher' => false,
'meta_secondary_online_patcher' => false,
@@ -707,10 +715,10 @@ class SubmissionsService {
$needDeletion = array_diff( $existingUuids, $requestUuids );
if( !empty( $needDeletion ) ){
$userId = \Auth::user()->user_id;
EntryFile::where('entry_id', $entryId)->whereIn('file_uuid', $needDeletion)->get()->each( function ( $f ) use ( $userId ) {
EntryFile::where('entry_id', $entryId)->whereIn('file_uuid', $needDeletion)->whereNot('state', 'archived')->get()->each( function ( $f ) use ( $userId ) {
DeleteFile::dispatch( $f->filepath, $f->filename, $userId);
});
EntryFile::where('entry_id', $entryId)->whereIn('file_uuid', $needDeletion)->delete();
EntryFile::where('entry_id', $entryId)->whereIn('file_uuid', $needDeletion)->whereNot('state', 'archived')->delete();
}
$needAddition = array_diff( $requestUuids, $existingUuids );