Пример #1
0
        /// <summary>
        /// 云存储回调
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public async Task <UploadPictureOutput> UploadPictureCallBack(UploadPictureInput input)
        {
            if (!_storageProvider.VerifyCallback())
            {
                throw new UserFriendlyException("File.UploadPictureCallBack.InvalidRequest");
            }

            var picture = await _pictureManager.GetByKeyAsync(input.Key);

            if (picture == null)
            {
                var originalUrl = $"{GetBucketDomain(input.Bucket)}/{input.Key}";
                if (!input.ImageMogr2.IsNullOrEmpty())
                {
                    originalUrl = $"{originalUrl}?{input.ImageMogr2}";
                }

                picture = new Picture()
                {
                    Name          = input.Name,
                    Key           = input.Key,
                    GroupId       = input.GroupId,
                    OriginalUrl   = originalUrl,
                    CreationTime  = DateTime.UtcNow,
                    CreatorUserId = input.CreatorUserId,
                    TenantId      = input.TenantId,
                };

                if (input.CreatorUserId > 0)
                {
                    picture.CreatorUserId = input.CreatorUserId;
                }

                await _pictureManager.CreateAsync(picture);
            }
            else
            {
                picture.Name        = input.Name;
                picture.Key         = input.Key;
                picture.GroupId     = input.GroupId;
                picture.OriginalUrl = $"{GetBucketDomain(input.Bucket)}/{input.Key}";
            }

            await CurrentUnitOfWork.SaveChangesAsync();

            return(new UploadPictureOutput()
            {
                Id = picture.Id,
                Url = picture.OriginalUrl
            });
        }