修改上传图片安全验证问题

This commit is contained in:
张成
2026-02-14 12:59:21 +08:00
parent 8688b6b82d
commit 64f0267457
54 changed files with 239 additions and 240 deletions

View File

@@ -342,7 +342,7 @@ export default forwardRef(function Comments(
try {
await messageService.markAsRead("comment", [message_id]);
} catch (e) {
console.error("标记评论已读失败:", e);
console.warn("标记评论已读失败:", e);
}
}

View File

@@ -134,7 +134,7 @@ const DistanceQuickFilterV2 = (props) => {
throw new Error('获取位置信息失败');
}
} catch (error: any) {
console.error('重新定位失败:', error);
console.warn('重新定位失败:', error);
(Taro as any).showToast({
title: error?.message || '定位失败,请检查定位权限',
icon: 'none',

View File

@@ -42,7 +42,7 @@ const FollowUserCard: React.FC<FollowUserCardProps> = ({ user, tabKey, onFollowC
onFollowChange?.(user.id, new_status);
} catch (error) {
console.error('关注操作失败:', error);
console.warn('关注操作失败:', error);
Taro.showToast({
title: '操作失败',
icon: 'none'
@@ -67,7 +67,7 @@ const FollowUserCard: React.FC<FollowUserCardProps> = ({ user, tabKey, onFollowC
onBlockSuccess?.(user.id);
}
} catch (error) {
console.error('删除推荐人员失败:', error);
console.warn('删除推荐人员失败:', error);
Taro.showToast({
title: '操作失败',
icon: 'none'

View File

@@ -146,7 +146,7 @@ const HomeNavbar = (props: IProps) => {
console.log(`[HomeNavbar] 距离上次选择"继续浏览"还不到2小时剩余时间: ${Math.ceil((TWO_HOURS_MS - time_diff) / 1000 / 60)}分钟`);
return false;
} catch (error) {
console.error('[HomeNavbar] 检查定位弹窗显示条件失败:', error);
console.warn('[HomeNavbar] 检查定位弹窗显示条件失败:', error);
return true; // 出错时默认显示
}
};
@@ -239,7 +239,7 @@ const HomeNavbar = (props: IProps) => {
// console.log(`距离上次选择"继续浏览"还不到2小时剩余时间: ${Math.ceil((TWO_HOURS_MS - time_diff) / 1000 / 60)}分钟`);
// return false;
// } catch (error) {
// console.error('检查定位弹窗显示条件失败:', error);
// console.warn('检查定位弹窗显示条件失败:', error);
// return true; // 出错时默认显示
// }
// };
@@ -276,7 +276,7 @@ const HomeNavbar = (props: IProps) => {
(Taro as any).setStorageSync(CITY_CHANGE_TIME_KEY, current_time);
console.log(`[LocationDialog] 已记录用户切换城市的时间2小时内不再提示`);
} catch (error) {
console.error('保存城市切换时间失败:', error);
console.warn('保存城市切换时间失败:', error);
}
console.log("切换到用户详情中的位置信息并更新缓存:", detectedProvince);
@@ -304,7 +304,7 @@ const HomeNavbar = (props: IProps) => {
(Taro as any).setStorageSync(LOCATION_DIALOG_DISMISS_TIME_KEY, current_time);
console.log(`[LocationDialog] 已记录用户选择"继续浏览"的时间2小时内不再提示`);
} catch (error) {
console.error('保存定位弹窗关闭时间失败:', error);
console.warn('保存定位弹窗关闭时间失败:', error);
}
// 关闭弹窗
@@ -409,7 +409,7 @@ const HomeNavbar = (props: IProps) => {
(Taro as any).setStorageSync(CITY_CHANGE_TIME_KEY, current_time);
console.log("已保存城市到缓存并记录切换时间:", _newArea, current_time);
} catch (error) {
console.error("保存城市缓存失败:", error);
console.warn("保存城市缓存失败:", error);
}
// 先调用列表接口(会使用更新后的 state.area

View File

@@ -43,7 +43,7 @@ const ImageUpload: React.FC<ImageUploadProps> = ({
onChange([...images, ...newImages])
},
fail: (err) => {
console.error('选择图片失败:', err)
console.warn('选择图片失败:', err)
}
})
}, [images.length, maxCount, onChange])

View File

@@ -256,7 +256,7 @@ const RadarChartV2 = forwardRef<RadarChartV2Ref, RadarChartV2Props>(
const bgImg = await loadImage(canvas, shareBgUrl);
ctx.drawImage(bgImg, 0, 0, width, height);
} catch (error) {
console.error("Failed to load background image:", error);
console.warn("Failed to load background image:", error);
// 如果加载失败,使用白色背景作为兜底
ctx.fillStyle = "#FFFFFF";
ctx.fillRect(0, 0, width, height);
@@ -392,12 +392,12 @@ const RadarChartV2 = forwardRef<RadarChartV2Ref, RadarChartV2Props>(
);
ctx.restore();
} catch (error) {
console.error("Failed to load docCopy image:", error);
console.warn("Failed to load docCopy image:", error);
}
currentY += (48 + 20) * scale; // 头像区域高度 + gap
} catch (error) {
console.error("Failed to load avatar image:", error);
console.warn("Failed to load avatar image:", error);
}
}
@@ -523,7 +523,7 @@ const RadarChartV2 = forwardRef<RadarChartV2Ref, RadarChartV2Props>(
iconSize,
);
} catch (error) {
console.error("Failed to load icon:", error);
console.warn("Failed to load icon:", error);
}
// 绘制底部文字
@@ -601,7 +601,7 @@ const RadarChartV2 = forwardRef<RadarChartV2Ref, RadarChartV2Props>(
// 恢复上下文状态
ctx.restore();
} catch (error) {
console.error("Failed to load QR code:", error);
console.warn("Failed to load QR code:", error);
}
}

View File

@@ -575,7 +575,7 @@ const ShareCardCanvas: React.FC<ShareCardCanvasProps> = ({
setTempImagePath(res.tempFilePath)
},
fail: (error: any) => {
console.error('图片生成失败:', error)
console.warn('图片生成失败:', error)
setIsDrawing(false)
reject(error)
}
@@ -595,7 +595,7 @@ const ShareCardCanvas: React.FC<ShareCardCanvasProps> = ({
console.log('Canvas绘制命令已发送')
} catch (error) {
console.error('绘制分享卡片失败:', error)
console.warn('绘制分享卡片失败:', error)
setIsDrawing(false) // 绘制失败,重置状态
Taro.showToast({
title: '生成分享卡片失败',

View File

@@ -16,7 +16,7 @@ const SubscribeNotificationTip: React.FC<SubscribeNotificationTipProps> = ({
navigateTo({
url: '/other_pages/enable_notification/index',
}).catch((err) => {
console.error('跳转失败:', err);
console.warn('跳转失败:', err);
});
};

View File

@@ -86,9 +86,9 @@ async function onChooseImageSuccess(tempFiles) {
...fileRes,
...(height > IMAGE_MAX_SIZE.height
? {
width: Math.floor(IMAGE_MAX_SIZE.height * image_aspect_ratio),
height: IMAGE_MAX_SIZE.height,
}
width: Math.floor(IMAGE_MAX_SIZE.height * image_aspect_ratio),
height: IMAGE_MAX_SIZE.height,
}
: { width: Math.floor(height * image_aspect_ratio), height }),
};
} else {
@@ -96,9 +96,9 @@ async function onChooseImageSuccess(tempFiles) {
...fileRes,
...(width > IMAGE_MAX_SIZE.width
? {
width: IMAGE_MAX_SIZE.width,
height: Math.floor(IMAGE_MAX_SIZE.width / image_aspect_ratio),
}
width: IMAGE_MAX_SIZE.width,
height: Math.floor(IMAGE_MAX_SIZE.width / image_aspect_ratio),
}
: { width, height: Math.floor(width / image_aspect_ratio) }),
};
}
@@ -119,7 +119,6 @@ export default function UploadFromWx(props: UploadFromWxProps) {
sourceType: ["album", "camera"],
}).then(async (res) => {
const analyzedFiles = await onChooseImageSuccess(res.tempFiles);
// cropping image to standard size
const compressedTempFiles = await compressImage(analyzedFiles);
let start = Date.now();
@@ -130,19 +129,22 @@ export default function UploadFromWx(props: UploadFromWxProps) {
is_public: 1 as unknown as 0 | 1,
id: (start++).toString(),
}));
const onFileUpdate = uploadApi.batchUpload(files).then((res) => {
return res.map((item) => ({
id: item.id,
url: item ? item.data.file_url : "",
}));
});
onAdd(
files.map((item) => ({
id: item.id,
url: item.filePath,
})),
onFileUpdate
);
Taro.showLoading({ title: "上传中..." });
try {
const uploadRes = await uploadApi.batchUpload(files);
const successful = uploadRes
.filter((item) => item.data != null)
.map((item) => ({
id: item.id,
url: (item.data as { file_url: string }).file_url,
}));
onAdd(successful, Promise.resolve(successful));
} catch (e) {
console.warn("批量上传失败:", e);
} finally {
Taro.hideLoading();
}
});
};
return (

View File

@@ -250,7 +250,7 @@ const UserInfoCardComponent: React.FC<UserInfoCardProps> = ({
icon: "success",
});
} catch (error) {
console.error("保存失败:", error);
console.warn("保存失败:", error);
Taro.showToast({
title: "保存失败",
icon: "error",
@@ -293,7 +293,7 @@ const UserInfoCardComponent: React.FC<UserInfoCardProps> = ({
icon: "success",
});
} catch (error) {
console.error("保存失败:", error);
console.warn("保存失败:", error);
Taro.showToast({
title: "保存失败",
icon: "error",