Skip to content

Commit

Permalink
feat: add robots.txt setting (close #4303)
Browse files Browse the repository at this point in the history
  • Loading branch information
xhofe committed May 12, 2023
1 parent ddc19ab commit 5be79eb
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions internal/bootstrap/data/setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ func InitialSettings() []model.SettingItem {
{Key: "default_page_size", Value: "30", Type: conf.TypeNumber, Group: model.SITE},
{Key: conf.AllowIndexed, Value: "false", Type: conf.TypeBool, Group: model.SITE},
{Key: conf.AllowMounted, Value: "true", Type: conf.TypeBool, Group: model.SITE},
{Key: conf.RobotsTxt, Value: "User-agent: *\nAllow: /", Type: conf.TypeText, Group: model.SITE},
// style settings
{Key: conf.Logo, Value: "https://cdn.jsdelivr.net/gh/alist-org/logo@main/logo.svg", Type: conf.TypeText, Group: model.STYLE},
{Key: conf.Favicon, Value: "https://cdn.jsdelivr.net/gh/alist-org/logo@main/logo.svg", Type: conf.TypeString, Group: model.STYLE},
Expand Down
1 change: 1 addition & 0 deletions internal/conf/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const (
Announcement = "announcement"
AllowIndexed = "allow_indexed"
AllowMounted = "allow_mounted"
RobotsTxt = "robots_txt"

Logo = "logo"
Favicon = "favicon"
Expand Down
4 changes: 4 additions & 0 deletions server/handles/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ func Favicon(c *gin.Context) {
c.Redirect(302, setting.GetStr(conf.Favicon))
}

func Robots(c *gin.Context) {
c.String(200, setting.GetStr(conf.RobotsTxt))
}

func Plist(c *gin.Context) {
linkNameB64 := strings.TrimSuffix(c.Param("link_name"), ".plist")
linkName, err := utils.SafeAtob(linkNameB64)
Expand Down
5 changes: 3 additions & 2 deletions server/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,16 @@ func Init(e *gin.Engine) {
g.Any("/ping", func(c *gin.Context) {
c.String(200, "pong")
})
g.GET("/favicon.ico", handles.Favicon)
g.GET("/robots.txt", handles.Robots)
g.GET("/i/:link_name", handles.Plist)
common.SecretKey = []byte(conf.Conf.JwtSecret)
g.Use(middlewares.StoragesLoaded)
if conf.Conf.MaxConnections > 0 {
g.Use(middlewares.MaxAllowed(conf.Conf.MaxConnections))
}
WebDav(g.Group("/dav"))

g.GET("/favicon.ico", handles.Favicon)
g.GET("/i/:link_name", handles.Plist)
g.GET("/d/*path", middlewares.Down, handles.Down)
g.GET("/p/*path", middlewares.Down, handles.Proxy)

Expand Down

0 comments on commit 5be79eb

Please sign in to comment.