Browse Source

go fmt

tags/v1.0.0
Andrea Spacca 5 years ago
parent
commit
0605b8e271
4 changed files with 29 additions and 35 deletions
  1. +6
    -7
      cmd/cmd.go
  2. +5
    -5
      server/handlers.go
  3. +0
    -1
      server/server.go
  4. +18
    -22
      server/storage.go

+ 6
- 7
cmd/cmd.go View File

@@ -116,14 +116,14 @@ var globalFlags = []cli.Flag{
EnvVar: "BUCKET", EnvVar: "BUCKET",
}, },
cli.StringFlag{ cli.StringFlag{
Name: "gdrive-client-json-filepath",
Usage: "",
Value: "",
Name: "gdrive-client-json-filepath",
Usage: "",
Value: "",
}, },
cli.StringFlag{ cli.StringFlag{
Name: "gdrive-local-config-path",
Usage: "",
Value: "",
Name: "gdrive-local-config-path",
Usage: "",
Value: "",
}, },
cli.IntFlag{ cli.IntFlag{
Name: "rate-limit", Name: "rate-limit",
@@ -271,7 +271,6 @@ func New() *Cmd {
options = append(options, server.HttpAuthCredentials(httpAuthUser, httpAuthPass)) options = append(options, server.HttpAuthCredentials(httpAuthUser, httpAuthPass))
} }



switch provider := c.String("provider"); provider { switch provider := c.String("provider"); provider {
case "s3": case "s3":
if accessKey := c.String("aws-access-key"); accessKey == "" { if accessKey := c.String("aws-access-key"); accessKey == "" {


+ 5
- 5
server/handlers.go View File

@@ -59,8 +59,8 @@ import (
"github.com/gorilla/mux" "github.com/gorilla/mux"
"github.com/russross/blackfriday" "github.com/russross/blackfriday"


qrcode "github.com/skip2/go-qrcode"
"encoding/base64" "encoding/base64"
qrcode "github.com/skip2/go-qrcode"
) )


var ( var (
@@ -166,9 +166,9 @@ func (s *Server) previewHandler(w http.ResponseWriter, r *http.Request) {
Filename string Filename string
Url string Url string
ContentLength uint64 ContentLength uint64
GAKey string
GAKey string
UserVoiceKey string UserVoiceKey string
QRCode string
QRCode string
}{ }{
contentType, contentType,
content, content,
@@ -326,7 +326,7 @@ func MetadataForRequest(contentType string, r *http.Request) Metadata {
MaxDate: time.Now().Add(time.Hour * 24 * 365 * 10), MaxDate: time.Now().Add(time.Hour * 24 * 365 * 10),
Downloads: 0, Downloads: 0,
MaxDownloads: 99999999, MaxDownloads: 99999999,
DeletionToken: Encode(10000000 + int64(rand.Intn(1000000000))) + Encode(10000000 + int64(rand.Intn(1000000000))),
DeletionToken: Encode(10000000+int64(rand.Intn(1000000000))) + Encode(10000000+int64(rand.Intn(1000000000))),
} }


if v := r.Header.Get("Max-Downloads"); v == "" { if v := r.Header.Get("Max-Downloads"); v == "" {
@@ -439,7 +439,7 @@ func (s *Server) putHandler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/plain") w.Header().Set("Content-Type", "text/plain")


relativeURL, _ := url.Parse(path.Join(token, filename)) relativeURL, _ := url.Parse(path.Join(token, filename))
deleteUrl , _ := url.Parse(path.Join(token, filename, metadata.DeletionToken))
deleteUrl, _ := url.Parse(path.Join(token, filename, metadata.DeletionToken))


w.Header().Set("X-Url-Delete", resolveUrl(r, deleteUrl, true)) w.Header().Set("X-Url-Delete", resolveUrl(r, deleteUrl, true))




+ 0
- 1
server/server.go View File

@@ -203,7 +203,6 @@ func TLSConfig(cert, pk string) OptionFn {
} }
} }



func HttpAuthCredentials(user string, pass string) OptionFn { func HttpAuthCredentials(user string, pass string) OptionFn {
return func(srvr *Server) { return func(srvr *Server) {
srvr.AuthUser = user srvr.AuthUser = user


+ 18
- 22
server/storage.go View File

@@ -11,16 +11,16 @@ import (
"strconv" "strconv"
"sync" "sync"


"github.com/goamz/goamz/s3"
"encoding/json" "encoding/json"
"github.com/goamz/goamz/s3"


"golang.org/x/oauth2"
"golang.org/x/net/context" "golang.org/x/net/context"
"golang.org/x/oauth2"
"golang.org/x/oauth2/google" "golang.org/x/oauth2/google"
"google.golang.org/api/drive/v3" "google.golang.org/api/drive/v3"
"google.golang.org/api/googleapi" "google.golang.org/api/googleapi"
"net/http"
"io/ioutil" "io/ioutil"
"net/http"
) )


type Storage interface { type Storage interface {
@@ -83,10 +83,10 @@ func (s *LocalStorage) Get(token string, filename string) (reader io.ReadCloser,


func (s *LocalStorage) Delete(token string, filename string) (err error) { func (s *LocalStorage) Delete(token string, filename string) (err error) {
metadata := filepath.Join(s.basedir, token, fmt.Sprintf("%s.metadata", filename)) metadata := filepath.Join(s.basedir, token, fmt.Sprintf("%s.metadata", filename))
os.Remove(metadata);
os.Remove(metadata)


path := filepath.Join(s.basedir, token, filename) path := filepath.Join(s.basedir, token, filename)
err = os.Remove(path);
err = os.Remove(path)
return return
} }


@@ -315,9 +315,9 @@ func (s *S3Storage) Put(token string, filename string, reader io.Reader, content
} }


type GDrive struct { type GDrive struct {
service *drive.Service
rootId string
basedir string
service *drive.Service
rootId string
basedir string
localConfigPath string localConfigPath string
} }


@@ -338,7 +338,7 @@ func NewGDriveStorage(clientJsonFilepath string, localConfigPath string, basedir
return nil, err return nil, err
} }


storage := &GDrive{service: srv, basedir: basedir, rootId: "", localConfigPath:localConfigPath}
storage := &GDrive{service: srv, basedir: basedir, rootId: "", localConfigPath: localConfigPath}
err = storage.setupRoot() err = storage.setupRoot()
if err != nil { if err != nil {
return nil, err return nil, err
@@ -364,8 +364,8 @@ func (s *GDrive) setupRoot() error {
} }


dir := &drive.File{ dir := &drive.File{
Name: s.basedir,
MimeType: GDriveDirectoryMimeType,
Name: s.basedir,
MimeType: GDriveDirectoryMimeType,
} }


di, err := s.service.Files.Create(dir).Fields("id").Do() di, err := s.service.Files.Create(dir).Fields("id").Do()
@@ -374,7 +374,7 @@ func (s *GDrive) setupRoot() error {
} }


s.rootId = di.Id s.rootId = di.Id
err = ioutil.WriteFile(rootFileConfig, []byte(s.rootId), os.FileMode(0600))
err = ioutil.WriteFile(rootFileConfig, []byte(s.rootId), os.FileMode(0600))
if err != nil { if err != nil {
return err return err
} }
@@ -386,7 +386,7 @@ func (s *GDrive) hasChecksum(f *drive.File) bool {
return f.Md5Checksum != "" return f.Md5Checksum != ""
} }


func (s *GDrive) list(nextPageToken string, q string) (*drive.FileList, error){
func (s *GDrive) list(nextPageToken string, q string) (*drive.FileList, error) {
return s.service.Files.List().Fields("nextPageToken, files(id, name, mimeType)").Q(q).PageToken(nextPageToken).Do() return s.service.Files.List().Fields("nextPageToken, files(id, name, mimeType)").Q(q).PageToken(nextPageToken).Do()
} }


@@ -439,7 +439,6 @@ func (s *GDrive) findId(filename string, token string) (string, error) {
l, err = s.list(l.NextPageToken, q) l, err = s.list(l.NextPageToken, q)
} }



if fileId == "" { if fileId == "" {
return "", fmt.Errorf("Cannot find file %s/%s", token, filename) return "", fmt.Errorf("Cannot find file %s/%s", token, filename)
} }
@@ -484,7 +483,6 @@ func (s *GDrive) Get(token string, filename string) (reader io.ReadCloser, conte
return return
} }



contentLength = uint64(fi.Size) contentLength = uint64(fi.Size)
contentType = fi.MimeType contentType = fi.MimeType


@@ -534,12 +532,11 @@ func (s *GDrive) Put(token string, filename string, reader io.Reader, contentTyp
return err return err
} }



if dirId == "" { if dirId == "" {
dir := &drive.File{ dir := &drive.File{
Name: token,
Parents: []string{s.rootId},
MimeType: GDriveDirectoryMimeType,
Name: token,
Parents: []string{s.rootId},
MimeType: GDriveDirectoryMimeType,
} }


di, err := s.service.Files.Create(dir).Fields("id").Do() di, err := s.service.Files.Create(dir).Fields("id").Do()
@@ -552,8 +549,8 @@ func (s *GDrive) Put(token string, filename string, reader io.Reader, contentTyp


// Instantiate empty drive file // Instantiate empty drive file
dst := &drive.File{ dst := &drive.File{
Name: filename,
Parents: []string{dirId},
Name: filename,
Parents: []string{dirId},
MimeType: contentType, MimeType: contentType,
} }


@@ -567,7 +564,6 @@ func (s *GDrive) Put(token string, filename string, reader io.Reader, contentTyp
return nil return nil
} }



// Retrieve a token, saves the token, then returns the generated client. // Retrieve a token, saves the token, then returns the generated client.
func getGDriveClient(config *oauth2.Config) *http.Client { func getGDriveClient(config *oauth2.Config) *http.Client {
tokenFile := "token.json" tokenFile := "token.json"


Loading…
Cancel
Save