Repository navigation
feat: add short videos to ordinary commits #1000
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
christophrumpel
wants to merge
2
commits into
dev-null-sh:production
Choose a base branch
from
christophrumpel:feat/native-video
base: production
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace App\Actions; | ||
|
|
||
| use App\Models\CommitVideo; | ||
| use App\Models\User; | ||
| use Illuminate\Support\Arr; | ||
| use Illuminate\Support\Facades\Storage; | ||
| use Illuminate\Support\Fluent; | ||
|
|
||
| final readonly class CreateCommitVideo | ||
| { | ||
| /** @return array{video: CommitVideo, upload: array{url: string, method: string, headers: array<mixed>}} */ | ||
| public function handle(User $user, int $size): array | ||
| { | ||
| $video = CommitVideo::query()->create(['user_id' => $user->id, 'size' => $size]); | ||
| $upload = config('filesystems.disks.'.config()->string('filesystems.default').'.driver') === 'local' | ||
| ? ['url' => route('commit-video-upload.update', $video), 'headers' => ['Content-Type' => 'application/octet-stream']] | ||
| : Storage::temporaryUploadUrl($video->path('source'), now()->addMinutes(15), ['ContentType' => 'application/octet-stream', 'ContentLength' => $size]); | ||
|
|
||
| $upload = new Fluent($upload); | ||
|
|
||
| return ['video' => $video->refresh(), 'upload' => ['url' => $upload->string('url')->value(), 'method' => 'PUT', 'headers' => Arr::except($upload->array('headers'), ['Host', 'Content-Length'])]]; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace App\Actions; | ||
|
|
||
| use App\Models\CommitVideo; | ||
| use Illuminate\Support\Facades\DB; | ||
|
|
||
| final readonly class DeleteCommitVideo | ||
| { | ||
| public function __construct(private DeleteStoredFiles $deleteFiles) | ||
| { | ||
| // | ||
| } | ||
|
|
||
| public function handle(CommitVideo $video): void | ||
| { | ||
| DB::transaction(function () use ($video): void { | ||
| $video = CommitVideo::query()->whereNull('commit_id')->lockForUpdate()->find($video->id); | ||
|
|
||
| if ($video !== null) { | ||
| $this->deleteFiles->retain($video->paths()); | ||
| $video->delete(); | ||
| } | ||
| }); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace App\Actions; | ||
|
|
||
| use App\Enums\CommitVideoStatus; | ||
| use App\Jobs\ProcessCommitVideo; | ||
| use App\Models\CommitVideo; | ||
| use Illuminate\Support\Facades\DB; | ||
|
|
||
| final readonly class UpdateCommitVideoProcessing | ||
| { | ||
| public function handle(CommitVideo $video): CommitVideo | ||
| { | ||
| return DB::transaction(function () use ($video): CommitVideo { | ||
| $video = CommitVideo::query()->lockForUpdate()->findOrFail($video->id); | ||
|
|
||
| if ($video->status === CommitVideoStatus::Uploading) { | ||
| $video->update(['status' => CommitVideoStatus::Processing]); | ||
| dispatch(new ProcessCommitVideo($video->id))->afterCommit(); | ||
| } | ||
|
|
||
| return $video; | ||
| }); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace App\Actions; | ||
|
|
||
| use App\Models\CommitVideo; | ||
| use Illuminate\Support\Facades\Storage; | ||
|
|
||
| final readonly class UpdateCommitVideoUpload | ||
| { | ||
| /** @param resource $contents */ | ||
| public function handle(CommitVideo $video, mixed $contents): void | ||
| { | ||
| Storage::put($video->path('source'), $contents); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace App\Enums; | ||
|
|
||
| enum CommitVideoStatus: string | ||
| { | ||
| case Uploading = 'uploading'; | ||
| case Processing = 'processing'; | ||
| case Ready = 'ready'; | ||
| case Failed = 'failed'; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace App\Http\Controllers; | ||
|
|
||
| use App\Actions\CreateCommitVideo; | ||
| use App\Actions\DeleteCommitVideo; | ||
| use App\Http\Requests\CreateCommitVideoRequest; | ||
| use App\Http\Requests\DeleteCommitVideoRequest; | ||
| use App\Http\Requests\ShowCommitVideoRequest; | ||
| use App\Models\CommitVideo; | ||
| use App\Models\User; | ||
| use Illuminate\Container\Attributes\CurrentUser; | ||
| use Illuminate\Http\JsonResponse; | ||
| use Illuminate\Http\Response; | ||
|
|
||
| final readonly class CommitVideoController | ||
| { | ||
| public function store(CreateCommitVideoRequest $request, #[CurrentUser] User $user, CreateCommitVideo $action): JsonResponse | ||
| { | ||
| return response()->json($action->handle($user, $request->integer('size')), 201); | ||
| } | ||
|
|
||
| public function show(ShowCommitVideoRequest $request, CommitVideo $commitVideo): JsonResponse | ||
| { | ||
| return response()->json(['video' => $commitVideo])->header('Cache-Control', 'private, no-store'); | ||
| } | ||
|
|
||
| public function destroy(DeleteCommitVideoRequest $request, CommitVideo $commitVideo, DeleteCommitVideo $action): Response | ||
| { | ||
| $action->handle($commitVideo); | ||
|
|
||
| return response()->noContent(); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check the
Storage::putresult before returning success.UpdateCommitVideoUpload::handlediscards the boolean thatStorage::putreturns. Every configured disk setsthrowtofalse, so a failed write returnsfalseand does not raise an exception.CommitVideoUploadController::updatethen returns204 No Contentwithout checking. The client receives a success response for an upload that was not stored.Return a failure response when the write fails. Change
handleto return the write result, and have the controller reject afalseresult before it returns success.Suggested fix
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Leaving this one as is. This route only handles uploads when the app runs on the local disk, which is just local development. With S3 the browser uploads straight to the bucket through a signed URL and never hits this endpoint.
A failed write here can't produce a ready video either: the next step,
CreateCommitVideoProcessingRequest, checks that the source file exists and returns 422 "The upload is incomplete. Please choose the video again."