feat(profile): increase profile photo upload limit to 5MB and verify webp storage

This commit is contained in:
sky121113 2026-05-17 13:09:39 +08:00
parent a77236bda8
commit 1b63ec6c56
6 changed files with 12 additions and 6 deletions

View File

@ -9,9 +9,11 @@ use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Redirect; use Illuminate\Support\Facades\Redirect;
use Illuminate\Support\Facades\Storage; use Illuminate\Support\Facades\Storage;
use Illuminate\View\View; use Illuminate\View\View;
use App\Traits\ImageHandler;
class ProfileController extends Controller class ProfileController extends Controller
{ {
use ImageHandler;
/** /**
* Display the user's profile form. * Display the user's profile form.
*/ */
@ -48,7 +50,7 @@ class ProfileController extends Controller
public function updateAvatar(Request $request): \Illuminate\Http\JsonResponse public function updateAvatar(Request $request): \Illuminate\Http\JsonResponse
{ {
$request->validate([ $request->validate([
'avatar' => ['required', 'image', 'mimes:jpeg,png,jpg,gif,webp', 'max:1024'], 'avatar' => ['required', 'image', 'mimes:jpeg,png,jpg,gif,webp', 'max:5120'],
]); ]);
$user = $request->user(); $user = $request->user();
@ -59,7 +61,8 @@ class ProfileController extends Controller
Storage::disk('public')->delete($user->avatar); Storage::disk('public')->delete($user->avatar);
} }
$path = $request->file('avatar')->store('avatars', 'public'); // 將上傳的大頭貼轉換為高壓縮率且清晰的 WebP 格式 (300x300 居中裁切)
$path = $this->storeAsWebp($request->file('avatar'), 'avatars', 85, 300, 300);
$user->avatar = $path; $user->avatar = $path;
$user->save(); $user->save();

View File

@ -19,7 +19,7 @@ class ProfileUpdateRequest extends FormRequest
'name' => ['required', 'string', 'max:255'], 'name' => ['required', 'string', 'max:255'],
'email' => ['required', 'string', 'lowercase', 'email', 'max:255', Rule::unique(User::class)->ignore($this->user()->id)], 'email' => ['required', 'string', 'lowercase', 'email', 'max:255', Rule::unique(User::class)->ignore($this->user()->id)],
'phone' => ['nullable', 'string', 'max:20'], 'phone' => ['nullable', 'string', 'max:20'],
'avatar' => ['nullable', 'image', 'mimes:jpeg,png,jpg,gif', 'max:2048'], 'avatar' => ['nullable', 'image', 'mimes:jpeg,png,jpg,gif,webp', 'max:5120'],
]; ];
} }
} }

View File

@ -1616,6 +1616,7 @@
"The Super Admin role is immutable.": "The Super Admin role is immutable.", "The Super Admin role is immutable.": "The Super Admin role is immutable.",
"The Super Admin role name cannot be modified.": "The Super Admin role name cannot be modified.", "The Super Admin role name cannot be modified.": "The Super Admin role name cannot be modified.",
"The image is too large. Please upload an image smaller than 1MB.": "The image is too large. Please upload an image smaller than 1MB.", "The image is too large. Please upload an image smaller than 1MB.": "The image is too large. Please upload an image smaller than 1MB.",
"The image is too large. Please upload an image smaller than 5MB.": "The image is too large. Please upload an image smaller than 5MB.",
"This is a system administrator role. Its name is locked to ensure system stability.": "This is a system administrator role. Its name is locked to ensure system stability.", "This is a system administrator role. Its name is locked to ensure system stability.": "This is a system administrator role. Its name is locked to ensure system stability.",
"This machine has a pending command. Please wait.": "This machine has a pending command. Please wait.", "This machine has a pending command. Please wait.": "This machine has a pending command. Please wait.",
"This role belongs to another company and cannot be assigned.": "This role belongs to another company and cannot be assigned.", "This role belongs to another company and cannot be assigned.": "This role belongs to another company and cannot be assigned.",

View File

@ -1616,6 +1616,7 @@
"The Super Admin role is immutable.": "特権管理者ロールは変更できません。", "The Super Admin role is immutable.": "特権管理者ロールは変更できません。",
"The Super Admin role name cannot be modified.": "特権管理者ロールの名前は変更できません。", "The Super Admin role name cannot be modified.": "特権管理者ロールの名前は変更できません。",
"The image is too large. Please upload an image smaller than 1MB.": "画像サイズが大きすぎます。1MB未満の画像をアップロードしてください。", "The image is too large. Please upload an image smaller than 1MB.": "画像サイズが大きすぎます。1MB未満の画像をアップロードしてください。",
"The image is too large. Please upload an image smaller than 5MB.": "画像サイズが大きすぎます。5MB未満の画像をアップロードしてください。",
"This is a system administrator role. Its name is locked to ensure system stability.": "これはシステム管理者ロールです。システムの安定性を確保するため、名前はロックされています。", "This is a system administrator role. Its name is locked to ensure system stability.": "これはシステム管理者ロールです。システムの安定性を確保するため、名前はロックされています。",
"This machine has a pending command. Please wait.": "この機器には実行中のコマンドがあります。しばらくお待ちください。", "This machine has a pending command. Please wait.": "この機器には実行中のコマンドがあります。しばらくお待ちください。",
"This role belongs to another company and cannot be assigned.": "このロールは別の会社に属しているため、割り当てることができません。", "This role belongs to another company and cannot be assigned.": "このロールは別の会社に属しているため、割り当てることができません。",

View File

@ -1638,6 +1638,7 @@
"The Super Admin role is immutable.": "超級管理員角色不可修改。", "The Super Admin role is immutable.": "超級管理員角色不可修改。",
"The Super Admin role name cannot be modified.": "超級管理員角色的名稱無法修改。", "The Super Admin role name cannot be modified.": "超級管理員角色的名稱無法修改。",
"The image is too large. Please upload an image smaller than 1MB.": "圖片檔案太大,請上傳小於 1MB 的圖片。", "The image is too large. Please upload an image smaller than 1MB.": "圖片檔案太大,請上傳小於 1MB 的圖片。",
"The image is too large. Please upload an image smaller than 5MB.": "圖片檔案太大,請上傳小於 5MB 的圖片。",
"This is a system administrator role. Its name is locked to ensure system stability.": "這是系統管理員角色,名稱已鎖定以確保系統穩定性。", "This is a system administrator role. Its name is locked to ensure system stability.": "這是系統管理員角色,名稱已鎖定以確保系統穩定性。",
"This machine has a pending command. Please wait.": "此機台已有指令正在執行,請稍後。", "This machine has a pending command. Please wait.": "此機台已有指令正在執行,請稍後。",
"This role belongs to another company and cannot be assigned.": "此角色屬於其他公司,無法指派。", "This role belongs to another company and cannot be assigned.": "此角色屬於其他公司,無法指派。",

View File

@ -8,9 +8,9 @@
const file = event.target.files[0]; const file = event.target.files[0];
if (!file) return; if (!file) return;
// Size Check (1MB = 1024 * 1024 bytes) // Size Check (5MB = 5 * 1024 * 1024 bytes)
if (file.size > 1024 * 1024) { if (file.size > 5 * 1024 * 1024) {
alert('{{ __('The image is too large. Please upload an image smaller than 1MB.') }}'); alert('{{ __('The image is too large. Please upload an image smaller than 5MB.') }}');
return; return;
} }