コード例 #1
0
ファイル: FoldersService.cs プロジェクト: StasVitAlex/Video
        public async Task UpdateFolder(int userId, UpdateFolderVm model)
        {
            if (!await _foldersRepository.UserHasAccessToFolder(userId, model.Id))
            {
                throw new AccessDeniedException();
            }

            await _foldersRepository.UpdateFolder(userId, _mapper.Map <UpdateFolderDto>(model));
        }
コード例 #2
0
ファイル: VideoService.cs プロジェクト: StasVitAlex/Video
        public async Task <long> CreateVideo(long userId, CreateVideoVm model, string basePath)
        {
            if (!await _foldersRepository.UserHasAccessToFolder(model.UserId, model.FolderId))
            {
                throw new AccessDeniedException();
            }
            model.LinkCode = StringExtensions.GenerateUniqueRandomToken();
            model.LinkUrl  = $"{_commonSettings.ApplicationUrl}/api/video/stream/{model.LinkCode}";
            var videoId = await _videoRepository.CreateVideo(userId, _mapper.Map <CreateVideoDto>(model));

            var userVideoFolder = Path.Combine(basePath, _commonSettings.UserVideosFolder);

            if (!Directory.Exists(userVideoFolder))
            {
                Directory.CreateDirectory(userVideoFolder);
            }
            var videoFileDestinationPath = Path.Combine(userVideoFolder, $"{videoId}{model.Extension}");

            await using (var fileStream = new FileStream(videoFileDestinationPath, FileMode.Create))
            {
                await model.VideoFile.CopyToAsync(fileStream);
            }

            var videoImagesFolder = Path.Combine(basePath, _commonSettings.VideoImagesFolder);

            if (!Directory.Exists(videoImagesFolder))
            {
                Directory.CreateDirectory(videoImagesFolder);
            }
            var thumbnailDestinationPath = Path.Combine(videoImagesFolder, $"{videoId}.png");

            VideoHelpers.GenerateThumbNail(basePath, videoFileDestinationPath, thumbnailDestinationPath);
            var duration = VideoHelpers.GetVideoDuration(basePath, videoFileDestinationPath);
            await _videoRepository.UpdateVideoInfo(new UpdateVideoInfoDto { Duration = duration, ThumbnailUrl = $"{_commonSettings.ApplicationUrl}/api/video/thumbnail/{videoId}", Id = videoId, LocationUrl = videoFileDestinationPath });

            return(videoId);
        }