示例#1
0
        public static void Render(FrontContext context)
        {
            var script = context.SiteDb.Scripts.Get(context.Route.objectId);

            context.RenderContext.Response.ContentType = "application/javascript;charset=utf-8";

            string result = Getbody(context, script);

            if (context.RenderContext.WebSite != null && context.RenderContext.WebSite.EnableJsCssCompress)
            {
                if (script != null)
                {
                    result = CompressCache.Get(script.Id, script.Version, result, CompressType.js);
                }
            }

            TextBodyRender.SetBody(context, result);

            VersionRenderer.ScriptStyleVersion(context);
        }
示例#2
0
        public static void Render(FrontContext context)
        {
            var css = context.SiteDb.Styles.Get(context.Route.objectId);

            context.RenderContext.Response.ContentType = "text/css;charset=utf-8";

            if (css != null && css.Body != null)
            {
                var body = GetBody(context.RenderContext, css);

                if (context.RenderContext.WebSite != null && context.RenderContext.WebSite.EnableJsCssCompress)
                {
                    if (css != null)
                    {
                        body = CompressCache.Get(css.Id, css.Version, body, CompressType.css);
                    }
                }
                TextBodyRender.SetBody(context, body);
                VersionRenderer.ScriptStyleVersion(context);
            }
        }
示例#3
0
        //file only contains column data.
        public static async Task RenderFile(FrontContext context, Models.CmsFile file)
        {
            var    sitedb      = context.WebSite.SiteDb();
            string contentType = null;

            if (!string.IsNullOrEmpty(file.ContentType))
            {
                contentType = file.ContentType;
            }
            else if (!string.IsNullOrWhiteSpace(file.Name))
            {
                contentType = IOHelper.MimeType(file.Name);
            }

            if (string.IsNullOrWhiteSpace(contentType))
            {
                if (context.Route != null)
                {
                    contentType = IOHelper.MimeType(context.Route.Name);
                }
            }

            context.RenderContext.Response.ContentType = contentType;

            if (file.Size > BigSize)
            {
                var partinfo = sitedb.Files.Store.GetFieldPart(file.Id, nameof(file.ContentBytes));

                context.RenderContext.Response.FilePart = partinfo;
            }
            else
            {
                // read whole content.
                CmsFile FileContent = null;
                if (file.ContentBytes == null)
                {
                    FileContent = await sitedb.FilePool.GetAsync(file.Id);
                }
                else
                {
                    FileContent = file;
                }


                if (FileContent.ContentBytes != null)
                {
                    context.RenderContext.Response.Body = FileContent.ContentBytes;
                }
                else if (!string.IsNullOrEmpty(FileContent.ContentString))
                {
                    context.RenderContext.Response.Body = DataConstants.DefaultEncoding.GetBytes(FileContent.ContentString);
                }
            }

            // cache for font.
            if (contentType != null)
            {
                string lower = contentType.ToLower();

                if (lower.Contains("font"))
                {
                    VersionRenderer.FontVersion(context);
                }
                else if (lower.Contains("image"))
                {
                    context.RenderContext.Response.Headers.Add("Access-Control-Allow-Origin", "*");
                    context.RenderContext.Response.Headers.Add("Access-Control-Allow-Headers", "*");

                    VersionRenderer.ImageVersion(context);
                }
                else if (lower.Contains("css"))
                {
                    VersionRenderer.ScriptStyleVersion(context);
                }
                else if (lower.Contains("javascript"))
                {
                    VersionRenderer.ScriptStyleVersion(context);
                }
                else if (lower.Contains("video"))
                {
                    VersionRenderer.VideoVersion(context);
                }
            }
        }