Skip to content

Commit

Permalink
Overwrite support, Fixes #5
Browse files Browse the repository at this point in the history
  • Loading branch information
andreimarcu committed Oct 27, 2015
1 parent 70d75d4 commit b305b0f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Options
- ```-r``` -- Randomize filename
- ```-e 600``` -- Time until file expires in seconds
- ```-deletekey mysecret``` -- Specify deletion key

- ```-o``` -- Overwrite file if you have its deletion key

#### Delete file(s)

Expand Down
16 changes: 14 additions & 2 deletions linx.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ func main() {

var del bool
var randomize bool
var overwrite bool
var expiry int64
var deleteKey string

Expand All @@ -56,6 +57,8 @@ func main() {
"Time in seconds until file expires (ex: -e 600)")
flag.StringVar(&deleteKey, "deletekey", "",
"Specify your own delete key for the upload(s) (ex: -deletekey mysecret)")
flag.BoolVar(&overwrite, "o", false,
"Overwrite file (assuming you have its delete key")
flag.Parse()

if del {
Expand All @@ -64,12 +67,12 @@ func main() {
}
} else {
for _, fileName := range flag.Args() {
upload(fileName, deleteKey, randomize, expiry)
upload(fileName, deleteKey, randomize, expiry, overwrite)
}
}
}

func upload(filePath string, deleteKey string, randomize bool, expiry int64) {
func upload(filePath string, deleteKey string, randomize bool, expiry int64, overwrite bool) {
fileInfo, err := os.Stat(filePath)
checkErr(err)
file, err := os.Open(filePath)
Expand Down Expand Up @@ -98,6 +101,15 @@ func upload(filePath string, deleteKey string, randomize bool, expiry int64) {
if expiry != 0 {
req.Header.Set("Linx-Expiry", strconv.FormatInt(expiry, 10))
}
if overwrite {
fileUrl := Config.siteurl + fileName
deleteKey, exists := keys[fileUrl]
if !exists {
checkErr(errors.New("No delete key for " + fileUrl))
}

req.Header.Set("Linx-Delete-Key", deleteKey)
}

client := &http.Client{}
resp, err := client.Do(req)
Expand Down

0 comments on commit b305b0f

Please sign in to comment.