2014-06-03 15:08:58 +00:00
|
|
|
package commands
|
2013-10-04 17:09:03 +00:00
|
|
|
|
|
|
|
import (
|
2014-06-03 15:08:58 +00:00
|
|
|
"github.com/github/git-media/gitmedia"
|
|
|
|
"github.com/github/git-media/gitmediaclient"
|
2014-03-12 14:55:01 +00:00
|
|
|
"strings"
|
2013-10-04 17:09:03 +00:00
|
|
|
)
|
|
|
|
|
2014-05-27 16:36:07 +00:00
|
|
|
type PushCommand struct {
|
2013-10-04 17:09:03 +00:00
|
|
|
*Command
|
|
|
|
}
|
|
|
|
|
2014-05-27 16:36:07 +00:00
|
|
|
func (c *PushCommand) Run() {
|
2013-10-21 20:02:15 +00:00
|
|
|
q := gitmedia.UploadQueue()
|
|
|
|
q.Walk(func(id string, body []byte) error {
|
2014-03-12 14:55:01 +00:00
|
|
|
fileInfo := string(body)
|
|
|
|
parts := strings.Split(fileInfo, ":")
|
|
|
|
|
|
|
|
var sha, filename string
|
|
|
|
sha = parts[0]
|
|
|
|
if len(parts) > 1 {
|
|
|
|
filename = parts[1]
|
|
|
|
}
|
|
|
|
|
2013-10-21 20:02:15 +00:00
|
|
|
path := gitmedia.LocalMediaPath(sha)
|
2014-04-01 15:17:04 +00:00
|
|
|
|
|
|
|
err := gitmediaclient.Options(path)
|
|
|
|
if err != nil {
|
|
|
|
gitmedia.Panic(err, "error uploading file %s", filename)
|
|
|
|
}
|
|
|
|
|
|
|
|
err = gitmediaclient.Put(path, filename)
|
2013-10-21 20:02:15 +00:00
|
|
|
if err != nil {
|
|
|
|
gitmedia.Panic(err, "error uploading file %s", sha)
|
|
|
|
}
|
2013-10-21 18:42:29 +00:00
|
|
|
|
2013-10-21 20:02:15 +00:00
|
|
|
if err := q.Del(id); err != nil {
|
|
|
|
gitmedia.Panic(err, "error removing %s from queue", sha)
|
|
|
|
}
|
2013-10-21 20:25:24 +00:00
|
|
|
return nil
|
2013-10-21 20:02:15 +00:00
|
|
|
})
|
2013-10-04 17:09:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
2014-05-27 16:36:07 +00:00
|
|
|
registerCommand("push", func(c *Command) RunnableCommand {
|
|
|
|
return &PushCommand{Command: c}
|
2013-10-04 17:09:03 +00:00
|
|
|
})
|
|
|
|
}
|