Skip to content

Commit

Permalink
Merge pull request #160 from root-gg/1.2-rc2
Browse files Browse the repository at this point in the history
1.2 rc2
  • Loading branch information
bodji authored Jun 19, 2016
2 parents ea9851a + 30703b5 commit f3169c6
Show file tree
Hide file tree
Showing 16 changed files with 203 additions and 114 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
# THE SOFTWARE.
###

RELEASE_VERSION="1.2-RC1"
RELEASE_VERSION="1.2-RC2"
RELEASE_DIR="release/plik-$(RELEASE_VERSION)"
RELEASE_TARGETS=darwin-386 darwin-amd64 freebsd-386 \
freebsd-amd64 linux-386 linux-amd64 linux-arm openbsd-386 \
Expand Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

# Plik

Plik is an simple and powerful file uploading system written in golang.
Plik is a scalable & friendly temporary file upload system ( wetransfer like ) in golang.

### Main features
- Multiple data backends : File, OpenStack Swift, WeedFS
Expand All @@ -21,7 +21,7 @@ Plik is an simple and powerful file uploading system written in golang.
- Upload restriction : Source IP / Token

### Version
1.2-RC1
1.2-RC2

### Installation

Expand Down Expand Up @@ -295,4 +295,5 @@ The screenshot is then removed of your home directory to avoid garbage.

Contributions are welcome, feel free to open issues and/or submit pull requests.
Please make your pull requests against the current development (RC) branch, not against master.
Please run/update the test suite using the makefile test target.
Please run/update the test suite using the makefile test target.

