fix(web): 积分商品保存 — 去掉 image_url 中的临时 token 参数
MediaPicker 返回含 ?token= 的 URL 用于预览认证,但保存到数据库时应只存纯路径, 避免 JWT token 持久化。同时改进错误提示显示后端返回的具体消息。
This commit is contained in:
@@ -128,10 +128,12 @@ export default function PointsProductList() {
|
||||
description?: string;
|
||||
sort_order?: number;
|
||||
};
|
||||
// 保存时去掉 URL 中的 ?token= 参数(token 是临时的,不应持久化)
|
||||
const cleanImageUrl = imageUrl ? imageUrl.replace(/\?token=.*$/, '') : undefined;
|
||||
if (editing) {
|
||||
await pointsApi.updateProduct(editing.id, {
|
||||
...typed,
|
||||
image_url: imageUrl || undefined,
|
||||
image_url: cleanImageUrl,
|
||||
version: editing.version,
|
||||
});
|
||||
} else {
|
||||
@@ -141,7 +143,7 @@ export default function PointsProductList() {
|
||||
points_cost: typed.points_cost,
|
||||
stock: typed.stock,
|
||||
description: typed.description,
|
||||
image_url: imageUrl || undefined,
|
||||
image_url: cleanImageUrl,
|
||||
sort_order: typed.sort_order,
|
||||
};
|
||||
await pointsApi.createProduct(req);
|
||||
@@ -149,8 +151,9 @@ export default function PointsProductList() {
|
||||
message.success(editing ? '更新成功' : '创建成功');
|
||||
handleCloseDrawer();
|
||||
refresh(page);
|
||||
} catch {
|
||||
message.error(editing ? '更新失败' : '创建失败');
|
||||
} catch (err: unknown) {
|
||||
const apiMsg = (err as { response?: { data?: { message?: string } } })?.response?.data?.message;
|
||||
message.error(apiMsg || (editing ? '更新失败' : '创建失败'));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user