Skip to content

Commit

Permalink
Merge pull request #268 from MineTrax/feature/downloads
Browse files Browse the repository at this point in the history
Feature/downloads
  • Loading branch information
Xinecraft authored Sep 22, 2023
2 parents 96a2c8d + a429d07 commit 20f89c7
Show file tree
Hide file tree
Showing 225 changed files with 2,871 additions and 1,160 deletions.
4 changes: 4 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ DB_PASSWORD=password
FILESYSTEM_DISK=local
MEDIA_DISK=media
PROFILE_PHOTO_DISK=public
DOWNLOADS_MODULE_DISK=download

BROADCAST_DRIVER=null
CACHE_DRIVER=redis
Expand Down Expand Up @@ -128,3 +129,6 @@ POWERED_BY_EXTRA_LINK=

PING_PROXY_SERVER_USING_IP_ADDRESS=false
QUERY_PROXY_SERVER_USING_IP_ADDRESS=true

MAX_USER_PROFILE_PHOTO_SIZE_KB=512
MAX_USER_COVER_PHOTO_SIZE_KB=1024
6 changes: 4 additions & 2 deletions app/Actions/Fortify/UpdateUserProfileInformation.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ class UpdateUserProfileInformation implements UpdatesUserProfileInformation
*/
public function update($user, array $input)
{
$maxProfilePhotoSize = config('auth.max_profile_photo_size_kb');
$maxCoverPhotoSize = config('auth.max_cover_photo_size_kb');
Validator::make($input, [
'name' => ['required', 'string', 'max:255'],
// 'email' => ['required', 'email', 'max:255', Rule::unique('users')->ignore($user->id)],
'photo' => ['nullable', 'image', 'max:512'],
'cover_image' => ['nullable', 'image', 'max:1024'],
'photo' => ['nullable', 'image', 'max:' . $maxProfilePhotoSize],
'cover_image' => ['nullable', 'image', 'max:' . $maxCoverPhotoSize],
'dob' => ['nullable', 'date', 'before:today'],
'gender' => ['nullable', 'in:m,f,o'],
'about' => ['nullable', 'string', 'max:255'],
Expand Down
138 changes: 138 additions & 0 deletions app/Http/Controllers/Admin/DownloadController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use App\Http\Requests\CreateDownloadRequest;
use App\Http\Requests\UpdateDownloadRequest;
use App\Models\Download;
use App\Queries\Filters\FilterMultipleFields;
use Inertia\Inertia;
use Spatie\QueryBuilder\AllowedFilter;
use Spatie\QueryBuilder\QueryBuilder;

class DownloadController extends Controller
{
public function index(): \Inertia\Response
{
$this->authorize('viewAny', Download::class);

$perPage = request()->input('perPage', 10);
if ($perPage > 100) {
$perPage = 100;
}

$fields = [
'id',
'name',
'slug',
'description',
'is_external',
'is_external_url_hidden',
'is_only_auth',
'is_active',
'file_name',
'file_url',
'min_role_weight_required',
'download_count',
'created_at',
'updated_at',
];

$downloads = QueryBuilder::for(Download::class)
->select($fields)
->with('media')
->allowedFilters([
...$fields,
AllowedFilter::custom('q', new FilterMultipleFields(['id', 'name', 'description', 'file_name'])),
])
->allowedSorts($fields)
->defaultSort('-id')
->paginate($perPage)
->through(function ($download) {
return $download->append('file')->makeHidden('media');
})
->withQueryString();

return Inertia::render('Admin/Download/IndexDownload', [
'downloads' => $downloads,
'filters' => request()->all(['perPage', 'sort', 'filter']),
]);
}

public function create(): \Inertia\Response
{
$this->authorize('create', Download::class);

return Inertia::render('Admin/Download/CreateDownload');
}

public function store(CreateDownloadRequest $request)
{
$isExternal = $request->is_external;
if ($isExternal) {
$fileUrl = $request->file_url;
}

$download = Download::create([
'name' => $request->name,
'slug' => \Str::slug($request->name),
'description' => $request->description,
'is_external' => $request->is_external,
'is_external_url_hidden' => $request->is_external_url_hidden,
'file_url' => $fileUrl ?? null,
'file_name' => $request->file_name ?? null,
'is_only_auth' => $request->is_only_auth,
'min_role_weight_required' => $request->min_role_weight_required,
'is_active' => $request->is_active,
'created_by' => $request->user()->id,
]);

// Upload the File if !isExternal
if (! $isExternal && $request->hasFile('file')) {
$download->addMediaFromRequest('file')->toMediaCollection('download');
}

return redirect()->route('admin.download.index')
->with(['toast' => ['type' => 'success', 'title' => __('Created Successfully'), 'body' => __('Download has been created successfully')]]);
}

public function edit(Download $download): \Inertia\Response
{
$this->authorize('update', Download::class);

return Inertia::render('Admin/Download/EditDownload', [
'download' => $download->append('file')->makeHidden('media'),
]);
}

public function update(UpdateDownloadRequest $request, Download $download)
{
$this->authorize('update', $download);

$download->update([
'name' => $request->name,
'slug' => \Str::slug($request->name),
'description' => $request->description,
'is_external_url_hidden' => $request->is_external_url_hidden,
'file_name' => $request->file_name ?? null,
'is_only_auth' => $request->is_only_auth,
'min_role_weight_required' => $request->min_role_weight_required,
'is_active' => $request->is_active,
'updated_by' => $request->user()->id,
]);

return redirect()->route('admin.download.index')
->with(['toast' => ['type' => 'success', 'title' => __('Updated Successfully'), 'body' => __('Download has been updated successfully')]]);
}

public function destroy(Download $download)
{
$this->authorize('delete', $download);

$download->delete();

return redirect()->route('admin.download.index')
->with(['toast' => ['type' => 'success', 'title' => __('Deleted Successfully'), 'body' => __('Download has been deleted permanently')]]);
}
}
Loading

0 comments on commit 20f89c7

Please sign in to comment.