implement diff/parent/%d endpoint
This commit is contained in:
parent
1bb94eae76
commit
73becc8729
15
DB.go
15
DB.go
@ -165,6 +165,21 @@ func (this *WikiDB) GetRevisionHistory(title string) ([]Article, error) {
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func (this *WikiDB) GetNextOldestRevision(revision int) (int, error) {
|
||||
row := this.db.QueryRow(
|
||||
`SELECT articles.id FROM articles WHERE articles.article = (SELECT article FROM articles WHERE id = ?) AND id < ? ORDER BY id DESC LIMIT 1`,
|
||||
revision, revision,
|
||||
)
|
||||
|
||||
var ret int
|
||||
err := row.Scan(&ret)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func (this *WikiDB) GetRecentChanges(offset int, limit int) ([]Article, error) {
|
||||
rows, err := this.db.Query(
|
||||
`SELECT articles.id, articles.modified, articles.author, titles.title FROM articles JOIN titles ON articles.article=titles.id ORDER BY modified DESC ` +
|
||||
|
@ -194,6 +194,22 @@ func (this *WikiServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
this.serveRedirect(w, this.opts.ExpectBaseURL+`diff/`+r.URL.Query().Get("f")+`/`+r.URL.Query().Get("t"))
|
||||
return
|
||||
|
||||
} else if strings.HasPrefix(remainingPath, "diff/parent/") {
|
||||
toRev, err := strconv.Atoi(remainingPath[len("diff/parent/"):])
|
||||
if err != nil {
|
||||
this.serveErrorMessage(w, err)
|
||||
return
|
||||
}
|
||||
|
||||
fromRev, err := this.db.GetNextOldestRevision(toRev)
|
||||
if err != nil {
|
||||
this.serveErrorMessage(w, err)
|
||||
return
|
||||
}
|
||||
|
||||
this.serveRedirect(w, this.opts.ExpectBaseURL+`diff/`+fmt.Sprintf("%d/%d", fromRev, toRev))
|
||||
return
|
||||
|
||||
} else if match := this.rxDiff.FindStringSubmatch(remainingPath); len(match) == 3 {
|
||||
|
||||
fromRev, err := strconv.Atoi(match[1])
|
||||
|
Loading…
Reference in New Issue
Block a user