-
Notifications
You must be signed in to change notification settings - Fork 0
/
path.go
36 lines (31 loc) · 788 Bytes
/
path.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package main
import (
"fmt"
"net/url"
"os"
"path/filepath"
"strings"
)
func getProperAvailableFilepath(path string) string {
filepathExtension := filepath.Ext(path)
filepathBase := strings.TrimSuffix(path, filepathExtension)
properAvailableFilepath := path
curRevision := 1
for true {
if _, err := os.Stat(properAvailableFilepath); err != nil {
break
}
properAvailableFilepath = fmt.Sprintf("%s-%d%s", filepathBase, curRevision, filepathExtension)
curRevision++
}
return properAvailableFilepath
}
func filepathToDownloadUrl(path string) (string, error) {
return url.JoinPath(getFullHostname(), strings.TrimPrefix(path, UPLOADS_DIR))
}
func getFullHostname() string {
if PORT == 80 || PORT == 443 {
return HOST
}
return fmt.Sprintf("%s:%d", HOST, PORT)
}