Beispiel #1
0
// Add a new block to a structured file. The name of the block
// is in the parameter "block", the content is as before in "data"
func blockAddFunc(w http.ResponseWriter, r *http.Request, filesys *fs.RootFileSystem) {
	fileNode, dirNode, err := filesys.GetFileOrDirectory(r.URL.Path, true)
	if err != nil {
		writeError(w, err)
	} else if dirNode != nil {
		writeError(w, errors.New("Cannot add to a directory"))
	} else {
		// We have a filenode...
		filesys.SaveNewBlock(r.URL.Path, fileNode, r.Form["block"][0], []byte(r.Form["data"][0]), true)
		getFunc(w, r, filesys)
	}
}
Beispiel #2
0
func attrAddFunc(w http.ResponseWriter, r *http.Request, filesys *fs.RootFileSystem) {
	fileNode, dirNode, err := filesys.GetFileOrDirectory(r.URL.Path, false)
	if err != nil {
		writeError(w, err)
	} else if dirNode != nil {
		dirNode.Attributes[r.Form["key"][0]] = r.Form["value"][0]
		filesys.ChangeCache.SaveDirectoryNode(dirNode)
		statFunc(w, r, filesys)
	} else if fileNode != nil {
		fileNode.Attributes[r.Form["key"][0]] = r.Form["value"][0]
		filesys.ChangeCache.SaveFileNode(fileNode)
		statFunc(w, r, filesys)
	}
}
Beispiel #3
0
func statFunc(w http.ResponseWriter, r *http.Request, filesys *fs.RootFileSystem) {
	fileNode, dirNode, err := filesys.GetFileOrDirectory(r.URL.Path, false)
	if err != nil {
		writeError(w, err)
	} else if dirNode != nil {
		var b []byte
		b, err = json.MarshalIndent(dirNode, "", "    ")
		fmt.Fprintf(w, "%v", string(b))
	} else if fileNode != nil {
		var b []byte
		b, err = json.MarshalIndent(fileNode, "", "    ")
		fmt.Fprintf(w, "%v", string(b))
	}
}
Beispiel #4
0
// The block get Func retrieves a block given a range
// Parameters are
// start (optional) the start block (inclusive)
// end (optional) the end block (inclusive)
// tag (optional) the tag of the version to do this for
// Basically the function retrieves the route given the tag version (or default root)
// and then filters the block names given the start and end.
// The return data is a list structure containing the key (block name) and the value (the value of the block)
func blockGetFunc(w http.ResponseWriter, r *http.Request, filesys *fs.RootFileSystem) {
	fileNode, dirNode, err := filesys.GetFileOrDirectory(r.URL.Path, false)
	if err != nil {
		writeError(w, err)
	} else if dirNode != nil {
		writeError(w, errors.New("Cannot do this to a directory"))
	} else {
		// We have a filenode...
		blockStructure, err := filesys.GetBlock(fileNode, getFormValue(r, "tag", ""), getFormValue(r, "start", ""), getFormValue(r, "end", ""))
		if err != nil {
			writeError(w, err)
		} else {
			var b []byte
			b, err = json.MarshalIndent(blockStructure, "", "    ")
			fmt.Fprintf(w, "%v", string(b))
		}
	}
}
Beispiel #5
0
func getFunc(w http.ResponseWriter, r *http.Request, filesys *fs.RootFileSystem) {
	// This can be two things
	// 1 get of a file, so dump the contents
	// 2 get of a folder, so construct some nice json

	fileNode, dirNode, err := filesys.GetFileOrDirectory(r.URL.Path, false)

	if err != nil {
		writeError(w, err)
	} else {
		w.WriteHeader(http.StatusOK)
		if fileNode != nil {
			var x []byte
			x, err = filesys.ReadFile(r.URL.Path)
			fmt.Fprintf(w, "%v", string(x))
		} else {
			// Need to get file directory structure as a json object
			dirStructure := getDirStructure(r.URL.Path, dirNode, filesys)
			var b []byte
			b, err = json.MarshalIndent(dirStructure, "", "    ")
			fmt.Fprintf(w, "%v", string(b))
		}
	}
}