21 changes: 15 additions & 6 deletions client/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,16 @@ func Load() (err error) {
// Stat file
_, err = os.Stat(configFile)
if err != nil {
// File not present. Ask for domain
// File not found.

// Check if quiet mode ( you'll have to pass --server flag )
for _, arg := range os.Args[1:] {
if arg == "-q" || arg == "--quiet" {
return
}
}

// Ask for domain
var domain string
fmt.Printf("Please enter your plik domain [default:http://127.0.0.1:8080] : ")
_, err := fmt.Scanf("%s", &domain)
Expand Down Expand Up @@ -315,11 +324,11 @@ func UnmarshalArgs(arguments map[string]interface{}) (err error) {
// Configure the archive backend
archiveBackend, err = archive.NewArchiveBackend(Config.ArchiveMethod, Config.ArchiveOptions)
if err != nil {
return fmt.Errorf("Invalid archive params : %s\n", err)
return fmt.Errorf("Invalid archive params : %s", err)
}
err = archiveBackend.Configure(arguments)
if err != nil {
return fmt.Errorf("Invalid archive params : %s\n", err)
return fmt.Errorf("Invalid archive params : %s", err)
}
Debug("Archive backend configuration : " + utils.Sdump(archiveBackend.GetConfiguration()))

Expand Down Expand Up @@ -380,7 +389,7 @@ func UnmarshalArgs(arguments map[string]interface{}) (err error) {
}
ttl, err := strconv.Atoi(ttlStr)
if err != nil {
return fmt.Errorf("Invalid TTL %s", arguments["--ttl"].(string))
return fmt.Errorf("Invalid TTL %s\n", arguments["--ttl"].(string))
}
Upload.TTL = ttl * mul
}
Expand All @@ -397,11 +406,11 @@ func UnmarshalArgs(arguments map[string]interface{}) (err error) {
// Configure crypto backend
cryptoBackend, err = crypto.NewCryptoBackend(secureMethod, Config.SecureOptions)
if err != nil {
return fmt.Errorf("Invalid secure params : %s\n", err)
return fmt.Errorf("Invalid secure params : %s", err)
}
err = cryptoBackend.Configure(arguments)
if err != nil {
return fmt.Errorf("Invalid secure params : %s\n", err)
return fmt.Errorf("Invalid secure params : %s", err)
}

Debug("Crypto backend configuration : " + utils.Sdump(cryptoBackend.GetConfiguration()))
Expand Down
7 changes: 6 additions & 1 deletion client/plik.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ Options:
// Unmarshal arguments in configuration
err = config.UnmarshalArgs(arguments)
if err != nil {
fmt.Printf("%s", err)
fmt.Printf("%s\n", err)
os.Exit(1)
}

Expand Down Expand Up @@ -477,6 +477,11 @@ func updateClient(updateFlag bool) (err error) {
}

resp, err := makeRequest(req)
if err != nil {
err = fmt.Errorf("Unable to get server version : %s", err)
return
}

defer resp.Body.Close()

if resp.StatusCode == 200 {
Expand Down
78 changes: 60 additions & 18 deletions client/plik.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,28 +38,47 @@ function setTtl() {
## Vars
#
PLIK_URL=${PLIK_URL-"http://127.0.0.1:8080"}
PASSPHRASE=""
PLIK_TOKEN=${PLIK_TOKEN-""}
QUIET=false
SECURE=false
PASSPHRASE=""
ARCHIVE=false
ONESHOT=false
REMOVABLE=false
TTL=0

#
## Read ~/.plikrc file
#

PLIKRC=${PLIKRC-"$HOME/.plikrc"}
if [ -e "$PLIKRC" ]; then
URL=$(grep URL $PLIKRC | grep -Po '(http[^\"]*)')
if [ "$URL" != "" ]; then
PLIK_URL=$URL
fi
TOKEN=$(grep Token $PLIKRC | sed -n 's/^.*"\(.*\)".*$/\1/p' )
if [ "$TOKEN" != "" ]; then
PLIK_TOKEN=$TOKEN
fi
fi

#
## Parse arguments
#
declare -a files

declare -a files
while [ $# -gt 0 ] ; do
case "$1" in
-q) QUIET=true ; shift ;;
-s) SECURE=true ; shift ;;
-a) ARCHIVE=true ; shift ;;
-u) shift ; PLIK_URL="$1" ; shift ;;
-T) shift ; PLIK_TOKEN="$1" ; shift ;;
-o) ONESHOT=true ; shift ;;
-r) REMOVABLE=true ; shift ;;
-t) shift ; setTtl $1 ; shift ;;
-a) ARCHIVE=true ; shift ;;
-s) SECURE=true ; shift ;;
-p) SECURE=true ; shift ; PASSPHRASE="$1" ; shift ;;
-q) QUIET=true ; shift ;;
--) shift ;;
-*) qecho "bad option '$1'" ; exit 1 ;;
*) files=("${files[@]}" "$1") ; shift ;;
Expand All @@ -70,26 +89,37 @@ if [ "${#files[@]}" == 0 ]; then
qecho "No files specified !"
exit 1
fi
if [ -e "$HOME/.plikrc" ]; then
URL=$(grep URL ~/.plikrc | grep -Po '(http[^\"]*)')

if [ "$URL" != "" ]; then
PLIK_URL=$URL
fi
fi


#
## Create new upload
#

qecho -e "Creating upload on $PLIK_URL...\n"
if [ "$PLIK_TOKEN" != "" ]; then
AUTH_TOKEN_HEADER="-H \"X-PlikToken: $PLIK_TOKEN\""
fi

OPTIONS="{ \"OneShot\" : $ONESHOT, \"Removable\" : $REMOVABLE, \"Ttl\" : $TTL }"
NEW_UPLOAD_RESP=$(curl -s -X POST -d "$OPTIONS" ${PLIK_URL}/upload)
qecho -e "Create new upload on $PLIK_URL...\n"

CREATE_UPLOAD_CMD="curl -s -X POST $AUTH_TOKEN_HEADER -d '$OPTIONS' ${PLIK_URL}/upload"
NEW_UPLOAD_RESP=$(eval $CREATE_UPLOAD_CMD)
UPLOAD_ID=$(echo $NEW_UPLOAD_RESP | jsonValue id)

# Handle error
if [ "$UPLOAD_ID" == "" ]; then
ERROR_MSG=$(echo $NEW_UPLOAD_RESP | jsonValue message)
if [ "$ERROR_MSG" != "" ]; then
echo $ERROR_MSG
elif [ "$NEW_UPLOAD_RESP" != "" ]; then
echo $NEW_UPLOAD_RESP
fi
exit 1
fi

