A share link from s3d only opened where s3d is reachable, which on a default setup is this computer. Pithos now makes a Sia shared-object URL for the file the way the Sia SDK does (the indexer's sealed object, its data key opened with a key derived from s3d's app key) and registers it at navigate.st, which streams the file from Sia hosts for anyone, with seeking, even with this computer off. A shared-object URL reads that one object and nothing else in the account. Files still waiting on this computer are uploaded first. A folder gets a page with its files and a player. Settings lists the links, each one can be switched off. sia-share is the navigate.st side, in Go on the Sia SDK: it keeps short ids, checks every URL against an allowed indexer, serves files sandboxed so a shared page cannot run script on navigate.st, and caps sign-ups per address and downloads per link per day. Host reads are paid by its own app on Silent Mode's indexer account.
37 lines
1.2 KiB
Go
37 lines
1.2 KiB
Go
package main
|
|
|
|
import "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)
|
|
}
|
|
}
|
|
}
|