Esempio n. 1
0
func restGetNeed(m *model.Model, w http.ResponseWriter, r *http.Request) {
	var qs = r.URL.Query()
	var folder = qs.Get("folder")

	files := m.NeedFolderFilesLimited(folder, 100, 2500) // max 100 files or 2500 blocks

	w.Header().Set("Content-Type", "application/json; charset=utf-8")
	json.NewEncoder(w).Encode(files)
}
Esempio n. 2
0
func restGetNeed(m *model.Model, w http.ResponseWriter, r *http.Request) {
	var qs = r.URL.Query()
	var folder = qs.Get("folder")

	files := m.NeedFolderFilesLimited(folder, 100) // max 100 files
	// Convert the struct to a more loose structure, and inject the size.
	output := make([]map[string]interface{}, 0, len(files))
	for _, file := range files {
		output = append(output, map[string]interface{}{
			"Name":         file.Name,
			"Flags":        file.Flags,
			"Modified":     file.Modified,
			"Version":      file.Version,
			"LocalVersion": file.LocalVersion,
			"NumBlocks":    file.NumBlocks,
			"Size":         protocol.BlocksToSize(file.NumBlocks),
		})
	}

	w.Header().Set("Content-Type", "application/json; charset=utf-8")
	json.NewEncoder(w).Encode(output)
}