UPLOAD_TOKEN=$(echo $NEW_UPLOAD_RESP | jsonValue uploadToken)
qecho -e " --> ${green}$PLIK_URL/#/?id=$UPLOAD_ID${endColor}\n"
UPLOAD_TOKEN_HEADER="-H \"X-UploadToken: $UPLOAD_TOKEN\""

qecho -e " --> ${green}$PLIK_URL/#/?id=$UPLOAD_ID${endColor}\n"

#
## Test if we have to archive
Expand Down Expand Up @@ -154,13 +184,25 @@ do
fi

if [ "$STDIN" == true ]; then
UPLOAD_COMMAND+="curl -s -X POST --header \"X-UploadToken: $UPLOAD_TOKEN\" -F \"file=@-;filename=$FILENAME\" $PLIK_URL/file/$UPLOAD_ID"
UPLOAD_COMMAND+="curl -s -X POST $AUTH_TOKEN_HEADER $UPLOAD_TOKEN_HEADER -F \"file=@-;filename=$FILENAME\" $PLIK_URL/file/$UPLOAD_ID"
else
UPLOAD_COMMAND+="curl -s -X POST --header \"X-UploadToken: $UPLOAD_TOKEN\" -F \"file=@$FILE;filename=$FILENAME\" $PLIK_URL/file/$UPLOAD_ID"
UPLOAD_COMMAND+="curl -s -X POST $AUTH_TOKEN_HEADER $UPLOAD_TOKEN_HEADER -F \"file=@$FILE;filename=$FILENAME\" $PLIK_URL/file/$UPLOAD_ID"
fi

FILE_RESP=$(eval $UPLOAD_COMMAND)
FILE_ID=$(echo $FILE_RESP | jsonValue id)

# Handle error
if [ "$FILE_ID" == "" ]; then
ERROR_MSG=$(echo $FILE_RESP | jsonValue message)
if [ "$ERROR_MSG" != "" ]; then
echo $ERROR_MSG
elif [ "$FILE_RESP" != "" ]; then
echo $FILE_RESP
fi
exit 1
fi

FILE_MD5=$(echo $FILE_RESP | jsonValue fileMd5)
FILE_NAME=$(echo $FILE_RESP | jsonValue fileName)
FILE_STATUS=$(echo $FILE_RESP | jsonValue status)
Expand Down
20 changes: 20 additions & 0 deletions client/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,26 @@ grep "$URL/file/.*/.*/FILE1" $CLIENT_LOG >/dev/null 2>/dev/null

echo "OK"

#---------------------------------------------

echo -n " - quiet and no .plikrc : "

before
rm $PLIKRC
cp $SPECIMEN $TMPDIR/upload/FILE1
upload -q
test $(cat $CLIENT_LOG | wc -l) -eq 1
grep "$URL/file/.*/.*/FILE1" $CLIENT_LOG >/dev/null 2>/dev/null

before
rm $PLIKRC
cp $SPECIMEN $TMPDIR/upload/FILE1
upload --quiet
test $(cat $CLIENT_LOG | wc -l) -eq 1
grep "$URL/file/.*/.*/FILE1" $CLIENT_LOG >/dev/null 2>/dev/null

echo "OK"

###
# Tar archive
###
Expand Down
3 changes: 2 additions & 1 deletion server/Godeps/Godeps.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

This file was deleted.

2 changes: 1 addition & 1 deletion server/handlers/getFile.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func GetFile(ctx *juliet.Context, resp http.ResponseWriter, req *http.Request) {
// If upload has OneShot option, test if file has not been already downloaded once
if upload.OneShot && file.Status == "downloaded" {
log.Warningf("File %s has already been downloaded", file.Name)
common.Fail(ctx, req, resp, "File %s has already been downloaded", 404)
common.Fail(ctx, req, resp, fmt.Sprintf("File %s has already been downloaded", file.Name), 404)
return
}

Expand Down
Loading

0 comments on commit f3169c6

Please sign in to comment.