예제 #1
0
파일: update.go 프로젝트: send-to/server
// HandleUpdateShow handles the POST of the form to update a file
func HandleUpdate(context router.Context) error {

	// Find the file
	file, err := files.Find(context.ParamInt("id"))
	if err != nil {
		return router.NotFoundError(err)
	}

	// Authorise update file
	err = authorise.Resource(context, file)
	if err != nil {
		return router.NotAuthorizedError(err)
	}

	// Update the file from params
	params, err := context.Params()
	if err != nil {
		return router.InternalError(err)
	}

	// Find the to user, by querying users on username or email
	// Set the user id if found, else return 404 error, user not found

	// TODO: Make *sure* this only accepts the params we want
	err = file.Update(params.Map())
	if err != nil {
		return router.InternalError(err)
	}

	// Redirect to file
	return router.Redirect(context, file.URLShow())
}
예제 #2
0
파일: download.go 프로젝트: send-to/server
// HandleDownload sends a single file
func HandleDownload(context router.Context) error {

	// Find the file
	file, err := files.Find(context.ParamInt("id"))
	if err != nil {
		return router.InternalError(err)
	}

	// Authorise access to this file - only the file owners can access their own files
	err = authorise.Resource(context, file)
	if err != nil {
		return router.NotAuthorizedError(err)
	}

	// If we are permitted, send the file to the user
	//w.Header().Set("Content-Type", "text/plain; charset=utf-8")
	//http.DetectContentType(data []byte) string
	h := context.Header()
	h.Set("Content-Type", "application/pgp-encrypted")
	h.Set("Content-Disposition", fmt.Sprintf("attachment; filename=\"%s\"", file.Name()))
	h.Set("Content-Transfer-Encoding", "binary")

	http.ServeFile(context, context.Request(), file.Path)
	return nil
}
예제 #3
0
파일: update.go 프로젝트: send-to/server
// HandleUpdateShow renders the form to update a file
func HandleUpdateShow(context router.Context) error {

	// Find the file
	file, err := files.Find(context.ParamInt("id"))
	if err != nil {
		return router.NotFoundError(err)
	}

	// Authorise update file
	err = authorise.ResourceAndAuthenticity(context, file)
	if err != nil {
		return router.NotAuthorizedError(err)
	}

	// Render the template
	view := view.New(context)
	view.AddKey("file", file)
	return view.Render()
}
예제 #4
0
파일: destroy.go 프로젝트: send-to/server
// HandleDestroy handles a DESTROY request for files
func HandleDestroy(context router.Context) error {

	// Find the file
	file, err := files.Find(context.ParamInt("id"))
	if err != nil {
		return router.NotFoundError(err)
	}

	// Authorise destroy file
	err = authorise.ResourceAndAuthenticity(context, file)
	if err != nil {
		return router.NotAuthorizedError(err)
	}

	// Destroy the file
	file.Destroy()

	// Redirect to files root
	return router.Redirect(context, "/files")
}