-
Notifications
You must be signed in to change notification settings - Fork 143
fix: Fix custom avatar issue #2717
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry @pengfeixx, you have reached your weekly rate limit of 500000 diff characters.
Please try again later or upgrade to continue using Sourcery
99f06f0 to
8e5faba
Compare
|
TAG Bot New tag: 6.1.51 |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: caixr23, pengfeixx The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
Fix custom avatar issue Log: Fix custom avatar issue pms: BUG-298689
deepin pr auto review代码审查报告总体评价这次代码更新主要涉及账户系统中的头像功能改进,包括头像的存储、管理、裁剪和显示等方面。代码质量总体良好,但存在一些可以改进的地方。 具体问题与建议1. 代码逻辑问题问题: 建议:
2. 性能问题问题:在 建议: // 在文件操作前添加缓存检查
if (QFileInfo(targetFile).exists() && QFileInfo(tempAbs).size() == QFileInfo(targetFile).size()) {
return QUrl::fromLocalFile(targetFile).toString();
}问题: 建议: // 添加缓存机制
property var avatarCache: []
property var lastRefreshTime: 0
function shouldRefresh() {
return Date.now() - lastRefreshTime > 5000 // 5秒缓存
}
function refresh() {
if (!shouldRefresh()) return
lastRefreshTime = Date.now()
// ... 原有刷新逻辑
}3. 安全问题问题:文件路径处理存在潜在的安全风险。 建议: // 在 AccountsWorker::saveCustomAvatar() 中添加路径验证
bool isSafePath(const QString &path) {
QDir dir(path);
return dir.isAbsolutePath() &&
dir.absolutePath().startsWith(QStandardPaths::writableLocation(QStandardPaths::CacheLocation));
}
if (!isSafePath(targetFile)) {
qWarning() << "Unsafe file path detected:" << targetFile;
return QString();
}问题:在 建议: // 添加文件权限检查
function cropToTemp(callback) {
if (!control.iconSource || control.iconSource.length < 1) {
if (callback) callback("")
return
}
const tmp = StandardPaths.writableLocation(StandardPaths.TempLocation) + "/dcc_avatar_tmp.png"
imgGrabber.grabToImage(function (result) {
result.saveToFile(tmp)
// 设置适当的文件权限
Qt.callLater(function() {
const file = new File(tmp)
file.setPermissions(File.ReadOwner | File.WriteOwner)
if (callback) callback(tmp)
})
})
}4. 代码质量问题问题:一些函数过长,职责不够单一。 建议:
问题:部分代码存在重复。 建议: // 提取公共的路径处理函数
namespace AvatarPaths {
QString getAvatarsDir() {
const QString appCacheDir = QStandardPaths::writableLocation(QStandardPaths::CacheLocation);
return appCacheDir + QDir::separator() + "avatars";
}
QString getMarkerFile() {
return getAvatarsDir() + QDir::separator() + "current";
}
}5. 用户体验问题问题:头像裁剪组件的交互不够直观。 建议:
// 在 CustomAvatarCropper.qml 中添加
Button {
text: qsTr("Reset")
onClicked: {
img2.scale = 1.0
img2.updatePos()
}
anchors.bottom: parent.bottom
anchors.horizontalCenter: parent.horizontalCenter
}总结这次更新改进了头像功能的多个方面,但仍有一些可以优化的地方。建议重点关注性能优化、安全性增强和代码重构,同时改进用户体验。对于已经实现的缓存机制和文件管理功能,可以进一步扩展和完善。 |
|
/merge |
Fix custom avatar issue
Log: Fix custom avatar issue
pms: BUG-298689