forked from Gitlink/gitea-1120-rc1
fix:wikies
This commit is contained in:
parent
e6c3986962
commit
554fd29ebb
|
@ -278,3 +278,29 @@ func (ctx *APIContext) FileNameError(objs ...interface{}){
|
|||
"errors": errors,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
func (ctx *APIContext) FileExistError(objs ...interface{}){
|
||||
var message = "file does not exist"
|
||||
var errors []string
|
||||
|
||||
for _, obj := range objs {
|
||||
// Ignore nil
|
||||
if obj == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
if err, ok := obj.(error); ok {
|
||||
errors = append(errors, err.Error())
|
||||
} else {
|
||||
message = obj.(string)
|
||||
}
|
||||
}
|
||||
ctx.JSON(500, map[string]interface{}{
|
||||
"message": message,
|
||||
"documentation_url": setting.API.SwaggerURL,
|
||||
"errors": errors,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@ import (
|
|||
"code.gitea.io/gitea/modules/wikies"
|
||||
wiki_service "code.gitea.io/gitea/services/wiki"
|
||||
"net/http"
|
||||
"sort"
|
||||
)
|
||||
|
||||
func WikiList(ctx *context.APIContext) {
|
||||
|
@ -51,7 +52,7 @@ func WikiList(ctx *context.APIContext) {
|
|||
//ctx.JSON(http.StatusOK, []api.WikiesResponse{})
|
||||
return
|
||||
}
|
||||
wikies := make([]api.WikiesResponse, 0, len(entries))
|
||||
wikiesList := make([]api.WikiesResponse, 0, len(entries))
|
||||
for _, entry := range entries {
|
||||
if !entry.IsRegular() {
|
||||
continue
|
||||
|
@ -73,10 +74,10 @@ func WikiList(ctx *context.APIContext) {
|
|||
if wikiRepo != nil {
|
||||
wikiRepo.Close()
|
||||
}
|
||||
ctx.ServerError("WikiFilenameToName", err)
|
||||
//ctx.ServerError("WikiFilenameToName", err)
|
||||
return
|
||||
}
|
||||
wikies = append(wikies, api.WikiesResponse{
|
||||
wikiesList = append(wikiesList, api.WikiesResponse{
|
||||
WikiCloneLink: api.CloneLink{
|
||||
HTTPS: wikiCloneLink.HTTPS,
|
||||
SSH: wikiCloneLink.SSH,
|
||||
|
@ -100,7 +101,11 @@ func WikiList(ctx *context.APIContext) {
|
|||
},
|
||||
})
|
||||
}
|
||||
ctx.JSON(http.StatusOK, wikies)
|
||||
//根据创建时间,按最新的时间排序
|
||||
sort.Slice(wikiesList,func(i, j int) bool{
|
||||
return wikiesList[i].Commit.Commiter.When > wikiesList[j].Commit.Commiter.When
|
||||
})
|
||||
ctx.JSON(http.StatusOK, wikiesList)
|
||||
}
|
||||
|
||||
func GetWiki(ctx *context.APIContext) {
|
||||
|
@ -130,9 +135,6 @@ func GetWiki(ctx *context.APIContext) {
|
|||
// "$ref": "#/responses/Wiki"
|
||||
|
||||
wikiRepo, commit, _ := wikies.FindWikiRepoCommit(ctx)
|
||||
|
||||
//repository := ctx.Repo.Repository
|
||||
//wikiCloneLink:= repository.CloneWikiLink()
|
||||
repository := ctx.Repo.Repository
|
||||
wikiCloneLink:= repository.CloneWikiLink()
|
||||
pageName := wiki_service.NormalizeWikiName(ctx.Params(":page"))
|
||||
|
@ -159,7 +161,6 @@ func GetWiki(ctx *context.APIContext) {
|
|||
}
|
||||
}
|
||||
commitsCount, _ := wikiRepo.FileCommitsCount("master", pageFilename)
|
||||
|
||||
wiki := api.WikiResponse{
|
||||
WikiCloneLink: api.CloneLink{
|
||||
HTTPS: wikiCloneLink.HTTPS,
|
||||
|
@ -223,8 +224,6 @@ func CreateWiki(ctx *context.APIContext, form api.WikiOption) {
|
|||
wikiCloneLink:= repository.CloneWikiLink()
|
||||
wikies.NewWikiPost(ctx,form)
|
||||
|
||||
|
||||
|
||||
wikiRepo, commit, _ := wikies.FindWikiRepoCommit(ctx)
|
||||
data, entry, pageFilename, _:= wikies.WikiContentsByName(ctx, commit, form.Name)
|
||||
metas := ctx.Repo.Repository.ComposeDocumentMetas()
|
||||
|
@ -266,7 +265,7 @@ func CreateWiki(ctx *context.APIContext, form api.WikiOption) {
|
|||
}
|
||||
|
||||
func EditWiki(ctx *context.APIContext, form api.WikiOption) {
|
||||
// swagger:operation PATCH /repos/{owner}/{repo}/wikies/{pagename} repository repoEditWiki
|
||||
// swagger:operation PATCH /repos/{owner}/{repo}/wikies/{pagename} repository repoEditWiki
|
||||
// ---
|
||||
// summary: Edit a wiki in a repository
|
||||
// produces:
|
||||
|
@ -292,9 +291,8 @@ func EditWiki(ctx *context.APIContext, form api.WikiOption) {
|
|||
// schema:
|
||||
// "$ref": "#/definitions/WikiOption"
|
||||
// responses:
|
||||
// "200":
|
||||
// "$ref": "#/responses/Wiki
|
||||
//oldWikiName := wiki_service.NormalizeWikiName(ctx.Params(":page"))
|
||||
// "201":
|
||||
// "$ref": "#/responses/Wiki"
|
||||
|
||||
newWikiName := wiki_service.NormalizeWikiName(form.Name)
|
||||
err1 := wiki_service.CheckFile(newWikiName)
|
||||
|
@ -302,10 +300,6 @@ func EditWiki(ctx *context.APIContext, form api.WikiOption) {
|
|||
ctx.FileNameError()
|
||||
return
|
||||
}
|
||||
//err2 := wiki_service.EditWikiPage(ctx.User, ctx.Repo.Repository, oldWikiName,newWikiName, form.Content, form.CommitMessage)
|
||||
//if err2 != nil{
|
||||
// ctx.ServerError("EditWikiPage", err2)
|
||||
|
||||
|
||||
wikies.EditWikiPost(ctx, form)
|
||||
wikiRepo, commit, _ := wikies.FindWikiRepoCommit(ctx)
|
||||
|
@ -369,15 +363,59 @@ func DeleteWiki(ctx *context.APIContext) {
|
|||
// "204":
|
||||
// "$ref": "#/responses/empty"
|
||||
// "500":
|
||||
// "$ref": "#/responses/notFound"
|
||||
// "$ref": "#/responses/noFound"
|
||||
|
||||
|
||||
wikiRepo, commit, err := wikies.FindWikiRepoCommit(ctx)
|
||||
if err != nil {
|
||||
if wikiRepo != nil {
|
||||
wikiRepo.Close()
|
||||
}
|
||||
return
|
||||
}
|
||||
entries, err1 := commit.ListEntries()
|
||||
if err1 != nil {
|
||||
if wikiRepo != nil {
|
||||
wikiRepo.Close()
|
||||
}
|
||||
return
|
||||
}
|
||||
wikies := make([]api.WikiMeta, 0, len(entries))
|
||||
for _, entry := range entries {
|
||||
|
||||
name, err := wiki_service.FilenameToName(entry.Name())
|
||||
if err != nil {
|
||||
if models.IsErrWikiInvalidFileName(err) {
|
||||
continue
|
||||
}
|
||||
if wikiRepo != nil {
|
||||
wikiRepo.Close()
|
||||
}
|
||||
return
|
||||
}
|
||||
wikies = append(wikies, api.WikiMeta{
|
||||
Name: name,
|
||||
})
|
||||
|
||||
}
|
||||
wikiName := wiki_service.NormalizeWikiName(ctx.Params(":page"))
|
||||
if len(wikiName) == 0 {
|
||||
wikiName = "Home"
|
||||
}
|
||||
err := wiki_service.DeleteWikiPage(ctx.User, ctx.Repo.Repository, wikiName)
|
||||
if err != nil{
|
||||
ctx.Error(http.StatusInternalServerError,"DeleteWikiPage", err)
|
||||
//Does the file exist
|
||||
for _, wiky := range wikies {
|
||||
if wikiName == wiky.Name{
|
||||
continue
|
||||
}else{
|
||||
ctx.FileExistError()
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
err2 := wiki_service.DeleteWikiPage(ctx.User, ctx.Repo.Repository, wikiName)
|
||||
if err2 != nil{
|
||||
//ctx.Error(http.StatusInternalServerError,"DeleteWikiPage", err)
|
||||
ctx.FileExistError()
|
||||
return
|
||||
}
|
||||
}
|
||||
|
|
|
@ -68,7 +68,7 @@ func FilenameToName(filename string) (string, error) {
|
|||
}
|
||||
// check filename
|
||||
func CheckFile(filename string) error {
|
||||
if(len(filename) <= 150 ){
|
||||
if(len(filename) <= 50 ){
|
||||
return nil
|
||||
}else {
|
||||
err := errors.New("The name is too long, please be less than 200 bytes")
|
||||
|
@ -76,8 +76,6 @@ func CheckFile(filename string) error {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// InitWiki initializes a wiki for repository,
|
||||
// it does nothing when repository already has wiki.
|
||||
func InitWiki(repo *models.Repository) error {
|
||||
|
|
|
@ -9047,7 +9047,7 @@
|
|||
"$ref": "#/responses/empty"
|
||||
},
|
||||
"500": {
|
||||
"$ref": "#/responses/notFound"
|
||||
"$ref": "#/responses/noFound"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -9091,7 +9091,7 @@
|
|||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"201": {
|
||||
"$ref": "#/responses/Wiki"
|
||||
}
|
||||
}
|
||||
|
@ -15560,6 +15560,9 @@
|
|||
"simple_content": {
|
||||
"type": "string",
|
||||
"x-go-name": "SimpleContent"
|
||||
},
|
||||
"wiki_clone_link": {
|
||||
"$ref": "#/definitions/CloneLink"
|
||||
}
|
||||
},
|
||||
"x-go-package": "code.gitea.io/gitea/modules/structs"
|
||||
|
|
Loading…
Reference in New Issue