このコミットが含まれているのは:
守矢諏訪子 2021-11-16 21:31:26 +09:00
コミット c78754f44f
1個のファイルの変更66行の追加7行の削除

ファイルの表示

@ -21,6 +21,45 @@ class MeetingsController extends Controller {
return ['status_code' => 400, 'error_messages' => ['ミーティングの登録に失敗しました。']];
}
// tmp
/////////////////////////
// ファイルサイズは10MiB以内
Validator::extend('image_size', function ($attribute, $value, $params, $validator) {
try {
$ok = true;
foreach ($value as $v) {
if (strlen(base64_decode($v)) > 1048576) {
$ok = false;
}
}
return $ok;
} catch (\Throwable $e) {
Log::critical($e->getMessage());
return false;
}
});
// ミームタイプ
Validator::extend('image_meme', function ($attribute, $value, $params, $validator) {
try {
$ok = true;
foreach ($value as $v) {
if (
mime_content_type($v) == 'image/jpeg' || // jpg
mime_content_type($v) == 'image/png' || // png
mime_content_type($v) == 'image/gif' // gif
) {
$ok = false;
}
}
return $ok;
} catch (\Throwable $e) {
Log::critical($e->getMessage());
return false;
}
});
/////////////////////////
// ミームタイプ
Validator::extend('pdf_meme', function ($attribute, $value, $params, $validator) {
try {
@ -35,7 +74,8 @@ class MeetingsController extends Controller {
'title' => 'required|max:100',
'text' => 'required|max:2000',
'memo' => 'max:2000',
'pdf' => 'pdf_meme'
'pdf' => 'pdf_meme',
'image' => 'image_size|image_meme', // tmp
]);
if ($validate->fails()) {
@ -59,6 +99,24 @@ class MeetingsController extends Controller {
}
$id = Meeting::create($insert);
// tmp
/////////////////////////
foreach ($r->image as $img) {
$ext = explode('/', mime_content_type($img))[1];
$filename = uniqid() . '.'.$ext;
$image = base64_decode(substr($img, strpos($img, ',') + 1));
Storage::disk('public')->put($filename, $image);
$insert_image = [
'meeting_id' => (int)$id,
'image' => '/storage/'.$filename,
];
MeetingImage::create($insert_image);
}
/////////////////////////
$params = ['meeting_id' => $id];
} catch (\Throwable $e) {
// 失敗
@ -580,12 +638,6 @@ class MeetingsController extends Controller {
return ['status_code' => 400, 'error_messages' => ['ミーティングの登録に失敗しました。']];
}
$validate = Validator::make($r->all(), [
'title' => 'required|max:100',
'text' => 'required|max:2000',
'memo' => 'nullable|max:2000',
]);
// ミームタイプ
Validator::extend('pdf_meme', function ($attribute, $value, $params, $validator) {
try {
@ -596,6 +648,13 @@ class MeetingsController extends Controller {
}
});
$validate = Validator::make($r->all(), [
'title' => 'required|max:100',
'text' => 'required|max:2000',
'memo' => 'nullable|max:2000',
'pdf' => 'pdf_meme',
]);
if ($validate->fails()) {
return ['status_code' => 422, 'error_messages' => $validate->errors()];
}