Ejemplo n.º 1
0
func main() {

	configFile, err := ioutil.ReadFile("config.json")
	if err != nil {
		panic("Error opening config file: " + err.Error())
	}

	var c config
	err = json.Unmarshal(configFile, &c)
	if err != nil {
		panic(err)
	}

	var db *dropbox.Dropbox
	// 1. Create a new dropbox object.
	db = dropbox.NewDropbox()

	// 2. Provide your clientid and clientsecret (see prerequisite).
	db.SetAppInfo(c.Clientid, c.Clientsecret)

	// 3. Provide the user token.
	db.SetAccessToken(c.Token)
	fmt.Println(c.DropboxPath)
	err = db.DownloadToFile(c.DropboxPath, c.Destination, "")
	if err != nil {
		panic(err)
	}
}
Ejemplo n.º 2
0
// New creates a client to connect to Dropbox.
func New(key, secret, token string) (db *Dropbox, err error) {
	if key == "" {
		err = errors.New("empty key")
		return
	}
	if secret == "" {
		err = errors.New("empty secret")
		return
	}
	if token == "" {
		err = errors.New("empty token")
		return
	}

	var (
		client *dropbox.Dropbox
	)

	client = dropbox.NewDropbox()
	client.SetAppInfo(key, secret)
	client.SetAccessToken(token)

	db = &Dropbox{
		client: client,
		cwd:    "/",
	}

	return
}
Ejemplo n.º 3
0
func main() {

	err := rpio.Open()
	if err != nil {
		fmt.Println("rpio.Open()")
		fmt.Println(err)
	}
	// Unmap gpio memory when done
	defer rpio.Close()

	toggleLight(9)

	var db *dropbox.Dropbox

	db = dropbox.NewDropbox()

	db.SetAppInfo(clientid, clientsecret)
	db.SetAccessToken(token)

	toggleLight(10)

	shoot(db)

	toggleLight(11)
}
Ejemplo n.º 4
0
func handler(w http.ResponseWriter, r *http.Request) {
	var err error
	var db *dropbox.Dropbox
	var input io.ReadCloser
	var length int64
	var ok bool
	var cachedItem interface{}
	var s string

	if r.URL.Path[1:] == "favicon.ico" {
		return
	}

	cachedItem, ok = Lru.Get(r.URL.Path[1:])

	if ok {
		item := cachedItem.(cacheItem)
		s = item.Value
		length = item.Length
	} else {

		var clientid, clientsecret string
		var token string

		clientid = os.Getenv("CLIENTID")
		clientsecret = os.Getenv("CLIENTSECRET")
		token = os.Getenv("TOKEN")

		// 1. Create a new dropbox object.
		db = dropbox.NewDropbox()

		// 2. Provide your clientid and clientsecret (see prerequisite).
		db.SetAppInfo(clientid, clientsecret)

		// 3. Provide the user token.
		db.SetAccessToken(token)

		// 4. Send your commands.
		// In this example, you will create a new folder named "demo".
		if input, length, _, err = db.Thumbnails("/"+r.URL.Path[2:], "jpeg", r.URL.Path[1:2]); err != nil {
			fmt.Printf("Error: %s Url: %s Size: \n", err, r.URL.Path[2:], r.URL.Path[1:2])
		} else {
			//fmt.Printf("Error %s\n", input)

			buf := new(bytes.Buffer)
			buf.ReadFrom(input)
			s = buf.String()
			Lru.Add(r.URL.Path[1:], cacheItem{Value: s, Length: length})

		}
	}

	w.Header().Set("Content-Length", strconv.FormatInt(length, 10))
	fmt.Fprintf(w, "%s", s)

}
Ejemplo n.º 5
0
func WriteFile(config *DropboxConfig, file string, content string) error {
	var db *dropbox.Dropbox

	db = dropbox.NewDropbox()
	db.SetAppInfo(config.AppKey, config.AppSecret)
	db.SetAccessToken(config.Token)

	in := ioutil.NopCloser(bytes.NewBufferString(content))
	_, err := db.UploadByChunk(in, 1024, file, true, "")
	return err
}
Ejemplo n.º 6
0
func ReadFile(config *DropboxConfig, file string) (string, error) {

	var err error
	var db *dropbox.Dropbox
	var s string

	db = dropbox.NewDropbox()
	db.SetAppInfo(config.AppKey, config.AppSecret)
	db.SetAccessToken(config.Token)

	rd, _, err := db.Download(file, "", 0)
	if err != nil {
		return s, err
	}

	buf := new(bytes.Buffer)
	buf.ReadFrom(rd)
	s = buf.String()

	return s, nil
}
Ejemplo n.º 7
0
func handleOriginalFile(w http.ResponseWriter, r *http.Request) {
	var err error
	var db *dropbox.Dropbox
	//        var input io.ReadCloser
	var length int64
	var ok bool
	var cachedItem interface{}
	var s string

	if r.URL.Path[1:] == "favicon.ico" {
		return
	}

	cachedItem, ok = Lru.Get(r.URL.Path[5:])

	if ok {
		item := cachedItem.(cacheItem)
		s = item.Value
		length = item.Length
	} else {
		var clientid, clientsecret string
		var token, rev string

		clientid = os.Getenv("CLIENTID")
		clientsecret = os.Getenv("CLIENTSECRET")
		token = os.Getenv("TOKEN")

		// 1. Create a new dropbox object.
		db = dropbox.NewDropbox()

		// 2. Provide your clientid and clientsecret (see prerequisite).
		db.SetAppInfo(clientid, clientsecret)

		// 3. Provide the user token.
		db.SetAccessToken(token)

		rev = ""

		//h := md5.New()
		//io.WriteString(h, r.URL.Path[5:])
		//b := h.Sum(nil)
		str := strings.Replace(r.URL.Path[5:], "/", "-", -1)

		err = db.DownloadToFile("/"+r.URL.Path[5:], "/tmp/"+str, rev)
		if err != nil {
			fmt.Printf("123 Error: %s Url: %s Size: \n", err, r.URL.Path[5:], r.URL.Path[1:2])
		} else {
			dat, err := ioutil.ReadFile("/tmp/" + str)
			if err != nil {

			} else {
				f, err := os.Open("/tmp/" + str)
				if err != nil {

				}
				fi, err := f.Stat()
				if err != nil {
					// Could not obtain stat, handle error
				}

				length = fi.Size()
				s = string(dat[:])
				//				w.Header().Set("Content-Length", strconv.FormatInt(fi.Size(), 10))
				fmt.Fprintf(w, "%s", dat)
				Lru.Add(r.URL.Path[5:], cacheItem{Value: s, Length: length})
			}
		}
	}
	w.Header().Set("Content-Length", strconv.FormatInt(length, 10))
	fmt.Fprintf(w, "%s", s)
}