89 lines
2.3 KiB
Go
89 lines
2.3 KiB
Go
package util
|
|
|
|
import (
|
|
"net/http"
|
|
"strings"
|
|
"time"
|
|
)
|
|
|
|
const (
|
|
ServiceRadio = "radio"
|
|
ServiceFiles = "files"
|
|
ServiceUpload = "upload"
|
|
ServiceGit = "git"
|
|
ServiceHome = "home"
|
|
)
|
|
|
|
// GetServiceByHost returns a service's URL depending on what type of network
|
|
// is accessed (www, i2p, tor, yggdrasil).
|
|
func GetServiceByHost(host, service string) string {
|
|
if strings.HasSuffix(host, "i2p") {
|
|
switch service {
|
|
case ServiceRadio:
|
|
return "http://radio.arav.i2p"
|
|
case ServiceFiles:
|
|
return "http://files.arav.i2p"
|
|
case ServiceUpload:
|
|
return "http://upload.arav.i2p"
|
|
case ServiceGit:
|
|
return "http://git.arav.i2p"
|
|
default:
|
|
return "http://arav.i2p"
|
|
}
|
|
} else if strings.HasPrefix(host, "[300") {
|
|
switch service {
|
|
case ServiceRadio:
|
|
return "http://[300:a98d:d6d0:8a08::e]"
|
|
case ServiceFiles:
|
|
return "http://[300:a98d:d6d0:8a08::d]"
|
|
case ServiceUpload:
|
|
return "http://[300:a98d:d6d0:8a08::c]"
|
|
case ServiceGit:
|
|
return "http://[300:a98d:d6d0:8a08::b]"
|
|
default:
|
|
return "http://[300:a98d:d6d0:8a08::f]"
|
|
}
|
|
} else if strings.HasSuffix(host, "onion") {
|
|
switch service {
|
|
case ServiceRadio:
|
|
return "http://wsmkgnmhmzqm7kyzv7jnzzafvgm7xlmlfvzhgorpapd5or2arnhuktqd.onion"
|
|
case ServiceFiles:
|
|
return "http://qf5e43nlhvnrutmikuvbdfj3cmtthokpbaxtkm6mjlslttzvtgm4fxid.onion"
|
|
case ServiceUpload:
|
|
return "http://4usftbmjpfexkr2x5xbp5ukmygpmg4fgrnx2wbifsexqctooz5hmviyd.onion"
|
|
case ServiceGit:
|
|
return "http://qqitm7qlsbbubwmjos4cqzmvkqidg34rfnbyhuydhalep33fbvh22xyd.onion"
|
|
default:
|
|
return "http://moq7aejnf4xk5k2bkaltli3ftkhusy2mbrd3pj23nrca343ku2mgk4yd.onion"
|
|
}
|
|
} else {
|
|
switch service {
|
|
case ServiceRadio:
|
|
return "https://radio.arav.su"
|
|
case ServiceFiles:
|
|
return "https://files.arav.su"
|
|
case ServiceUpload:
|
|
return "https://upload.arav.su"
|
|
case ServiceGit:
|
|
return "https://git.arav.su"
|
|
default:
|
|
return "https://arav.su"
|
|
}
|
|
}
|
|
}
|
|
|
|
// ToClientTimezone converts given time to timezone set in a
|
|
// X-Client-Timezone header. If this header is not set, then
|
|
// converts to UTC.
|
|
func ToClientTimezone(t time.Time, r *http.Request) time.Time {
|
|
if tz := r.Header.Get("X-Client-Timezone"); tz != "" {
|
|
loc, err := time.LoadLocation(tz)
|
|
if err != nil {
|
|
return t.UTC()
|
|
}
|
|
return t.In(loc)
|
|
}
|
|
|
|
return t.UTC()
|
|
}
|