public async Task <ActionResult <ApiSlideInfo> > SlideInfo([FromRoute] Course course, [FromRoute] Guid slideId) { var isInstructor = await courseRolesRepo.HasUserAccessToCourse(User.GetUserId(), course.Id, CourseRoleType.Instructor).ConfigureAwait(false); var slide = course?.FindSlideById(slideId, isInstructor); if (slide == null) { var instructorNote = course?.FindInstructorNoteById(slideId); if (instructorNote != null && isInstructor) { slide = instructorNote.Slide; } } if (slide == null) { return(NotFound(new { status = "error", message = "Course or slide not found" })); } var userId = User.GetUserId(); var getSlideMaxScoreFunc = await BuildGetSlideMaxScoreFunc(solutionsRepo, userQuizzesRepo, visitsRepo, groupsRepo, course, userId); var getGitEditLinkFunc = await BuildGetGitEditLinkFunc(userId, course, courseRolesRepo, coursesRepo); var baseUrl = CourseUnitUtils.GetDirectoryRelativeWebPath(slide.Info.SlideFile); var slideRenderContext = new SlideRenderContext(course.Id, slide, UserId, baseUrl, !isInstructor, course.Settings.VideoAnnotationsGoogleDoc, Url); return(await slideRenderer.BuildSlideInfo(slideRenderContext, getSlideMaxScoreFunc, getGitEditLinkFunc)); }
public static string RenderMarkdown(this string markdown, FileInfo sourceFile, string baseUrl = "") { var relativeUrl = CourseUnitUtils.GetDirectoryRelativeWebPath(sourceFile); baseUrl = baseUrl + relativeUrl; return(markdown.RenderMarkdown(baseUrl)); }
public void FixPaths(FileInfo slideFile) { if (string.IsNullOrEmpty(_image)) { return; } string relativeUrl; try { relativeUrl = CourseUnitUtils.GetDirectoryRelativeWebPath(slideFile); } catch (Exception e) { /* It's ok if courses web directory is not found, i.e. when we run this code on course tool * Just show error as warning to console and set relativeUrl to "" */ Console.WriteLine("Warning: " + e.Message); Console.WriteLine("It's ok if you are using course tool, not production ulearn web server."); relativeUrl = ""; } var imagePath = Path.Combine(relativeUrl, _image); var configuration = ApplicationConfiguration.Read <UlearnConfiguration>(); Image = configuration.BaseUrl + imagePath; }