mirror of
https://github.com/eyebluecn/tank.git
synced 2024-04-21 12:32:16 +00:00
feat: add a new api. add puuid for crawl.
This commit is contained in:
@@ -222,14 +222,29 @@ func (this *MatterController) Upload(writer http.ResponseWriter, request *http.R
|
||||
func (this *MatterController) Crawl(writer http.ResponseWriter, request *http.Request) *result.WebResult {
|
||||
|
||||
url := util.ExtractRequestString(request, "url")
|
||||
destPath := util.ExtractRequestString(request, "destPath")
|
||||
destPath := util.ExtractRequestOptionalString(request, "destPath", "")
|
||||
puuid := util.ExtractRequestOptionalString(request, "puuid", "")
|
||||
filename := util.ExtractRequestString(request, "filename")
|
||||
|
||||
user := this.checkUser(request)
|
||||
spaceUuid := util.ExtractRequestOptionalString(request, "spaceUuid", user.SpaceUuid)
|
||||
space := this.spaceService.CheckWritableByUuid(request, user, spaceUuid)
|
||||
|
||||
dirMatter := this.matterService.CreateDirectories(request, user, space, destPath)
|
||||
var dirMatter *Matter
|
||||
if puuid == "" {
|
||||
dirMatter = this.matterDao.CheckByUuid(puuid)
|
||||
if dirMatter.SpaceUuid != space.Uuid {
|
||||
panic(result.UNAUTHORIZED)
|
||||
}
|
||||
if !dirMatter.Dir {
|
||||
panic(" puuid is not a dir.")
|
||||
}
|
||||
} else {
|
||||
if destPath == "" {
|
||||
panic(" puuid or destPath cannot be null")
|
||||
}
|
||||
dirMatter = this.matterService.CreateDirectories(request, user, space, destPath)
|
||||
}
|
||||
|
||||
if url == "" || (!strings.HasPrefix(url, "http://") && !strings.HasPrefix(url, "https://")) {
|
||||
panic(" url must start with http:// or https://")
|
||||
|
||||
@@ -150,10 +150,16 @@ func (this *Matter) FetchPropMap() map[string]string {
|
||||
// fetch the props
|
||||
func (this *Matter) SetPropMap(propMap map[string]string) {
|
||||
|
||||
//恢复panic
|
||||
//defer func() {
|
||||
// if err := recover(); err != nil {
|
||||
// fmt.Printf("occur error while set prop map %s\r\n", err)
|
||||
// }
|
||||
//}()
|
||||
|
||||
b, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(propMap)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
this.Prop = string(b)
|
||||
}
|
||||
|
||||
@@ -62,6 +62,7 @@ func (this *SpaceMemberController) RegisterRoutes() map[string]func(writer http.
|
||||
routeMap["/api/space/member/edit"] = this.Wrap(this.Edit, USER_ROLE_USER)
|
||||
routeMap["/api/space/member/delete"] = this.Wrap(this.Delete, USER_ROLE_USER)
|
||||
routeMap["/api/space/member/detail"] = this.Wrap(this.Detail, USER_ROLE_USER)
|
||||
routeMap["/api/space/member/mine"] = this.Wrap(this.Mine, USER_ROLE_USER)
|
||||
routeMap["/api/space/member/page"] = this.Wrap(this.Page, USER_ROLE_USER)
|
||||
|
||||
return routeMap
|
||||
@@ -151,6 +152,18 @@ func (this *SpaceMemberController) Detail(writer http.ResponseWriter, request *h
|
||||
|
||||
}
|
||||
|
||||
// find my role in the space.
|
||||
func (this *SpaceMemberController) Mine(writer http.ResponseWriter, request *http.Request) *result.WebResult {
|
||||
|
||||
spaceUuid := util.ExtractRequestString(request, "spaceUuid")
|
||||
|
||||
user := this.checkUser(request)
|
||||
spaceMember := this.spaceMemberDao.FindBySpaceUuidAndUserUuid(spaceUuid, user.Uuid)
|
||||
|
||||
return this.Success(spaceMember)
|
||||
|
||||
}
|
||||
|
||||
func (this *SpaceMemberController) Page(writer http.ResponseWriter, request *http.Request) *result.WebResult {
|
||||
|
||||
page := util.ExtractRequestOptionalInt(request, "page", 0)
|
||||
|
||||
Reference in New Issue
Block a user