Beispiel #1
0
func (tr *TemplatesResource) ConvertRaw(c *gin.Context) {
	var (
		err error
		job conv.Job
		res conv.Result
		buf = []byte{}
	)

	if buf, err = ioutil.ReadAll(c.Request.Body); err != nil {
		log.Printf("Error while reading body: %s", err)
		c.JSON(500, ErrInternal)
		return
	}

	job = createRawJob(string(buf))
	tr.jobsChan <- job
	res = <-job.ResultChan

	if res.Error == nil {
		c.File(res.ResultPath)
	} else {
		log.Printf("Error while converting: %s", res.Error)
		c.JSON(500, ErrInternal)
	}
}
Beispiel #2
0
func doGETFile(c *gin.Context) {

	ID := normalize(c.Param("id"))
	ws := normalize(c.Param("ws"))
	name := normalize(c.Param("name"))

	file := instance.Srv.Store.Entry.FilePath(ws, ID, name)
	c.File(file)
}
func certHandler(c *gin.Context) {
	if strings.Contains(c.Request.UserAgent(), "Firefox") {
		c.Header("content-type", "application/x-x509-ca-cert")
		c.File("ca.cert.cer")
		return
	}
	noFirefoxTemplate.Execute(c.Writer, gin.H{
		"url": "http://" + c.Request.Host + c.Request.URL.String(),
	})
}
Beispiel #4
0
func handleResize(c *gin.Context) {
	size, err := strconv.ParseInt(c.Query("size"), 10, 0)

	resp, err := http.Get(c.Query("img"))
	if err != nil {
		panic(err)
	}

	imgName := createImageFromResponse(resp)
	resizedImg := resizeImage(imgName, int(size))
	c.File(resizedImg)
}
Beispiel #5
0
func (tr *TemplatesResource) Convert(c *gin.Context) {
	var (
		id   = GetIdParam(c)
		res  conv.Result
		job  conv.Job
		tmpl models.Template
		buf  []byte
		data map[string]interface{}
		err  error
	)

	if tr.db.First(&tmpl, id).RecordNotFound() {
		c.JSON(404, ErrNotFound)
	} else {
		if buf, err = ioutil.ReadAll(c.Request.Body); err != nil {
			log.Printf("Error while reading body: %s", err)
			c.JSON(500, ErrInternal)
			return
		}

		// Only try to parse json if the body has actual content
		if len(buf) > 0 {
			if err := json.Unmarshal(buf, &data); err != nil {
				c.JSON(400, ErrInvalidJson)
				return
			}
		}

		job = conv.Job{
			Template:   tmpl,
			Data:       data,
			ResultChan: make(conv.ResultChan),
		}

		tr.jobsChan <- job
		res = <-job.ResultChan

		if res.Error == nil {
			c.File(res.ResultPath)
		} else {
			log.Printf("Error while converting: %s", res.Error)
			c.JSON(500, ErrInternal)
		}
	}
}
Beispiel #6
0
func (s *Server) handleStatic(c *gin.Context) {
	var ct string

	// Get static file path
	p, _ := c.Params.Get("path")
	if p == "" {
		p = "index.html"
	}

	// Try to get file data from filesystem
	localPath := path.Join(s.config.StaticDir, p)
	if _, err := os.Stat(localPath); err == nil {
		logger.Debug("server", "serving %q from filesystem", p)
		c.File(localPath)
		return
	}

	// Get file data from built-in assets
	data, err := Asset(strings.TrimPrefix(p, "/"))
	if err != nil {
		c.JSON(http.StatusNotFound, nil)
		return
	}

	switch path.Ext(p) {
	case ".css":
		ct = "text/css"

	case ".js":
		ct = "text/javascript"

	default:
		ct = http.DetectContentType(data)
	}

	logger.Debug("server", "serving %q from built-in assets", p)
	c.Data(http.StatusOK, ct, data)
}
Beispiel #7
0
func Index(c *gin.Context) {
	c.File("./templates/index.html")
}
Beispiel #8
0
func handle404(c *gin.Context) {
	c.File("./client/templates/404.html")
}
Beispiel #9
0
func ServeRepoFile(c *gin.Context) {
	repo := session.Repo(c)
	arch := c.Param("arch")
	file := c.Param("file")
	c.File(path.Join(repo.PathDeep(arch), file))
}
Beispiel #10
0
func IndexHandler(c *gin.Context) {
	c.File("static/index.html")
}
Beispiel #11
-1
func doGETCache(c *gin.Context) {

	hash := normalize(c.Param("hash"))

	file := store.GetCachePath(hash)
	c.File(file)
}