public async Task Create( string projectId, string userName, string password, IPost post, bool publish) { var permission = await security.ValidatePermissions( projectId, userName, password, CancellationToken ).ConfigureAwait(false); if (!permission.CanEditPosts) { return; } var settings = await projectService.GetProjectSettings(projectId).ConfigureAwait(false); await InitializeNewPosts(projectId, post, publish); var urlHelper = urlHelperFactory.GetUrlHelper(actionContextAccesor.ActionContext); var imageAbsoluteBaseUrl = urlHelper.Content("~" + settings.LocalMediaVirtualPath); if (context != null) { imageAbsoluteBaseUrl = context.Request.AppBaseUrl() + settings.LocalMediaVirtualPath; } // open live writer passes in posts with absolute urls // we want to change them to relative to keep the files portable // to a different root url post.Content = await htmlProcessor.ConvertMediaUrlsToRelative( settings.LocalMediaVirtualPath, imageAbsoluteBaseUrl, //this shold be resolved from virtual using urlhelper post.Content); // olw also adds hard coded style to images post.Content = htmlProcessor.RemoveImageStyleAttribute(post.Content); var nonPublishedDate = new DateTime(1, 1, 1); if (post.PubDate == nonPublishedDate) { post.PubDate = DateTime.UtcNow; } await postCommands.Create(settings.Id, post).ConfigureAwait(false); await eventHandlers.HandleCreated(settings.Id, post).ConfigureAwait(false); }
public async Task Create( string projectId, string userName, string password, IPage page, bool publish) { var permission = await security.ValidatePermissions( projectId, userName, password, CancellationToken ).ConfigureAwait(false); if (!permission.CanEditPosts) { return; } var settings = await projectService.GetProjectSettings(projectId).ConfigureAwait(false); if (publish) { page.PubDate = DateTime.UtcNow; } if (string.IsNullOrEmpty(page.Slug)) { var slug = ContentUtils.CreateSlug(page.Title); var available = await SlugIsAvailable(slug); if (available) { page.Slug = slug; } } var urlHelper = urlHelperFactory.GetUrlHelper(actionContextAccesor.ActionContext); var imageAbsoluteBaseUrl = urlHelper.Content("~" + settings.LocalMediaVirtualPath); if (context != null) { imageAbsoluteBaseUrl = context.Request.AppBaseUrl() + settings.LocalMediaVirtualPath; } // open live writer passes in posts with absolute urls // we want to change them to relative to keep the files portable // to a different root url page.Content = await htmlProcessor.ConvertMediaUrlsToRelative( settings.LocalMediaVirtualPath, imageAbsoluteBaseUrl, //this shold be resolved from virtual using urlhelper page.Content); // olw also adds hard coded style to images page.Content = htmlProcessor.RemoveImageStyleAttribute(page.Content); // here we need to process any base64 embedded images // save them under wwwroot // and update the src in the post with the new url // since this overload of Save is only called from metaweblog // and metaweblog does not base64 encode the images like the browser client // this call may not be needed here //await mediaProcessor.ConvertBase64EmbeddedImagesToFilesWithUrls( // settings.LocalMediaVirtualPath, // post // ).ConfigureAwait(false); var nonPublishedDate = new DateTime(1, 1, 1); if (page.PubDate == nonPublishedDate) { page.PubDate = DateTime.UtcNow; } await pageCommands.Create(projectId, page).ConfigureAwait(false); await eventHandlers.HandleCreated(projectId, page).ConfigureAwait(false); }