From c43c099c5e8f6dbd660ae38df3b4ede73cee53a0 Mon Sep 17 00:00:00 2001 From: richjohnrambo Date: Wed, 9 Sep 2026 13:20:57 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=85=BC=E5=AE=B9=E5=8E=86=E5=8F=B2?= =?UTF-8?q?=E5=A4=B4=E5=83=8F=E6=96=87=E4=BB=B6=E4=B8=8B=E8=BD=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/db/mysql/adapter.go | 9 +++++++-- server/db/mysql/tenant_adapter.go | 11 +++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/server/db/mysql/adapter.go b/server/db/mysql/adapter.go index b055a57..ed1da2f 100644 --- a/server/db/mysql/adapter.go +++ b/server/db/mysql/adapter.go @@ -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)) diff --git a/server/db/mysql/tenant_adapter.go b/server/db/mysql/tenant_adapter.go index 4a729ae..dee0c27 100644 --- a/server/db/mysql/tenant_adapter.go +++ b/server/db/mysql/tenant_adapter.go @@ -7690,6 +7690,13 @@ func (a *adapter) TenantFileGet(id t.TenantID, fid string) (*t.FileDef, error) { err = a.db.GetContext(ctx, &fd, "SELECT tenant_id,id,createdat,updatedat,userid AS user,status,mimetype,size,IFNULL(etag,'') AS etag,location "+ "FROM im_fileuploads WHERE tenant_id=? AND id=?", id, decodeUID(fileID)) + if err == sql.ErrNoRows { + storageName := fileID.String32() + err = a.db.GetContext(ctx, &fd, + "SELECT tenant_id,id,createdat,updatedat,userid AS user,status,mimetype,size,IFNULL(etag,'') AS etag,location "+ + "FROM im_fileuploads WHERE tenant_id=? AND (location=? OR location LIKE ?) ORDER BY createdat DESC LIMIT 1", + id, storageName, "%/"+storageName) + } if err == sql.ErrNoRows { return nil, nil } @@ -7849,7 +7856,7 @@ func (a *adapter) TenantFileUserHasAccess(id t.TenantID, fid string, uid t.Uid) var allowed int err = a.db.GetContext(ctx, &allowed, ` SELECT COUNT(*) FROM im_fileuploads AS fu - WHERE fu.tenant_id=? AND fu.id=? AND fu.status=? AND ( + WHERE fu.tenant_id=? AND (fu.id=? OR fu.location=? OR fu.location LIKE ?) AND fu.status=? AND ( fu.userid=? OR EXISTS ( SELECT 1 FROM im_filemsglinks AS fml @@ -7897,7 +7904,7 @@ func (a *adapter) TenantFileUserHasAccess(id t.TenantID, fid string, uid t.Uid) AND s.deletedat IS NULL AND INSTR(s.modewant,'R')>0 AND INSTR(s.modegiven,'R')>0 ) ) LIMIT 1`, - id, decodeUID(fileID), t.UploadCompleted, decodeUID(uid), decodeUID(uid), decodeUID(uid), t.RelationshipFriend, + id, decodeUID(fileID), fileID.String32(), "%/"+fileID.String32(), t.UploadCompleted, decodeUID(uid), decodeUID(uid), decodeUID(uid), t.RelationshipFriend, decodeUID(uid), decodeUID(uid), t.GroupMemberStatusActive, decodeUID(uid), decodeUID(uid), decodeUID(uid), fid, fid) if err != nil {