// 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 }
// Fills a dropbox with the default stuff func fillDropbox(token string) { // The session to write with s := dropbox.Session{ AppKey: DROPBOX_KEY, AppSecret: DROPBOX_SECRET, AccessType: "app_folder", Token: token, } files := []string{"01-east-river_01.jpg", "01-east-river_02.md", "02-code_01.jpg", "02-code_02.md", "03-coffee_01.jpg", "03-coffee_02.md", "first-victory-theme.css", "first-victory-theme.js"} for _, f := range files { u := dropbox.Uri{ Root: "sandbox", Path: "/" + f, } content, err := ioutil.ReadFile("files/" + f) _, err = dropbox.UploadFile(s, content, u, nil) if err != nil { log.Printf("error uploading default file: %s", err.Error()) } } }