Share used to copy the link straight away, leaving no way to send it anywhere. It now opens a menu with the link and Copy, Open, X, Telegram and WhatsApp, plus the link options. The ⋯ menu's "Copy public link" still copies in one step. A person opening a single-file link in a browser used to get the bare file, with nothing saying where it came from. Browser visits now get a page with a preview, Download and Open, and links to pithos.sia, the Pithos app and Theseus Navigator; folder pages carry the same links. Players, embeds and download tools still get the file itself (?raw, ?dl, or any request that is not a page navigation).
67 lines
1.9 KiB
Go
67 lines
1.9 KiB
Go
package main
|
|
|
|
import (
|
|
"net/http/httptest"
|
|
"testing"
|
|
)
|
|
|
|
func TestParseRange(t *testing.T) {
|
|
cases := []struct {
|
|
hdr string
|
|
size, off, length int64
|
|
partial, ok bool
|
|
}{
|
|
{"", 100, 0, 100, false, true},
|
|
{"bytes=0-9", 100, 0, 10, true, true},
|
|
{"bytes=90-", 100, 90, 10, true, true},
|
|
{"bytes=-5", 100, 95, 5, true, true},
|
|
{"bytes=-500", 100, 0, 100, true, true},
|
|
{"bytes=50-1000", 100, 50, 50, true, true},
|
|
{"bytes=100-", 100, 0, 0, false, false},
|
|
{"bytes=9-3", 100, 0, 0, false, false},
|
|
{"bytes=0-1,5-6", 100, 0, 100, false, true}, // multi-range: whole file
|
|
}
|
|
for _, c := range cases {
|
|
off, length, partial, ok := parseRange(c.hdr, c.size)
|
|
if ok != c.ok || (ok && (off != c.off || length != c.length || partial != c.partial)) {
|
|
t.Errorf("%q/%d: got %d,%d,%v,%v want %d,%d,%v,%v", c.hdr, c.size, off, length, partial, ok, c.off, c.length, c.partial, c.ok)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestCleanName(t *testing.T) {
|
|
for in, want := range map[string]string{
|
|
"song.mp3": "song.mp3", "a/b/c.txt": "c.txt", `..\..\x.png`: "x.png", "..": "", "": "", " photo.jpg ": "photo.jpg",
|
|
} {
|
|
if got := cleanName(in); got != want {
|
|
t.Errorf("cleanName(%q) = %q, want %q", in, got, want)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestWantsPage(t *testing.T) {
|
|
cases := []struct {
|
|
url, dest, accept string
|
|
want bool
|
|
}{
|
|
{"/sia/x", "document", "", true},
|
|
{"/sia/x", "image", "", false},
|
|
{"/sia/x", "iframe", "", false},
|
|
{"/sia/x?raw=1", "document", "", false},
|
|
{"/sia/x?dl=1", "document", "", false},
|
|
{"/sia/x", "", "text/html,application/xhtml+xml", true},
|
|
{"/sia/x", "", "*/*", false},
|
|
}
|
|
for _, c := range cases {
|
|
r := httptest.NewRequest("GET", c.url, nil)
|
|
if c.dest != "" {
|
|
r.Header.Set("Sec-Fetch-Dest", c.dest)
|
|
}
|
|
if c.accept != "" {
|
|
r.Header.Set("Accept", c.accept)
|
|
}
|
|
if got := wantsPage(r); got != c.want {
|
|
t.Errorf("%s dest=%q accept=%q: got %v want %v", c.url, c.dest, c.accept, got, c.want)
|
|
}
|
|
}
|
|
}
|