public async Task <IActionResult> GenerateLink(int id)
        {
            var cuser = await GetCurrentUserAsync();

            var fileinfo = await _ossApiService.ViewOneFileAsync(id);

            if (fileinfo.File == null)
            {
                return(NotFound());
            }
            var bucketInfo = await _ossApiService.ViewBucketDetailAsync(fileinfo.File.BucketId);

            var app = await _dbContext.Apps.FindAsync(bucketInfo.BelongingAppId);

            if (bucketInfo.BelongingAppId != app.AppId)
            {
                return(Unauthorized());
            }
            var secret = await _secretService.GenerateAsync(id, await _appsContainer.AccessToken(app.AppId, app.AppSecret));

            var model = new GenerateLinkViewModel(cuser)
            {
                Address  = secret.Value,
                BucketId = bucketInfo.BucketId
            };

            return(View(model));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> GenerateLink(int id) // file Id
        {
            var cuser = await GetCurrentUserAsync();

            var fileinfo = await _ossApiService.ViewOneFileAsync(id);

            if (fileinfo.File == null)
            {
                return(NotFound());
            }
            var bucketInfo = await _ossApiService.ViewBucketDetailAsync(fileinfo.File.BucketId);

            var model = new GenerateViewModel(cuser)
            {
                FileId   = fileinfo.File.FileKey,
                FileName = fileinfo.File.RealFileName,
                BucketId = bucketInfo.BucketId
            };

            return(View(model));
        }