fix:filename
This commit is contained in:
parent
0e9fd60786
commit
c2392616b5
|
@ -255,3 +255,26 @@ func (ctx *APIContext) NotFound(objs ...interface{}) {
|
||||||
"errors": errors,
|
"errors": errors,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (ctx *APIContext) FileNameError(objs ...interface{}){
|
||||||
|
var message = "FileName too long"
|
||||||
|
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,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
|
@ -36,8 +36,7 @@ func WikiList(ctx *context.APIContext) {
|
||||||
// "$ref": "#/responses/WikiList"
|
// "$ref": "#/responses/WikiList"
|
||||||
|
|
||||||
repository := ctx.Repo.Repository
|
repository := ctx.Repo.Repository
|
||||||
wikiCloneLink := repository.WikiCloneLink()
|
wikiCloneLink:= repository.CloneLink()
|
||||||
|
|
||||||
wikiRepo, commit, err := wikies.FindWikiRepoCommit(ctx)
|
wikiRepo, commit, err := wikies.FindWikiRepoCommit(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if wikiRepo != nil {
|
if wikiRepo != nil {
|
||||||
|
@ -217,11 +216,15 @@ func CreateWiki(ctx *context.APIContext, form api.WikiOption) {
|
||||||
// "200":
|
// "200":
|
||||||
// "$ref": "#/responses/Wiki"
|
// "$ref": "#/responses/Wiki"
|
||||||
|
|
||||||
|
err1 := wiki_service.CheckFile(form.Name)
|
||||||
|
if err1 != nil{
|
||||||
|
ctx.FileNameError()
|
||||||
|
return
|
||||||
|
}
|
||||||
err2 := wiki_service.AddWikiPage(ctx.User, ctx.Repo.Repository, form.Name, form.Content, form.CommitMessage)
|
err2 := wiki_service.AddWikiPage(ctx.User, ctx.Repo.Repository, form.Name, form.Content, form.CommitMessage)
|
||||||
if err2 != nil{
|
if err2 != nil{
|
||||||
ctx.ServerError("CreateWikiPage", err2)
|
ctx.ServerError("CreateWikiPage", err2)
|
||||||
}
|
}
|
||||||
fmt.Println("content", form.Content)
|
|
||||||
wikiRepo, commit, _ := wikies.FindWikiRepoCommit(ctx)
|
wikiRepo, commit, _ := wikies.FindWikiRepoCommit(ctx)
|
||||||
data, entry, pageFilename, _:= wikies.WikiContentsByName(ctx, commit, form.Name)
|
data, entry, pageFilename, _:= wikies.WikiContentsByName(ctx, commit, form.Name)
|
||||||
metas := ctx.Repo.Repository.ComposeDocumentMetas()
|
metas := ctx.Repo.Repository.ComposeDocumentMetas()
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
package wiki
|
package wiki
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
|
@ -65,6 +66,17 @@ func FilenameToName(filename string) (string, error) {
|
||||||
}
|
}
|
||||||
return NormalizeWikiName(unescaped), nil
|
return NormalizeWikiName(unescaped), nil
|
||||||
}
|
}
|
||||||
|
// check filename
|
||||||
|
func CheckFile(filename string) error {
|
||||||
|
if(len(filename) <= 150 ){
|
||||||
|
return nil
|
||||||
|
}else {
|
||||||
|
err := errors.New("The name is too long, please be less than 200 bytes")
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// InitWiki initializes a wiki for repository,
|
// InitWiki initializes a wiki for repository,
|
||||||
// it does nothing when repository already has wiki.
|
// it does nothing when repository already has wiki.
|
||||||
|
|
Loading…
Reference in New Issue