feat(web): Support redirecting to custom url for index page
This commit is contained in:
parent
d27348ca0b
commit
15bf56a1e7
3 changed files with 15 additions and 1 deletions
|
@ -1,13 +1,19 @@
|
||||||
username = ""
|
username = ""
|
||||||
password = "asd123"
|
password = "asd123"
|
||||||
#proxyaddr = "socks5://localhost:5555"
|
#proxyaddr = "socks5://localhost:5555"
|
||||||
hostURL = "https://my.domain.tld"
|
|
||||||
|
#usewebserver = false
|
||||||
|
indextarget = "https://discord.gg/Kw4MFGxYEj" # Optional
|
||||||
|
hostURL = "https://my.domain.tld" # Can be omitted if not using webserver
|
||||||
|
|
||||||
webhook = "https://domain.tld/api/webhooks/"
|
webhook = "https://domain.tld/api/webhooks/"
|
||||||
|
|
||||||
channels = [
|
channels = [
|
||||||
"NinEverything",
|
"NinEverything",
|
||||||
"NintendoEurope",
|
"NintendoEurope",
|
||||||
"NintendoAmerica",
|
"NintendoAmerica",
|
||||||
]
|
]
|
||||||
|
|
||||||
# Binary representation for efficient filtering
|
# Binary representation for efficient filtering
|
||||||
# Bit from left to right (most to least significant bit): IsSelfThread, IsRetweet, IsReply, IsPin, IsQuoted
|
# Bit from left to right (most to least significant bit): IsSelfThread, IsRetweet, IsReply, IsPin, IsQuoted
|
||||||
filter = [
|
filter = [
|
||||||
|
|
|
@ -20,6 +20,7 @@ type Config struct {
|
||||||
WebPort uint16
|
WebPort uint16
|
||||||
UserAgents []string
|
UserAgents []string
|
||||||
NitterBase string
|
NitterBase string
|
||||||
|
IndexTarget string
|
||||||
}
|
}
|
||||||
|
|
||||||
func ConfigFromFile(filePath string) (*Config, error) {
|
func ConfigFromFile(filePath string) (*Config, error) {
|
||||||
|
|
|
@ -72,12 +72,19 @@ func New(config *config.Config, scraper *ts.Scraper) (*WebServer, error) {
|
||||||
WriteTimeout: 30 * time.Second,
|
WriteTimeout: 30 * time.Second,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
sm.HandleFunc("GET /", ws.handleIndex)
|
||||||
sm.HandleFunc("GET /avatar/{username}", ws.handleAvatar)
|
sm.HandleFunc("GET /avatar/{username}", ws.handleAvatar)
|
||||||
sm.HandleFunc("GET /tweet/{id}", ws.handleTweet)
|
sm.HandleFunc("GET /tweet/{id}", ws.handleTweet)
|
||||||
sm.HandleFunc("GET /video/{id}", ws.handleVideo)
|
sm.HandleFunc("GET /video/{id}", ws.handleVideo)
|
||||||
return ws, nil
|
return ws, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (ws WebServer) handleIndex(w http.ResponseWriter, r *http.Request) {
|
||||||
|
if ws.config.IndexTarget != "" {
|
||||||
|
http.Redirect(w, r, ws.config.IndexTarget, http.StatusPermanentRedirect)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (ws WebServer) handleAvatar(w http.ResponseWriter, r *http.Request) {
|
func (ws WebServer) handleAvatar(w http.ResponseWriter, r *http.Request) {
|
||||||
username := r.PathValue("username")
|
username := r.PathValue("username")
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue