Allow changing the "selif" path name
This commit is contained in:
parent
6290f408ff
commit
c746f70c10
|
@ -42,6 +42,7 @@ allowhotlink = true
|
||||||
- ```-bind 127.0.0.1:8080``` -- what to bind to (default is 127.0.0.1:8080)
|
- ```-bind 127.0.0.1:8080``` -- what to bind to (default is 127.0.0.1:8080)
|
||||||
- ```-sitename myLinx``` -- the site name displayed on top (default is inferred from Host header)
|
- ```-sitename myLinx``` -- the site name displayed on top (default is inferred from Host header)
|
||||||
- ```-siteurl "http://mylinx.example.org/"``` -- the site url (default is inferred from execution context)
|
- ```-siteurl "http://mylinx.example.org/"``` -- the site url (default is inferred from execution context)
|
||||||
|
- ```-selifpath "selif"``` -- path relative to site base url (the "selif" in https://mylinx.example.org/selif/image.jpg) where files are accessed directly (default: selif)
|
||||||
- ```-filespath files/``` -- Path to store uploads (default is files/)
|
- ```-filespath files/``` -- Path to store uploads (default is files/)
|
||||||
- ```-metapath meta/``` -- Path to store information about uploads (default is meta/)
|
- ```-metapath meta/``` -- Path to store information about uploads (default is meta/)
|
||||||
- ```-maxsize 4294967296``` -- maximum upload file size in bytes (default 4GB)
|
- ```-maxsize 4294967296``` -- maximum upload file size in bytes (default 4GB)
|
||||||
|
|
|
@ -23,6 +23,7 @@ func TestContentSecurityPolicy(t *testing.T) {
|
||||||
Config.maxSize = 1024 * 1024 * 1024
|
Config.maxSize = 1024 * 1024 * 1024
|
||||||
Config.noLogs = true
|
Config.noLogs = true
|
||||||
Config.siteName = "linx"
|
Config.siteName = "linx"
|
||||||
|
Config.selifPath = "selif"
|
||||||
Config.contentSecurityPolicy = testCSPHeaders["Content-Security-Policy"]
|
Config.contentSecurityPolicy = testCSPHeaders["Content-Security-Policy"]
|
||||||
Config.referrerPolicy = testCSPHeaders["Referrer-Policy"]
|
Config.referrerPolicy = testCSPHeaders["Referrer-Policy"]
|
||||||
Config.xFrameOptions = testCSPHeaders["X-Frame-Options"]
|
Config.xFrameOptions = testCSPHeaders["X-Frame-Options"]
|
||||||
|
|
12
server.go
12
server.go
|
@ -42,6 +42,7 @@ var Config struct {
|
||||||
siteName string
|
siteName string
|
||||||
siteURL string
|
siteURL string
|
||||||
sitePath string
|
sitePath string
|
||||||
|
selifPath string
|
||||||
certFile string
|
certFile string
|
||||||
keyFile string
|
keyFile string
|
||||||
contentSecurityPolicy string
|
contentSecurityPolicy string
|
||||||
|
@ -129,6 +130,11 @@ func setup() *web.Mux {
|
||||||
Config.sitePath = "/"
|
Config.sitePath = "/"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Config.selifPath = strings.TrimLeft(Config.selifPath, "/")
|
||||||
|
if lastChar := Config.selifPath[len(Config.selifPath)-1:]; lastChar != "/" {
|
||||||
|
Config.selifPath = Config.selifPath + "/"
|
||||||
|
}
|
||||||
|
|
||||||
metaStorageBackend = localfs.NewLocalfsBackend(Config.metaDir)
|
metaStorageBackend = localfs.NewLocalfsBackend(Config.metaDir)
|
||||||
metaBackend = metajson.NewMetaJSONBackend(metaStorageBackend)
|
metaBackend = metajson.NewMetaJSONBackend(metaStorageBackend)
|
||||||
fileBackend = localfs.NewLocalfsBackend(Config.filesDir)
|
fileBackend = localfs.NewLocalfsBackend(Config.filesDir)
|
||||||
|
@ -150,8 +156,8 @@ func setup() *web.Mux {
|
||||||
|
|
||||||
// Routing setup
|
// Routing setup
|
||||||
nameRe := regexp.MustCompile("^" + Config.sitePath + `(?P<name>[a-z0-9-\.]+)$`)
|
nameRe := regexp.MustCompile("^" + Config.sitePath + `(?P<name>[a-z0-9-\.]+)$`)
|
||||||
selifRe := regexp.MustCompile("^" + Config.sitePath + `selif/(?P<name>[a-z0-9-\.]+)$`)
|
selifRe := regexp.MustCompile("^" + Config.sitePath + Config.selifPath + `(?P<name>[a-z0-9-\.]+)$`)
|
||||||
selifIndexRe := regexp.MustCompile("^" + Config.sitePath + `selif/$`)
|
selifIndexRe := regexp.MustCompile("^" + Config.sitePath + Config.selifPath + `$`)
|
||||||
torrentRe := regexp.MustCompile("^" + Config.sitePath + `(?P<name>[a-z0-9-\.]+)/torrent$`)
|
torrentRe := regexp.MustCompile("^" + Config.sitePath + `(?P<name>[a-z0-9-\.]+)/torrent$`)
|
||||||
|
|
||||||
if Config.authFile == "" {
|
if Config.authFile == "" {
|
||||||
|
@ -211,6 +217,8 @@ func main() {
|
||||||
"name of the site")
|
"name of the site")
|
||||||
flag.StringVar(&Config.siteURL, "siteurl", "",
|
flag.StringVar(&Config.siteURL, "siteurl", "",
|
||||||
"site base url (including trailing slash)")
|
"site base url (including trailing slash)")
|
||||||
|
flag.StringVar(&Config.selifPath, "selifpath", "selif",
|
||||||
|
"path relative to site base url where files are accessed directly")
|
||||||
flag.Int64Var(&Config.maxSize, "maxsize", 4*1024*1024*1024,
|
flag.Int64Var(&Config.maxSize, "maxsize", 4*1024*1024*1024,
|
||||||
"maximum upload file size in bytes (default 4GB)")
|
"maximum upload file size in bytes (default 4GB)")
|
||||||
flag.Uint64Var(&Config.maxExpiry, "maxexpiry", 0,
|
flag.Uint64Var(&Config.maxExpiry, "maxexpiry", 0,
|
||||||
|
|
|
@ -173,7 +173,7 @@ func TestFileNotFound(t *testing.T) {
|
||||||
|
|
||||||
filename := generateBarename()
|
filename := generateBarename()
|
||||||
|
|
||||||
req, err := http.NewRequest("GET", "/selif/"+filename, nil)
|
req, err := http.NewRequest("GET", "/"+Config.selifPath+filename, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -941,7 +941,7 @@ func TestPutAndOverwrite(t *testing.T) {
|
||||||
|
|
||||||
// Make sure it's the new file
|
// Make sure it's the new file
|
||||||
w = httptest.NewRecorder()
|
w = httptest.NewRecorder()
|
||||||
req, err = http.NewRequest("GET", "/selif/"+myjson.Filename, nil)
|
req, err = http.NewRequest("GET", "/"+Config.selifPath+myjson.Filename, nil)
|
||||||
mux.ServeHTTP(w, req)
|
mux.ServeHTTP(w, req)
|
||||||
|
|
||||||
if w.Code == 404 {
|
if w.Code == 404 {
|
||||||
|
|
|
@ -83,6 +83,7 @@ func renderTemplate(tpl *pongo2.Template, context pongo2.Context, r *http.Reques
|
||||||
}
|
}
|
||||||
|
|
||||||
context["sitepath"] = Config.sitePath
|
context["sitepath"] = Config.sitePath
|
||||||
|
context["selifpath"] = Config.selifPath
|
||||||
context["using_auth"] = Config.authFile != ""
|
context["using_auth"] = Config.authFile != ""
|
||||||
|
|
||||||
return tpl.ExecuteWriter(context, writer)
|
return tpl.ExecuteWriter(context, writer)
|
||||||
|
|
|
@ -2,8 +2,8 @@
|
||||||
|
|
||||||
{% block main %}
|
{% block main %}
|
||||||
<audio class="display-audio" controls preload='auto'>
|
<audio class="display-audio" controls preload='auto'>
|
||||||
<source src='{{ sitepath }}selif/{{ filename }}'>
|
<source src='{{ sitepath }}{{ selifpath }}{{ filename }}'>
|
||||||
<a href='{{ sitepath }}selif/{{ filename }}'>Download it instead</a>
|
<a href='{{ sitepath }}{{ selifpath }}{{ filename }}'>Download it instead</a>
|
||||||
</audio>
|
</audio>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
{% block infomore %}{% endblock %}
|
{% block infomore %}{% endblock %}
|
||||||
<span>{{ size }}</span> |
|
<span>{{ size }}</span> |
|
||||||
<a href="{{ filename }}/torrent" download>torrent</a> |
|
<a href="{{ filename }}/torrent" download>torrent</a> |
|
||||||
<a href="{{ sitepath }}selif/{{ filename }}" download>get</a>
|
<a href="{{ sitepath }}{{ selifpath }}{{ filename }}" download>get</a>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{% block infoleft %}{% endblock %}
|
{% block infoleft %}{% endblock %}
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
{% block main %}
|
{% block main %}
|
||||||
<div class="normal display-file">
|
<div class="normal display-file">
|
||||||
<p class="center">You are requesting <a href="{{ sitepath }}selif/{{ filename }}">{{ filename }}</a>, <a href="{{ sitepath }}selif/{{ filename }}">click here</a> to download.</p>
|
<p class="center">You are requesting <a href="{{ sitepath }}{{ selifpath }}{{ filename }}">{{ filename }}</a>, <a href="{{ sitepath }}{{ selifpath }}{{ filename }}">click here</a> to download.</p>
|
||||||
|
|
||||||
{% if files|length > 0 %}
|
{% if files|length > 0 %}
|
||||||
<p>Contents of the archive:</p>
|
<p>Contents of the archive:</p>
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
{% extends "base.html" %}
|
{% extends "base.html" %}
|
||||||
|
|
||||||
{% block main %}
|
{% block main %}
|
||||||
<a href="{{ sitepath }}selif/{{ filename }}">
|
<a href="{{ sitepath }}{{ selifpath }}{{ filename }}">
|
||||||
<img class="display-image" src="{{ sitepath }}selif/{{ filename }}" />
|
<img class="display-image" src="{{ sitepath }}{{ selifpath }}{{ filename }}" />
|
||||||
</a>
|
</a>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
{% extends "base.html" %}
|
{% extends "base.html" %}
|
||||||
|
|
||||||
{% block main %}
|
{% block main %}
|
||||||
<object class="display-pdf" data="{{ sitepath }}selif/{{ filename }}" type="application/pdf">
|
<object class="display-pdf" data="{{ sitepath }}{{ selifpath }}{{ filename }}" type="application/pdf">
|
||||||
|
|
||||||
<p>It appears your Web browser is not configured to display PDF files.
|
<p>It appears your Web browser is not configured to display PDF files.
|
||||||
No worries, just <a href="{{ sitepath }}selif/{{ filename }}">click here to download the PDF file.</a></p>
|
No worries, just <a href="{{ sitepath }}{{ selifpath }}{{ filename }}">click here to download the PDF file.</a></p>
|
||||||
|
|
||||||
</object>
|
</object>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
{% block main %}
|
{% block main %}
|
||||||
<video class="display-video" controls autoplay>
|
<video class="display-video" controls autoplay>
|
||||||
<source src="{{ sitepath }}selif/{{ filename }}"/>
|
<source src="{{ sitepath }}{{ selifpath }}{{ filename }}"/>
|
||||||
<a href='{{ sitepath }}selif/{{ filename }}'>Download it instead</a>
|
<a href='{{ sitepath }}{{ selifpath }}{{ filename }}'>Download it instead</a>
|
||||||
</video>
|
</video>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
|
@ -45,7 +45,7 @@ func createTorrent(fileName string, f io.ReadCloser, r *http.Request) ([]byte, e
|
||||||
PieceLength: TORRENT_PIECE_LENGTH,
|
PieceLength: TORRENT_PIECE_LENGTH,
|
||||||
Name: fileName,
|
Name: fileName,
|
||||||
},
|
},
|
||||||
UrlList: []string{fmt.Sprintf("%sselif/%s", getSiteURL(r), fileName)},
|
UrlList: []string{fmt.Sprintf("%s%s%s", getSiteURL(r), Config.selifPath, fileName)},
|
||||||
}
|
}
|
||||||
|
|
||||||
for {
|
for {
|
||||||
|
|
|
@ -45,7 +45,7 @@ func TestCreateTorrent(t *testing.T) {
|
||||||
t.Fatal("Length was less than or equal to 0, expected more")
|
t.Fatal("Length was less than or equal to 0, expected more")
|
||||||
}
|
}
|
||||||
|
|
||||||
tracker := fmt.Sprintf("%sselif/%s", Config.siteURL, fileName)
|
tracker := fmt.Sprintf("%s%s%s", Config.siteURL, Config.selifPath, fileName)
|
||||||
if decoded.UrlList[0] != tracker {
|
if decoded.UrlList[0] != tracker {
|
||||||
t.Fatalf("First entry in URL list was %s, expected %s", decoded.UrlList[0], tracker)
|
t.Fatalf("First entry in URL list was %s, expected %s", decoded.UrlList[0], tracker)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue