deleted old files

This commit is contained in:
Peter Papp
2021-07-28 18:33:13 +02:00
parent 71a1eb8e7c
commit 6a805b03fa
14 changed files with 9 additions and 361 deletions
@@ -83,15 +83,6 @@ class ShareController extends Controller
->where('user_id', Auth::id())
->firstOrFail()
->delete();
// Get zip record if exist
$zip = Zip::where('shared_token', $token)
->where('user_id', Auth::id())
->first();
if ($zip) {
$zip->delete();
}
}
return response('Done!', 204);
@@ -1,44 +0,0 @@
<?php
namespace Domain\Zip\Controllers;
use Domain\Zip\Models\Zip;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Storage;
use Domain\Traffic\Actions\RecordDownloadAction;
use Symfony\Component\HttpFoundation\StreamedResponse;
class GetZipController extends Controller
{
public function __construct(
private RecordDownloadAction $recordDownload,
) {
}
/**
* Get generated zip for user
*/
public function __invoke(
string $id,
): StreamedResponse {
$disk = Storage::disk('local');
$zip = Zip::whereId($id)
->where('user_id', Auth::id())
->firstOrFail();
// Store user download size
($this->recordDownload)(
file_size: $disk->size("zip/$zip->basename"),
user_id: $zip->user_id,
);
return $disk->download("zip/$zip->basename", $zip->basename, [
'Content-Type' => 'application/zip',
'Content-Length' => $disk->size("zip/$zip->basename"),
'Accept-Ranges' => 'bytes',
'Content-Range' => 'bytes 0-600/' . $disk->size("zip/$zip->basename"),
'Content-Disposition' => "attachment; filename=$zip->basename",
]);
}
}
@@ -1,44 +0,0 @@
<?php
namespace Domain\Zip\Controllers;
use Domain\Zip\Models\Zip;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Storage;
use Domain\Traffic\Actions\RecordDownloadAction;
use Symfony\Component\HttpFoundation\StreamedResponse;
class VisitorGetZipController extends Controller
{
public function __construct(
private RecordDownloadAction $recordDownload,
) {
}
/**
* Get generated zip for visitor
*/
public function __invoke(
$id,
$token,
): StreamedResponse {
$disk = Storage::disk('local');
$zip = Zip::where('id', $id)
->where('shared_token', $token)
->first();
// Store user download size
($this->recordDownload)(
file_size: $disk->size("zip/$zip->basename"),
user_id: $zip->user_id,
);
return $disk->download("zip/$zip->basename", $zip->basename, [
'Content-Type' => 'application/zip',
'Content-Length' => $disk->size("zip/$zip->basename"),
'Accept-Ranges' => 'bytes',
'Content-Range' => 'bytes 0-600/' . $disk->size("zip/$zip->basename"),
'Content-Disposition' => 'attachment; filename=' . $zip->basename,
]);
}
}
-48
View File
@@ -1,48 +0,0 @@
<?php
namespace Domain\Zip\Models;
use App\Users\Models\User;
use Illuminate\Support\Str;
use Database\Factories\ZipFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasOne;
use Illuminate\Database\Eloquent\Factories\HasFactory;
/**
* @property string basename
* @property string shared_token
* @property string id
* @property string user_id
* @property string created_at
* @property string updated_at
* @method static where(string $string, string $string1, string $toDateTimeString)
*/
class Zip extends Model
{
use HasFactory;
protected $guarded = ['id'];
public $incrementing = false;
protected $keyType = 'string';
protected static function newFactory(): ZipFactory
{
return ZipFactory::new();
}
public function user(): HasOne
{
return $this->hasOne(User::class, 'id', 'user_id');
}
protected static function boot()
{
parent::boot();
static::creating(function ($model) {
$model->id = (string) Str::uuid();
});
}
}