Skip to content

Commit

Permalink
Adjust media path to match go-gitea#5184
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Thornton <[email protected]>
  • Loading branch information
zeripath committed Feb 7, 2019
1 parent 35dc5b9 commit 8b224e8
Showing 1 changed file with 25 additions and 14 deletions.
39 changes: 25 additions & 14 deletions routers/repo/wiki.go
Original file line number Diff line number Diff line change
Expand Up @@ -340,26 +340,37 @@ func WikiMedia(ctx *context.Context) {
return
}
}

providedPath := ctx.Params("*")
if strings.HasSuffix(providedPath, ".md") {
providedPath = providedPath[:len(providedPath)-3]
}
wikiPath := models.WikiNameToFilename(providedPath)

var entry *git.TreeEntry
if commit != nil {
entry, err = findEntryForFile(commit, wikiPath)
}
if err != nil {
ctx.ServerError("findFile", err)
return
} else if entry == nil {
ctx.NotFound("findEntryForFile", nil)
return
entry, err = findEntryForFile(commit, providedPath)
if err != nil {
ctx.ServerError("findFile", err)
}

if entry == nil {
// Try to find a wiki page with that name
if strings.HasSuffix(providedPath, ".md") {
providedPath = providedPath[:len(providedPath)-3]
}

wikiPath := models.WikiNameToFilename(providedPath)
entry, err = findEntryForFile(commit, wikiPath)
if err != nil {
ctx.ServerError("findFile", err)
return
}
}
}

if err = ServeBlobOrLFS(ctx, entry.Blob()); err != nil {
ctx.ServerError("ServeBlob", err)
if entry != nil {
if err = ServeBlobOrLFS(ctx, entry.Blob()); err != nil {
ctx.ServerError("ServeBlob", err)
}
}
ctx.NotFound("findEntryForFile", nil)
}

// NewWiki render wiki create page
Expand Down

0 comments on commit 8b224e8

Please sign in to comment.