Skip to content

Commit

Permalink
Merge pull request #18 from mostafaznv/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
mostafaznv authored Oct 21, 2023
2 parents 9bd3ec9 + b0fdda0 commit 26cfa85
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest]
php: [8.1, 8.2]
php: [8.1, 8.2, 8.3]
laravel: [10.*]
coverage: [none]
dependency-version: [prefer-stable]
Expand Down
2 changes: 1 addition & 1 deletion src/Concerns/Storage/Attachment/AttachmentEvents.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function saved(Model $model): Model
$this->setMediaDetails();
$this->uploadOriginalFile($this->id);
$this->setCover($this->id);
$this->handleStyles($this->id, $model->getMorphClass());
$this->handleStyles($this->id, $model);
}

$model = $this->setAttributes($model);
Expand Down
16 changes: 13 additions & 3 deletions src/Concerns/Storage/Attachment/StyleAttachment.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Mostafaznv\Larupload\Concerns\Storage\Attachment;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Storage;
use Mostafaznv\Larupload\Enums\LaruploadFileType;
use Mostafaznv\Larupload\Larupload;
Expand All @@ -14,10 +15,10 @@ trait StyleAttachment
* resize, crop and generate styles from original file
*
* @param string $id
* @param string $class
* @param Model|string $class
* @param bool $standalone
*/
protected function handleStyles(string $id, string $class, bool $standalone = false): void
protected function handleStyles(string $id, Model|string $model, bool $standalone = false): void
{
switch ($this->type) {
case LaruploadFileType::IMAGE:
Expand All @@ -37,7 +38,16 @@ protected function handleStyles(string $id, string $class, bool $standalone = fa
$this->uploadOriginalFile($id, $this->localDisk);
}

$this->initializeFFMpegQueue($id, $class, $standalone);
if ($model instanceof Model) {
$this->initializeFFMpegQueue(
$model->id, $model->getMorphClass(), $standalone
);
}
else {
$this->initializeFFMpegQueue(
$id, $model, $standalone
);
}
}
else {
$this->handleVideoStyles($id);
Expand Down
69 changes: 69 additions & 0 deletions tests/Feature/FFMpegQueueTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Support\Facades\Event;
use Illuminate\Support\Facades\Bus;
use Mostafaznv\Larupload\Enums\LaruploadSecureIdsMethod;
use Mostafaznv\Larupload\Events\LaruploadFFMpegQueueFinished;
use Mostafaznv\Larupload\Jobs\ProcessFFMpeg;
use Illuminate\Http\Exceptions\HttpResponseException;
Expand Down Expand Up @@ -204,6 +205,74 @@
->toHaveCount(0);
});

it('can queue ffmpeg when using secure-ids', function() {
config()->set('larupload.secure-ids', LaruploadSecureIdsMethod::ULID);

$model = LaruploadTestModels::QUEUE->instance();
$model = save($model, mp4());

$urls = $model->attachment('main_file')->urls();

expect($urls->original)
->toBeExists()
->and($urls->cover)
->toBeExists()
->and($urls->landscape)
->toNotExists();

$queue = DB::table(Larupload::FFMPEG_QUEUE_TABLE)->first();
$process = new ProcessFFMpeg($queue->id, $model->id, 'main_file', $model::class);
$process->handle();

expect($urls->landscape)->toBeExists();
});

it('can queue ffmpeg when using secure-ids in standalone mode', function() {
config()->set('larupload.secure-ids', LaruploadSecureIdsMethod::ULID);

$name = 'uploader';
$standalone = Larupload::init($name)->video('landscape', 400);
$uploader = $standalone->upload(mp4());

expect($uploader->original)
->toBeExists()
->and($uploader->cover)
->toBeExists()
->and($uploader->landscape)
->toNotExists();

$queue = DB::table(Larupload::FFMPEG_QUEUE_TABLE)->first();
$serializedClass = base64_encode(serialize($standalone));
$process = new ProcessFFMpeg($queue->id, $uploader->meta->id, $name, Larupload::class, $serializedClass);
$process->handle();

expect($uploader->landscape)->toBeExists();







$model = LaruploadTestModels::QUEUE->instance();
$model = save($model, mp4());

$urls = $model->attachment('main_file')->urls();

expect($urls->original)
->toBeExists()
->and($urls->cover)
->toBeExists()
->and($urls->landscape)
->toNotExists();

$queue = DB::table(Larupload::FFMPEG_QUEUE_TABLE)->first();
$process = new ProcessFFMpeg($queue->id, $model->id, 'main_file', $model::class);
$process->handle();

expect($urls->landscape)->toBeExists();
});

it('will change queue status after processing queue', function() {
$model = LaruploadTestModels::QUEUE->instance();
$model = save($model, mp4());
Expand Down

0 comments on commit 26cfa85

Please sign in to comment.