2019-03-29 09:31:37 +04:00
|
|
|
// Yandex Disk File Pusher
|
|
|
|
// Copyright (c) 2019 Vladimir "fat0troll" Hodakov
|
|
|
|
|
|
|
|
package yandexv1
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/fat0troll/yapusher/internal/context"
|
|
|
|
"github.com/rs/zerolog"
|
|
|
|
"gitlab.com/pztrn/flagger"
|
|
|
|
)
|
|
|
|
|
2019-03-30 07:06:15 +04:00
|
|
|
const YandexAppID = "7d8a0561fdc44c05bb6695b464403f9c"
|
|
|
|
const YandexAppPw = "56e12e4ed0d64738bf441a47f68c7146"
|
|
|
|
const DefaultDeviceName = "yapusher-cli"
|
2019-10-11 12:13:01 +04:00
|
|
|
const MaxUploadSize = 50 * 1024 * 1024 * 1024 // 50 gigabytes
|
2019-03-29 09:31:37 +04:00
|
|
|
|
|
|
|
var (
|
|
|
|
c *context.Context
|
|
|
|
dlog zerolog.Logger
|
|
|
|
)
|
|
|
|
|
|
|
|
// New initializes package
|
|
|
|
func New(cc *context.Context) {
|
|
|
|
c = cc
|
|
|
|
dlog = c.Logger.With().Str("domain", "yandex").Int("version", 1).Logger()
|
|
|
|
|
|
|
|
_ = c.Flagger.AddFlag(&flagger.Flag{
|
|
|
|
Name: "authCode",
|
|
|
|
Description: "Auth code obtained from Yandex (seven digits).",
|
|
|
|
Type: "int",
|
|
|
|
DefaultValue: 0000000,
|
|
|
|
})
|
|
|
|
|
2019-03-30 04:44:51 +04:00
|
|
|
_ = c.Flagger.AddFlag(&flagger.Flag{
|
|
|
|
Name: "uploadPath",
|
|
|
|
Description: "Path to upload your file on Yandex.Disk. Must exist before uploading.",
|
|
|
|
Type: "string",
|
2019-03-30 07:00:15 +04:00
|
|
|
DefaultValue: "",
|
2019-03-30 04:44:51 +04:00
|
|
|
})
|
|
|
|
|
|
|
|
_ = c.Flagger.AddFlag(&flagger.Flag{
|
|
|
|
Name: "file",
|
2019-03-30 07:00:15 +04:00
|
|
|
Description: "Path to file that will be uploaded. Max upload size - 10 GB",
|
2019-03-30 04:44:51 +04:00
|
|
|
Type: "string",
|
|
|
|
DefaultValue: "",
|
|
|
|
})
|
|
|
|
|
2019-03-30 07:00:15 +04:00
|
|
|
_ = c.Flagger.AddFlag(&flagger.Flag{
|
|
|
|
Name: "force",
|
|
|
|
Description: "Force file to be uploaded even if destination file on Yandex.Disk already exists.",
|
|
|
|
Type: "bool",
|
|
|
|
DefaultValue: false,
|
|
|
|
})
|
|
|
|
|
2019-03-29 09:31:37 +04:00
|
|
|
dlog.Info().Msg("Domain initialized")
|
|
|
|
}
|
|
|
|
|
|
|
|
// Process handles authorization and files
|
|
|
|
func Process() {
|
2019-03-30 04:31:31 +04:00
|
|
|
authCode, _ := c.Flagger.GetIntValue("authCode")
|
|
|
|
if authCode != 0 {
|
|
|
|
sendCode(authCode)
|
|
|
|
}
|
|
|
|
|
2019-03-29 09:31:37 +04:00
|
|
|
if !checkAuth() {
|
|
|
|
authorize()
|
2019-03-30 08:07:13 +04:00
|
|
|
} else {
|
|
|
|
filePath, _ := c.Flagger.GetStringValue("file")
|
|
|
|
if filePath != "" {
|
|
|
|
uploadPath, _ := c.Flagger.GetStringValue("uploadPath")
|
|
|
|
forceUpload, _ := c.Flagger.GetBoolValue("force")
|
|
|
|
uploadFile(uploadPath, filePath, forceUpload)
|
|
|
|
}
|
2019-03-29 09:31:37 +04:00
|
|
|
}
|
2019-03-30 04:44:51 +04:00
|
|
|
|
|
|
|
showHelp()
|
2019-03-29 09:31:37 +04:00
|
|
|
}
|