[PROMOTE] 晉升 dev 到 demo (包含廣告上傳修復)
This commit is contained in:
commit
1d07a90e51
@ -76,6 +76,7 @@ class AdvertisementController extends AdminController
|
||||
'end_at' => 'nullable|date|after_or_equal:start_at',
|
||||
]);
|
||||
|
||||
try {
|
||||
$user = auth()->user();
|
||||
$file = $request->file('file');
|
||||
|
||||
@ -103,7 +104,6 @@ class AdvertisementController extends AdminController
|
||||
]);
|
||||
|
||||
if ($request->wantsJson()) {
|
||||
session()->flash('success', __('Advertisement created successfully.'));
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => __('Advertisement created successfully.'),
|
||||
@ -112,6 +112,23 @@ class AdvertisementController extends AdminController
|
||||
}
|
||||
|
||||
return redirect()->back()->with('success', __('Advertisement created successfully.'));
|
||||
|
||||
} catch (\Exception $e) {
|
||||
\Log::error('Advertisement Upload Error: ' . $e->getMessage(), [
|
||||
'user_id' => auth()->id(),
|
||||
'file_name' => $request->file('file')?->getClientOriginalName(),
|
||||
'trace' => $e->getTraceAsString()
|
||||
]);
|
||||
|
||||
if ($request->wantsJson()) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => __('Failed to process advertisement file: ') . $e->getMessage()
|
||||
], 500);
|
||||
}
|
||||
|
||||
return redirect()->back()->with('error', __('Failed to process advertisement file.'));
|
||||
}
|
||||
}
|
||||
|
||||
public function update(Request $request, Advertisement $advertisement)
|
||||
|
||||
@ -1139,8 +1139,28 @@ $baseRoute = 'admin.data-config.advertisements';
|
||||
});
|
||||
|
||||
xhr.addEventListener('load', () => {
|
||||
let result;
|
||||
try {
|
||||
const result = JSON.parse(xhr.responseText);
|
||||
result = JSON.parse(xhr.responseText);
|
||||
} catch (e) {
|
||||
console.error('Failed to parse response', e, xhr.responseText);
|
||||
let errorMsg = 'System Error';
|
||||
if (xhr.status === 413) {
|
||||
errorMsg = '{{ __("File is too large for the server configuration") }} (Nginx 413)';
|
||||
} else if (xhr.status >= 500) {
|
||||
errorMsg = '{{ __("Server Internal Error") }} (500)';
|
||||
}
|
||||
window.showToast?.(errorMsg, 'error');
|
||||
this.isSubmitting = false;
|
||||
this.uploadProgress = 0;
|
||||
if (bar) {
|
||||
bar.style.width = '0%';
|
||||
bar.style.opacity = '0';
|
||||
bar.classList.remove('loading');
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (xhr.status >= 200 && xhr.status < 300 && result.success) {
|
||||
// 進度跳到 100%
|
||||
if (bar) bar.style.width = '100%';
|
||||
@ -1160,17 +1180,6 @@ $baseRoute = 'admin.data-config.advertisements';
|
||||
bar.classList.remove('loading');
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('Failed to parse response', e);
|
||||
window.showToast?.('System Error', 'error');
|
||||
this.isSubmitting = false;
|
||||
this.uploadProgress = 0;
|
||||
if (bar) {
|
||||
bar.style.width = '0%';
|
||||
bar.style.opacity = '0';
|
||||
bar.classList.remove('loading');
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
xhr.addEventListener('error', () => {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user