public async Task <Result> DeleteAsync([Required] string fileToken, [Required] string ownerToken) { if (!DecodeAndCheckFileToken(fileToken, out FileToken fToken, out DataResult <object> errResult)) { return(errResult); } if (!DecodeAndCheckOwnerToken(ownerToken, out OwnerToken oToken, out errResult)) { return(errResult); } var fOwner = await _fileData.GetFileOwnerByIdAsync(fToken.FileOwnerId, fToken.PseudoId); if (fOwner == null) { return(new Result(ResultErrorCodes.Failure, "记录不存在或已被删除")); } if (fOwner.OwnerId != oToken.OwnerId || fOwner.OwnerType != oToken.OwnerType) { return(new Result(ResultErrorCodes.Unauthorized, "您不是此文件的拥有者")); } var fileInfo = await _fileData.GetFileByIdAsync(fToken.PseudoId, fToken.FileId); var remainRefCount = await _fileData.DeleteFileAsync(fOwner.Id, fToken.FileId, fToken.PseudoId); if (remainRefCount < 1) { //引用计数为0,物理删除 var server = _clusterSvce.GetServerById(fileInfo.ServerId); await _clusterSvce.DeleteFileAsync(_storageSvce, fToken.PseudoId, fToken.FileCreateTime, fToken.FileId, server); } //删除已使用的配额 await _ownerData.DecreaseOwnerUsedQuotaAsync(oToken.OwnerType, oToken.OwnerId, fileInfo.Length); return(new Result(ResultErrorCodes.Success)); }