Skip to content

Commit 6e4dfed

Browse files
committed
Update StoreVideoRequest and upload endpoint to add missing can_duet and can_stitch params
1 parent fd51b24 commit 6e4dfed

3 files changed

Lines changed: 54 additions & 4 deletions

File tree

app/Http/Controllers/Api/VideoController.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@ public function store(StoreVideoRequest $request)
128128
$model->is_sensitive = $request->filled('is_sensitive') ? (bool) $request->boolean('is_sensitive') : false;
129129
$model->comment_state = $request->filled('comment_state') ? ($request->input('comment_state') == 4 ? 4 : 0) : 4;
130130
$model->can_download = $request->filled('can_download') ? $request->boolean('can_download') : false;
131+
$model->can_duet = $request->filled('can_duet') ? $request->boolean('can_duet') : false;
132+
$model->can_stitch = $request->filled('can_stitch') ? $request->boolean('can_stitch') : false;
131133
$model->alt_text = $request->filled('alt_text') ? app(SanitizeService::class)->cleanPlainText($request->alt_text) : null;
132134
$model->contains_ai = $request->filled('contains_ai') ? $request->boolean('contains_ai') : false;
133135
$model->contains_ad = $request->filled('contains_ad') ? $request->boolean('contains_ad') : false;

app/Http/Requests/StoreVideoRequest.php

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,60 @@ public function rules(): array
5353
],
5454
'description' => 'nullable|string|max:200',
5555
'comment_state' => 'sometimes|string|in:0,4',
56-
'can_download' => 'sometimes',
57-
'is_sensitive' => 'sometimes|boolean',
56+
'can_download' => 'nullable|boolean',
57+
'can_comment' => 'nullable|boolean',
58+
'can_duet' => 'nullable|boolean',
59+
'can_stitch' => 'nullable|boolean',
60+
'is_sensitive' => 'nullable|boolean',
5861
'alt_text' => 'nullable|sometimes|string|max:2000',
59-
'contains_ai' => 'sometimes|boolean',
60-
'contains_ad' => 'sometimes|boolean',
62+
'contains_ai' => 'nullable|boolean',
63+
'contains_ad' => 'nullable|boolean',
6164
'lang' => [
6265
'sometimes',
6366
'string',
6467
Rule::in(app(IntlService::class)->keys()),
6568
],
6669
];
6770
}
71+
72+
/**
73+
* Prepare the data for validation.
74+
*/
75+
protected function prepareForValidation(): void
76+
{
77+
$fields = ['can_download', 'can_comment', 'can_duet', 'can_stitch', 'is_sensitive', 'contains_ai', 'contains_ad'];
78+
foreach ($fields as $key) {
79+
if ($this->has($key)) {
80+
$this->merge([
81+
$key => $this->toBoolean($this->input($key)),
82+
]);
83+
}
84+
}
85+
}
86+
87+
/**
88+
* Converts a value to a boolean.
89+
* Handles 'true', 'false', 1, 0, '1', '0', true, false.
90+
*
91+
* @param mixed $value
92+
* @return bool|mixed
93+
*/
94+
private function toBoolean($value)
95+
{
96+
if (is_string($value)) {
97+
$value = strtolower($value);
98+
if (in_array($value, ['true', '1'])) {
99+
return true;
100+
}
101+
if (in_array($value, ['false', '0'])) {
102+
return false;
103+
}
104+
}
105+
106+
if (is_int($value) && in_array($value, [0, 1])) {
107+
return (bool) $value;
108+
}
109+
110+
return $value;
111+
}
68112
}

app/Models/Video.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,10 @@ protected function casts(): array
171171
'media_metadata' => 'array',
172172
'is_local' => 'boolean',
173173
'is_edited' => 'boolean',
174+
'can_duet' => 'boolean',
175+
'can_stitch' => 'boolean',
176+
'can_download' => 'boolean',
177+
'can_comment' => 'boolean',
174178
'contains_ai' => 'boolean',
175179
'contains_ad' => 'boolean',
176180
];

0 commit comments

Comments
 (0)