public async Task <MediaInfoStruct> NewMediaObject(
            string blogId,
            string userName,
            string password,
            MediaObjectStruct mediaObject)
        {
            var permission = await _security.ValidatePermissions(
                blogId,
                userName,
                password,
                CancellationToken.None
                ).ConfigureAwait(false);

            if (!permission.CanEditPosts)
            {
                _log.LogWarning($"user {userName} cannot edit posts");
                return(new MediaInfoStruct());
            }

            string extension = Path.GetExtension(mediaObject.name);
            string fileName  = Path.GetFileName(mediaObject.name).ToLowerInvariant().Replace("_thumb", "-wlw");
            var    project   = await _projectService.GetCurrentProjectSettings().ConfigureAwait(false);

            if (project == null)
            {
                _log.LogError("failed to resolve proejct settings");
                return(new MediaInfoStruct());
            }

            //https://github.com/cloudscribe/cloudscribe.SimpleContent/issues/345
            var currentTime        = DateTime.UtcNow;
            var storageVirtualPath = "/media/images/" + currentTime.Year.ToInvariantString()
                                     + "/" + currentTime.Month.ToString("00")
                                     + "/" + currentTime.Day.ToString("00")
                                     + "/"
            ;

            await _mediaProcessor.SaveMedia(storageVirtualPath, fileName, mediaObject.bytes).ConfigureAwait(false);

            var mediaUrl = await _mediaProcessor.ResolveMediaUrl(storageVirtualPath, fileName).ConfigureAwait(false);

            var result = new MediaInfoStruct()
            {
                url = mediaUrl
            };

            return(result);
        }
Exemple #2
0
        public async Task <MediaInfoStruct> NewMediaObject(
            string blogId,
            string userName,
            string password,
            MediaObjectStruct mediaObject)
        {
            var permission = await _security.ValidatePermissions(
                blogId,
                userName,
                password,
                CancellationToken.None
                ).ConfigureAwait(false);

            if (!permission.CanEditPosts)
            {
                _log.LogWarning($"user {userName} cannot edit posts");
                return(new MediaInfoStruct());
            }

            string extension = Path.GetExtension(mediaObject.name);
            string fileName  = Path.GetFileName(mediaObject.name).ToLowerInvariant().Replace("_thumb", "-wlw");
            var    project   = await _projectService.GetCurrentProjectSettings();

            if (project == null)
            {
                _log.LogError("failed to resolve proejct settings");
                return(new MediaInfoStruct());
            }

            await _blogService.SaveMedia(
                blogId,
                mediaObject.bytes,
                fileName
                ).ConfigureAwait(false);

            var mediaUrl = await _mediaProcessor.ResolveMediaUrl(project.LocalMediaVirtualPath, fileName);;
            var result   = new MediaInfoStruct()
            {
                url = mediaUrl
            };

            return(result);
        }
        /// <summary>
        /// this is only used for processing images added via metaweblog api
        /// </summary>
        /// <param name="fileName"></param>
        /// <returns></returns>
        public async Task <string> ResolveMediaUrl(string fileName)
        {
            await EnsureBlogSettings().ConfigureAwait(false);

            return(await mediaProcessor.ResolveMediaUrl(settings.LocalMediaVirtualPath, fileName).ConfigureAwait(false));
        }