Esempio n. 1
0
func init() {
	tmplData, err := asset.Asset("picture.html")
	if err != nil {
		log.Errorf("template: %s", err)
	}
	tmpl = template.Must(template.New("pictures").Parse(string(tmplData)))
}
Esempio n. 2
0
func (h *ListHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
	log.Debugf("path:%s localpath:%s", h.Path, h.LocalPath)

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

	st, err := os.Stat(h.LocalPath)
	if err == nil && st.IsDir() == false {
		dirname := filepath.Dir(h.LocalPath)
		prefix := filepath.Dir(r.URL.Path)
		log.Debugf("Serving static file path %s: dirname:%s prefix:%s localpath:%s", r.URL.Path, dirname, prefix, h.LocalPath)
		http.StripPrefix(prefix, http.FileServer(http.Dir(dirname))).ServeHTTP(w, r)
		return
	}

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

	data := &Gallery{
		Title:        "Lists",
		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)
		} else {
			data.Files = append(data.Files, file)
		}
	}

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

}
Esempio n. 3
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
	}

}
Esempio n. 4
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
	}

}
Esempio n. 5
0
func (me *DashboardHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
	log.Tracef("request %s", r.URL)
	log.Tracef("%#v", me)

	data := &DashboardData{
		Username:   me.Username,
		UrlPrefix:  "/~" + me.Username,
		ServerData: make(map[string]*ServerData, 0),
	}

	// local host server data
	req := &types.ListPathRequest{
		User: me.Username,
	}
	v, err := me.VoyFile.Load(req)
	if err != nil {
		log.Warnf("Load %s", err)
		return
	}
	data.ServerData["localhost"] = &ServerData{
		Server:     "localhost",
		ServerAddr: "localhost",
		Voy:        v,
	}

	log.Tracef("servers %s", v.Servers)

	dopts := vapi.DefaultDialOptions()
	for server, server_addr := range v.Servers {
		hostport := vapi.HostDefaultPort(server_addr, vapi.DefaultPortString)
		conn, err := vapi.Connect(hostport, dopts)
		if err != nil {
			log.Warnf("unable to connect to %s: %s", hostport, err)
			continue
		}

		creq := &vapi.ConfigRequest{
			User: me.Username,
		}

		cres, err := conn.Client.GetConfig(me.Ctx, creq)
		if err != nil {
			log.Warnf("unable to get config to %s: %s", hostport, err)
			continue
		}

		vf := &voy.VoyFile{
			Allow:   cres.Allow,
			Alias:   cres.Alias,
			Servers: cres.Servers,
		}
		data.ServerData[server] = &ServerData{
			Server:     server,
			ServerAddr: server_addr,
			Voy:        vf,
		}

	}

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

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

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

}