Skip to content

Commit

Permalink
feat: generate robots.txt with tunasync
Browse files Browse the repository at this point in the history
  • Loading branch information
idawnlight committed Oct 25, 2023
1 parent 6bc882b commit 52cc16a
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions manager/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ func GetTUNASyncManager(cfg *Config) *Manager {
// flush disabled jobs
s.engine.DELETE("/jobs/disabled", s.flushDisabledJobs)

// generate robots.txt
s.engine.GET("/robots.txt", s.generateRobotsTxt)

// list workers
s.engine.GET("/workers", s.listWorkers)
// worker online
Expand Down Expand Up @@ -152,6 +155,25 @@ func (s *Manager) listAllJobs(c *gin.Context) {
c.JSON(http.StatusOK, webMirStatusList)
}

func (s *Manager) generateRobotsTxt(c *gin.Context) {
s.rwmu.RLock()
mirrorStatusList, err := s.adapter.ListAllMirrorStatus()
s.rwmu.RUnlock()
if err != nil {
err := fmt.Errorf("failed to list all mirror status: %s",
err.Error(),
)
c.Error(err)
s.returnErrJSON(c, http.StatusInternalServerError, err)
return
}
content := "# robots.txt generated by tunasync-seu (seu-mirrors/tunasync)\nUser-agent: *\n\nDisallow: /-/\n"
for _, m := range mirrorStatusList {
content += fmt.Sprintf("Disallow: /%s/\n", m.Name)
}
c.String(http.StatusOK, content)
}

// flushDisabledJobs deletes all jobs that marks as deleted
func (s *Manager) flushDisabledJobs(c *gin.Context) {
s.rwmu.Lock()
Expand Down

0 comments on commit 52cc16a

Please sign in to comment.