示例#1
0
        public override async Task RunAsync(IWwtContext context, CancellationToken token)
        {
            string query = context.Request.Params["Q"];

            string[] values = query.Split(',');
            int      level  = Convert.ToInt32(values[0]);
            int      tileX  = Convert.ToInt32(values[1]);
            int      tileY  = Convert.ToInt32(values[2]);

            if (level > 14)
            {
                await context.Response.WriteAsync("No image", token);

                context.Response.Close();
                return;
            }

            if (level < 9)
            {
                context.Response.ContentType = "image/png";

                using (Stream s = await _plateTiles.GetStreamAsync(_options.WwtTilesDir, "SDSS_8.plate", level, tileX, tileY, token))
                {
                    await s.CopyToAsync(context.Response.OutputStream, token);

                    context.Response.Flush();
                    context.Response.End();
                    return;
                }
            }

            using (var stream = await _octTileMap.GetOctTileAsync(level, tileX, tileY, enforceBoundary: true, token: token))
            {
                if (stream is null)
                {
                    await context.Response.WriteAsync("No image", token);
                }
                else
                {
                    await stream.CopyToAsync(context.Response.OutputStream, token);
                }
            }
        }
示例#2
0
        public override async Task RunAsync(IWwtContext context, CancellationToken token)
        {
            if (context.Request.UserAgent.ToLower().Contains("wget"))
            {
                await context.Response.WriteAsync("You are not allowed to bulk download imagery thru the tile service. Please contact [email protected] for more information.", token);

                context.Response.End();
                return;
            }

            string query = context.Request.Params["Q"];

            string[] values = query.Split(',');
            //++
            // 2014-09-26 security fix.
            //
            int level = 0;
            int tileX = 0;
            int tileY = 0;

            try
            {
                level = Convert.ToInt32(values[0]);
                tileX = Convert.ToInt32(values[1]);
                tileY = Convert.ToInt32(values[2]);
            }
            catch
            {
                await context.Response.WriteAsync("Invalid query string.", token);

                context.Response.End();
                return;
            }

            if (level > 14)
            {
                await context.Response.WriteAsync("No image", token);

                context.Response.End();
                return;
            }

            if (level < 8)
            {
                context.Response.ContentType = "image/png";

                using (Stream s = await _plateTiles.GetStreamAsync(_options.WwtTilesDir, "sdssdr12_7.plate", level, tileX, tileY, token))
                {
                    if (s.Length == 0)
                    {
                        context.Response.Clear();
                        context.Response.ContentType = "text/plain";
                        await context.Response.WriteAsync("No image", token);

                        context.Response.End();
                        return;
                    }

                    await s.CopyToAsync(context.Response.OutputStream, token);

                    context.Response.Flush();
                    context.Response.End();
                    return;
                }
            }

            context.Response.ContentType = "image/png";

            using (var stream = await _octTileMap.GetOctTileAsync(level, tileX, tileY, token: token))
            {
                await stream.CopyToAsync(context.Response.OutputStream, token);
            }
        }