/
dropbox.go
44 lines (39 loc) · 1.08 KB
/
dropbox.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package main
import (
"github.com/pearkes/Dropbox-Go/dropbox"
"io/ioutil"
"log"
"os"
)
func newDropboxUrl() string {
s := dropbox.Session{
AppKey: DROPBOX_KEY,
AppSecret: DROPBOX_SECRET,
AccessType: "app_folder",
RedirectUri: os.Getenv("DROPBOX_CALLBACK"),
}
url := dropbox.GenerateAuthorizeUrl(s.AppKey, &dropbox.Parameters{RedirectUri: s.RedirectUri})
return url
}
// 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())
}
}
}