Add a locked-down image upload endpoint for the admin panel
Posts, projects and about-me all carry an image column that could only ever be filled by typing a URL by hand, so every featured image in the database is still a placeholder. Uploads are the missing half of content management. Filenames are generated rather than reused from the client, which is what keeps a double extension or a path traversal out of a web-served directory. The upload surface is restricted to raster formats (no SVG, which can carry script) with a size and dimension ceiling, and throttled at 12/min against the general admin API's 30/min because an upload costs far more than a JSON write. Routes move to per-feature files registered from bootstrap/app.php, since api.php had become a chokepoint for parallel work on this repo.
This commit is contained in:
1 parent
6f6640330a
commit
6b03c0fbc3
6 files changed
+351
No files matched your search
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Admin;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class StoreMediaRequest extends FormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, array<int, mixed>>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
// `image` alone accepts SVG and any other raster format the server
|
||||
// can decode, including formats browsers cannot display safely.
|
||||
// Pinning the list keeps the upload surface small and predictable:
|
||||
// no SVG means no stored script, and no BMP/TIFF means nothing that
|
||||
// would need converting before a browser can show it.
|
||||
'file' => [
|
||||
'required',
|
||||
'file',
|
||||
'image',
|
||||
'mimes:jpg,jpeg,png,webp,gif',
|
||||
'max:4096',
|
||||
'dimensions:min_width=1,min_height=1,max_width=6000,max_height=6000',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function messages(): array
|
||||
{
|
||||
return [
|
||||
'file.required' => 'فایلی انتخاب نشده است.',
|
||||
'file.image' => 'فایل انتخابشده یک تصویر معتبر نیست.',
|
||||
'file.mimes' => 'فقط فرمتهای jpg، png، webp و gif پذیرفته میشود.',
|
||||
'file.max' => 'حجم تصویر نباید بیشتر از ۴ مگابایت باشد.',
|
||||
'file.dimensions' => 'ابعاد تصویر مجاز نیست.',
|
||||
];
|
||||
}
|
||||
|
||||
public function attributes(): array
|
||||
{
|
||||
return ['file' => 'تصویر'];
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user