Example #1
0
// gets the settings from a dropbox file, parses it, returns it.
func (f *fetcher) checkSettings() error {
	u := dropbox.Uri{
		Root: "sandbox/_settings.txt",
	}

	file, meta, err := dropbox.GetFile(f.Session, u, nil)

	if err != nil {
		log.Printf("receieved error trying to retrieve settings file: %s", err)
	}

	set, errs := parseSettings(file)
	if set.Domain == "" {
		f.Settings.Domain = f.User.Name
	} else {
		f.Settings.Domain = set.Domain
	}
	if set.Title == "" {
		f.Settings.Title = "A Small Victory"
	} else {
		f.Settings.Title = set.Title
	}

	if meta.Revision == f.User.SettingsRev {
		return errors.New("Settings revision matches")
	}

	content, err := createSettings(f.Settings, errs)

	if err != nil {
		log.Printf("receieved error trying to generate settings file: %s", err)
		return err
	}

	meta, err = dropbox.UploadFile(f.Session, content, u, nil)

	f.Settings.Revision = meta.Revision

	if err != nil {
		log.Printf("receieved error trying to create settings file: %s", err)
		return err
	}

	return err
}
Example #2
0
func (f *fetcher) retrieveContent(path string, extension string) (string, error) {
	u := dropbox.Uri{
		Root: "sandbox" + path,
	}

	file, _, err := dropbox.GetFile(f.Session, u, nil)
	if err != nil {
		return "", err
	}

	// Markdown check
	if extension == "md" {
		p := markdown.NewParser(&markdown.Extensions{Smart: true})
		buf := new(bytes.Buffer)
		p.Markdown(bytes.NewReader(file), markdown.ToHTML(buf))
		return buf.String(), nil
	} else {
		return string(file), nil
	}

}