Merge pull request #103 from nakazawakan/backend

親画面でプロフィール画像は不要+会議の画像アップロードは配列化
このコミットが含まれているのは:
chankan77 2021-11-25 12:57:27 +09:00 committed by GitHub
コミット e9ca73c6ce
この署名に対応する既知のキーがデータベースに存在しません
GPGキーID: 4AEE18F83AFDEB23
3個のファイルの変更54行の追加26行の削除

ファイルの表示

@ -123,6 +123,8 @@ class FathersController extends Controller {
}
public function registerMain (Request $r) {
if ($r->image == 'null') $r->image = null;
// 電話番号の文字数。
Validator::extend('tel_size', function ($attribute, $value, $params, $validator) {
return $this->telsize($value);
@ -161,11 +163,13 @@ class FathersController extends Controller {
$password = Hash::make($r->password);
$ext = explode('/', mime_content_type($r->image))[1];
$lastid = Father::select('id')->orderBy('id', 'desc')->first();
$filename = $this->uuidv4() . '.'.$ext;
$image = base64_decode(substr($r->image, strpos($r->image, ',') + 1));
Storage::disk('public')->put($filename, $image);
if (!is_null($r->image)) {
$ext = explode('/', mime_content_type($r->image))[1];
$lastid = Father::select('id')->orderBy('id', 'desc')->first();
$filename = $this->uuidv4() . '.'.$ext;
$image = base64_decode(substr($r->image, strpos($r->image, ',') + 1));
Storage::disk('public')->put($filename, $image);
}
try {
// DBの値の準備。
@ -175,7 +179,7 @@ class FathersController extends Controller {
'email' => $get->email,
'password' => $password,
'company' => $r->company,
'image' => '/storage/'.$filename,
'image' => !is_null($r->image) ? '/storage/'.$filename : '/assets/default/avatar.jpg',
'profile' => $r->profile,
'tel' => $r->tel,
];

ファイルの表示

@ -12,7 +12,7 @@ use App\Models\MeetingImage;
class MeetingImagesController extends Controller {
public function register (Request $r) {
if (!isset($r->meeting_id) || !isset($r->image)) {
if (!isset($r->meeting_id) || !isset($r->image) || empty(json_decode($r->image))) {
return ['status_code' => 400];
}
@ -22,12 +22,12 @@ class MeetingImagesController extends Controller {
// ファイルサイズは10MiB以内
Validator::extend('image_size', function ($attribute, $value, $params, $validator) {
return $this->imagesize($value);
return $this->imagesizemulti($value);
});
// ミームタイプ
Validator::extend('image_meme', function ($attribute, $value, $params, $validator) {
return $this->imagememe($value);
return $this->imagemememulti($value);
});
// バリデーションエラー
@ -37,19 +37,20 @@ class MeetingImagesController extends Controller {
return ['status_code' => 422, 'error_messages' => $validate->errors()];
}
$ext = explode('/', mime_content_type($r->image))[1];
$filename = $this->uuidv4() . '.'.$ext;
try {
$image = base64_decode(substr($r->image, strpos($r->image, ',') + 1));
Storage::disk('public')->put($filename, $image);
foreach (json_decode($r->image) as $img) {
$ext = explode('/', mime_content_type($img))[1];
$filename = $this->uuidv4() . '.'.$ext;
$image = base64_decode(substr($img, strpos($img, ',') + 1));
Storage::disk('public')->put($filename, $image);
$insert = [
'meeting_id' => (int)$r->meeting_id,
'image' => '/storage/'.$filename,
];
$insert = [
'meeting_id' => (int)$r->meeting_id,
'image' => '/storage/'.$filename,
];
MeetingImage::create($insert);
MeetingImage::create($insert);
}
} catch (\Throwable $e) {
// 失敗
Log::critical($e->getMessage());
@ -67,17 +68,19 @@ class MeetingImagesController extends Controller {
}
public function delete ($meeting_id, Request $r) {
if (!isset($meeting_id) || !isset($r->image_id)) {
return ['status_code' => 400];
}
if (null === ($get = MeetingImage::select('image')->where('id', (int)$r->image_id)->first())) {
if (!isset($meeting_id) || !isset($r->image_id) || empty(json_decode($r->image_id))) {
return ['status_code' => 400];
}
try {
MeetingImage::where('id', (int)$r->image_id)->delete();
Storage::disk('public')->delete($get->image);
foreach (json_decode($r->image_id) as $img) {
if (null === ($get = MeetingImage::select('image')->where('id', (int)$img)->first())) {
return ['status_code' => 400];
}
MeetingImage::where('id', (int)$img)->delete();
Storage::disk('public')->delete($get->image);
}
} catch (\Throwable $e) {
// 失敗
Log::critical($e->getMessage());

ファイルの表示

@ -50,6 +50,7 @@ class Controller extends BaseController
}
public function imagesizecannull ($value) {
if ($value == 'null') $value = null;
if (is_null($value)) return true;
return $this->imagesize($value);
}
@ -68,6 +69,7 @@ class Controller extends BaseController
}
public function imagememecannull ($value) {
if ($value == 'null') $value = null;
if (is_null($value)) return true;
return $this->imagememe($value);
}
@ -98,6 +100,25 @@ class Controller extends BaseController
}
}
public function imagemememulti ($value) {
try {
$ok = true;
foreach (json_decode($value) as $v) {
if (
mime_content_type($value) != 'image/jpeg' && // jpg
mime_content_type($value) != 'image/png' && // png
mime_content_type($value) != 'image/gif' // gif
) {
$ok = false;
}
}
return $ok;
} catch (\Throwable $e) {
Log::critical($e->getMessage());
return false;
}
}
public function imagesizemulti ($value) {
try {
$ok = true;