Example #1
0
func (h *AudioHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
	log.Debugf("path:%s localpath:%s", h.Path, h.LocalPath)

	tmplData, err := asset.Asset("audio.html")
	if err != nil {
		WriteError(w, r, "template: %s", err)
		return
	}

	tmpl := template.Must(template.New("audio.html").Parse(string(tmplData)))

	data := &Gallery{
		Title:       "Audio",
		Files:       make([]*types.File, 0),
		Directories: make([]*types.File, 0),
		Path:        h.Path,
		LocalPath:   h.LocalPath,
		Breadcrumb:  NewBreadcrumb(),
	}

	tmp := strings.Split(filepath.Join(h.UrlPrefix, h.Path), "/")
	var crumbUrl string
	for i := 1; i < len(tmp); i++ {
		crumbUrl = strings.Join(tmp[0:i+1], "/") + "/"
		log.Debugf("breadcrumb #%d - %s - %s", i, tmp[i], crumbUrl)
		data.Breadcrumb.Add(crumbUrl, tmp[i])
	}

	for _, f := range h.Files {
		if f.IsDir {
			data.Directories = append(data.Directories, f)
			continue
		}
		if filetype.FileMatch(f, filetype.AudioFile) {
			data.Files = append(data.Files, f)
		}

	}

	log.Tracef("handler path:%s localpath:%s files:%d dirs:%d",
		data.Path, data.LocalPath, len(data.Files), len(data.Directories))

	err = tmpl.Execute(w, data)
	if err != nil {
		WriteError(w, r, "template render: %s", err)
		return
	}

}
Example #2
0
func (h *VideoHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
	log.Debugf("path:%s localpath:%s", h.Path, h.LocalPath)

	tmplData, err := asset.Asset("video.html")
	if err != nil {
		WriteError(w, r, "template: %s", err)
		return
	}

	tmpl := template.Must(template.New("Videos.html").Parse(string(tmplData)))

	data := &Gallery{
		Title:        "Videos",
		Files:        make([]*types.File, 0),
		Path:         h.Path,
		LocalPath:    h.LocalPath,
		UrlPrefix:    h.UrlPrefix,
		RelPath:      h.RelPath,
		RemoteServer: h.RemoteServer,
		Breadcrumb:   NewBreadcrumb(),
	}

	log.Tracef("handler %s", h.Handler.Path)

	tmp := strings.Split(h.Path, "/")
	for i := 0; i < len(tmp); i++ {
		data.Breadcrumb.Add(h.Url(strings.Join(tmp[0:i+1], "/")), tmp[i])
	}

	for _, file := range h.Files {
		if file.IsDir {
			data.Directories = append(data.Directories, file)
			continue
		}
		if filetype.FileMatch(file, filetype.VideoFile) {
			data.Files = append(data.Files, file)
		}
	}

	err = tmpl.Execute(w, data)
	if err != nil {
		WriteError(w, r, "template render: %s", err)
		return
	}

}