fix: 兼容历史头像文件下载

This commit is contained in:
richjohnrambo
2026-09-09 13:24:36 +08:00
parent 92a72d1bea
commit c43c099c5e
2 changed files with 16 additions and 4 deletions
+7 -2
View File
@@ -5006,6 +5006,11 @@ func (a *adapter) FileGet(fid string) (*t.FileDef, error) {
var fd t.FileDef
err := a.db.GetContext(ctx, &fd, "SELECT id,createdat,updatedat,userid AS user,status,mimetype,size,IFNULL(etag,'') AS etag,location "+
"FROM im_fileuploads WHERE id=?", store.DecodeUid(id))
if err == sql.ErrNoRows {
storageName := id.String32()
err = a.db.GetContext(ctx, &fd, "SELECT id,createdat,updatedat,userid AS user,status,mimetype,size,IFNULL(etag,'') AS etag,location "+
"FROM im_fileuploads WHERE location=? OR location LIKE ? ORDER BY createdat DESC LIMIT 1", storageName, "%/"+storageName)
}
if err == sql.ErrNoRows {
return nil, nil
}
@@ -5183,7 +5188,7 @@ func (a *adapter) FileUserHasAccess(fid string, uid t.Uid) (bool, error) {
var allowed int
err := a.db.GetContext(ctx, &allowed, `
SELECT COUNT(*) FROM im_fileuploads AS fu
WHERE fu.id=? AND fu.status=? AND (
WHERE (fu.id=? OR fu.location=? OR fu.location LIKE ?) AND fu.status=? AND (
fu.userid=?
OR EXISTS (
SELECT 1 FROM im_filemsglinks AS fml
@@ -5247,7 +5252,7 @@ func (a *adapter) FileUserHasAccess(fid string, uid t.Uid) (bool, error) {
)
)
) LIMIT 1`,
store.DecodeUid(fileID), t.UploadCompleted, store.DecodeUid(uid), store.DecodeUid(uid), store.DecodeUid(uid), t.RelationshipFriend,
store.DecodeUid(fileID), fileID.String32(), "%/"+fileID.String32(), t.UploadCompleted, store.DecodeUid(uid), store.DecodeUid(uid), store.DecodeUid(uid), t.RelationshipFriend,
store.DecodeUid(uid), store.DecodeUid(uid), t.GroupMemberStatusActive, store.DecodeUid(uid), store.DecodeUid(uid),
store.DecodeUid(uid), fid, fid,
fid, t.MeetingStateCanceled, store.DecodeUid(uid), store.DecodeUid(uid), store.DecodeUid(uid))