Пример #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
}
Пример #2
0
func (fs *Files) Upload(conf *config.Config, stor *storage.Storage, r *http.Request, w http.ResponseWriter) (err error) {
	// make temp files object
	tmpfs := &TmpFiles{r: r, fields: make(map[string]*temp.File), result: make(map[string]*temp.File), tmpDir: conf.TmpDir}
	defer tmpfs.Close()

	// upload
	for _, f := range *fs {
		err = f.Upload(tmpfs)
		if err != nil {
			return
		}
	}

	result := tmpfs.Result()

	// add to storage and set stae
	for name, tf := range result {
		aelog.Debugf("Uploader add file: %s (%s, %s)", name, utils.HumanBytes(tf.Size), tf.MimeType)
		file, _ := stor.Add(name, tf.File, tf.Size)
		for _, f := range *fs {
			if f.Name == name {
				f.SetState(file)
			}
		}
	}

	return
}
Пример #3
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
}
Пример #4
0
func (u unZip) saveFile(to string, zf *zip.File, s *storage.Storage) (fs int64, err error) {
	if zf.FileInfo().Size() == 0 {
		return
	}
	fname := strings.Trim(to, "/") + "/" + strings.Trim(zf.Name, "/")
	reader, err := zf.Open()
	if err != nil {
		return
	}
	defer reader.Close()
	if f, err := s.Add(fname, reader, zf.FileInfo().Size()); err == nil {
		return f.FSize, nil
	}
	return
}
Пример #5
0
func (u unZip) OnSave(file *storage.File, w http.ResponseWriter, r *http.Request, s *storage.Storage) (e error) {
	mode := u.needUnZip(r)
	if mode == UNZIP_NO {
		return
	}
	aelog.Debugf("UnZip: start unzip(%d) files to: %s (%s)", mode, file.Name, utils.HumanBytes(file.FSize))
	if mode == UNZIP_FORCE {
		s.DeleteChilds(file.Name)
	}

	filesCount, filesSize, err := u.unZipTo(file.Name, file, s)
	if err != nil {
		aelog.Debugf("UnZip: error: %v", err)
		w.Header().Add("X-Ae-Unzip-Error", err.Error())
		return
	}
	aelog.Debugf("UnZip: unziped: %s (%d files, %s files size)", file.Name, filesCount, utils.HumanBytes(filesSize))
	w.Header().Add("X-Ae-Unzip-Count", fmt.Sprint(filesCount))
	w.Header().Add("X-Ae-Unzip-Size", utils.HumanBytes(filesSize))
	return
}