Merge pull request #4966 from devansh-webkul/downloadable-link

Downloadable Links Moved To Private Disk #4962
This commit is contained in:
Glenn Hermans 2021-06-26 03:11:32 +02:00 committed by GitHub
commit 9544df3c12
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 28 additions and 9 deletions

View File

@ -48,6 +48,11 @@ return [
'root' => storage_path('app'),
],
'private' => [
'driver' => 'local',
'root' => storage_path('app/private'),
],
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),

View File

@ -3,22 +3,24 @@
namespace Webkul\Product\Repositories;
use Illuminate\Support\Facades\Storage;
use Webkul\Core\Eloquent\Repository;
use Illuminate\Support\Str;
use Webkul\Core\Eloquent\Repository;
class ProductDownloadableLinkRepository extends Repository
{
/**
* Specify Model class name
* Specify model class name.
*
* @return string
*/
function model()
public function model()
{
return 'Webkul\Product\Contracts\ProductDownloadableLink';
}
/**
* Upload.
*
* @param array $data
* @param integer $productId
* @return array
@ -28,7 +30,7 @@ class ProductDownloadableLinkRepository extends Repository
foreach ($data as $type => $file) {
if (request()->hasFile($type)) {
return [
$type => $path = request()->file($type)->store('product_downloadable_links/' . $productId),
$type => $path = request()->file($type)->store('product_downloadable_links/' . $productId, 'private'),
$type . '_name' => $file->getClientOriginalName(),
$type . '_url' => Storage::url($path),
];
@ -39,8 +41,10 @@ class ProductDownloadableLinkRepository extends Repository
}
/**
* Save links.
*
* @param array $data
* @param \Webkul\Product\Contracts\Product $product
* @param \Webkul\Product\Models\Product $product
* @return void
*/
public function saveLinks(array $data, $product)
@ -67,4 +71,4 @@ class ProductDownloadableLinkRepository extends Repository
$this->delete($linkId);
}
}
}
}

View File

@ -89,7 +89,11 @@ class DownloadableProductController extends Controller
}
if ($downloadableLinkPurchased->type == 'file') {
return Storage::download($downloadableLinkPurchased->file);
$privateDisk = Storage::disk('private');
return $privateDisk->exists($downloadableLinkPurchased->file)
? $privateDisk->download($downloadableLinkPurchased->file)
: abort(404);
} else {
$fileName = $name = substr($downloadableLinkPurchased->url, strrpos($downloadableLinkPurchased->url, '/') + 1);;

View File

@ -96,7 +96,11 @@ class ProductController extends Controller
$productDownloadableLink = $this->productDownloadableLinkRepository->findOrFail(request('id'));
if ($productDownloadableLink->sample_type == 'file') {
return Storage::download($productDownloadableLink->sample_file);
$privateDisk = Storage::disk('private');
return $privateDisk->exists($productDownloadableLink->sample_file)
? $privateDisk->download($productDownloadableLink->sample_file)
: abort(404);
} else {
$fileName = $name = substr($productDownloadableLink->sample_url, strrpos($productDownloadableLink->sample_url, '/') + 1);

View File

@ -1,3 +1,4 @@
*
!private/
!public/
!.gitignore

2
storage/app/private/.gitignore vendored Executable file
View File

@ -0,0 +1,2 @@
*
!.gitignore

View File

@ -1,3 +1,2 @@
*
!public/
!.gitignore