Ejemplo n.º 1
0
func (fl fileList) OnCommand(command, filename string, w http.ResponseWriter, r *http.Request, s *storage.Storage) (cont bool, err error) {
	if command != fileListCommand {
		return true, nil
	}
	var response = FileList{}
	list, err := s.Index.List(filename, fl.parseNested(r))
	if err != nil {
		errString := err.Error()
		response.Err = &errString
		fl.jsonResponse(w, response)
		return
	}
	s.Stats.Counters.Get.Add()
	response.List = make([]FileInfo, 0)
	for _, fn := range list {
		if f, ok := s.Get(fn); ok {
			response.List = append(response.List, FileInfo{
				Name:        f.Name[len(filename)+1:],
				Size:        f.FSize,
				ContentType: f.ContentType(),
				MD5:         f.Md5S(),
				Modified:    f.Time.Unix(),
			})
		}
	}
	s.Stats.Traffic.Output.AddN(fl.jsonResponse(w, response))
	return false, nil
}
Ejemplo n.º 2
0
func (u unZip) OnCommand(command, filename string, w http.ResponseWriter, r *http.Request, s *storage.Storage) (cont bool, e error) {
	if command != "unzip" {
		return true, nil
	}
	if file, ok := s.Get(filename); ok {
		return true, u.OnSave(file, w, r, s)
	}
	return true, nil
}