2023-02-05 04:41:52 +04:00
|
|
|
package util
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
2023-02-05 06:22:28 +04:00
|
|
|
"strings"
|
2023-02-05 04:41:52 +04:00
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
2023-02-05 06:25:38 +04:00
|
|
|
const (
|
|
|
|
ServiceRadio = "radio"
|
|
|
|
ServiceFiles = "files"
|
|
|
|
ServiceUpload = "upload"
|
|
|
|
ServiceGit = "git"
|
|
|
|
ServiceHome = "home"
|
|
|
|
)
|
|
|
|
|
2023-02-05 06:22:28 +04:00
|
|
|
// GetServiceByHost returns a service's URL depending on what type of network
|
|
|
|
// is accessed (www, i2p, yggdrasil).
|
|
|
|
func GetServiceByHost(host, service string) string {
|
|
|
|
if strings.HasSuffix(host, "i2p") {
|
|
|
|
switch service {
|
2024-04-20 05:06:28 +04:00
|
|
|
case ServiceRadio:
|
2023-02-05 06:22:28 +04:00
|
|
|
return "http://radio.arav.i2p"
|
2024-04-20 05:06:28 +04:00
|
|
|
case ServiceFiles:
|
2023-02-05 06:22:28 +04:00
|
|
|
return "http://files.arav.i2p"
|
2024-04-20 05:06:28 +04:00
|
|
|
case ServiceUpload:
|
2023-02-05 06:22:28 +04:00
|
|
|
return "http://upload.arav.i2p"
|
2024-04-20 05:06:28 +04:00
|
|
|
case ServiceGit:
|
2023-02-05 06:22:28 +04:00
|
|
|
return "http://git.arav.i2p"
|
|
|
|
default:
|
|
|
|
return "http://arav.i2p"
|
|
|
|
}
|
|
|
|
} else if strings.HasPrefix(host, "[300") {
|
|
|
|
switch service {
|
2024-04-20 05:06:28 +04:00
|
|
|
case ServiceRadio:
|
2023-02-05 06:22:28 +04:00
|
|
|
return "http://[300:a98d:d6d0:8a08::e]"
|
2024-04-20 05:06:28 +04:00
|
|
|
case ServiceFiles:
|
2023-02-05 06:22:28 +04:00
|
|
|
return "http://[300:a98d:d6d0:8a08::d]"
|
2024-04-20 05:06:28 +04:00
|
|
|
case ServiceUpload:
|
2023-02-05 06:22:28 +04:00
|
|
|
return "http://[300:a98d:d6d0:8a08::c]"
|
2024-04-20 05:06:28 +04:00
|
|
|
case ServiceGit:
|
2023-02-05 06:22:28 +04:00
|
|
|
return "http://[300:a98d:d6d0:8a08::b]"
|
|
|
|
default:
|
|
|
|
return "http://[300:a98d:d6d0:8a08::f]"
|
|
|
|
}
|
2023-06-26 04:07:50 +04:00
|
|
|
} else if strings.HasSuffix(host, "onion") {
|
|
|
|
switch service {
|
2024-04-20 05:06:28 +04:00
|
|
|
case ServiceRadio:
|
2023-06-26 04:07:50 +04:00
|
|
|
return "http://wsmkgnmhmzqm7kyzv7jnzzafvgm7xlmlfvzhgorpapd5or2arnhuktqd.onion"
|
2024-04-20 05:06:28 +04:00
|
|
|
case ServiceFiles:
|
2023-06-26 04:07:50 +04:00
|
|
|
return "http://qf5e43nlhvnrutmikuvbdfj3cmtthokpbaxtkm6mjlslttzvtgm4fxid.onion"
|
2024-04-20 05:06:28 +04:00
|
|
|
case ServiceUpload:
|
2023-06-26 04:07:50 +04:00
|
|
|
return "http://4usftbmjpfexkr2x5xbp5ukmygpmg4fgrnx2wbifsexqctooz5hmviyd.onion"
|
2024-04-20 05:06:28 +04:00
|
|
|
case ServiceGit:
|
2023-06-26 04:07:50 +04:00
|
|
|
return "http://qqitm7qlsbbubwmjos4cqzmvkqidg34rfnbyhuydhalep33fbvh22xyd.onion"
|
|
|
|
default:
|
|
|
|
return "http://moq7aejnf4xk5k2bkaltli3ftkhusy2mbrd3pj23nrca343ku2mgk4yd.onion"
|
|
|
|
}
|
2023-02-05 06:22:28 +04:00
|
|
|
} else {
|
|
|
|
switch service {
|
2024-04-20 05:06:28 +04:00
|
|
|
case ServiceRadio:
|
2023-03-11 22:45:22 +04:00
|
|
|
return "https://radio.arav.su"
|
2024-04-20 05:06:28 +04:00
|
|
|
case ServiceFiles:
|
2023-03-11 22:45:22 +04:00
|
|
|
return "https://files.arav.su"
|
2024-04-20 05:06:28 +04:00
|
|
|
case ServiceUpload:
|
2023-03-11 22:45:22 +04:00
|
|
|
return "https://upload.arav.su"
|
2024-04-20 05:06:28 +04:00
|
|
|
case ServiceGit:
|
2023-03-11 22:45:22 +04:00
|
|
|
return "https://git.arav.su"
|
2023-02-05 06:22:28 +04:00
|
|
|
default:
|
2023-03-11 22:45:22 +04:00
|
|
|
return "https://arav.su"
|
2023-02-05 06:22:28 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-05 04:41:52 +04:00
|
|
|
// 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()
|
|
|
|
}
|