MCPcopy
hub / github.com/eyebluecn/tank / Create

Method Create

code/rest/share_controller.go:79–155  ·  view source on GitHub ↗
(writer http.ResponseWriter, request *http.Request)

Source from the content-addressed store, hash-verified

77}
78
79func (this *ShareController) Create(writer http.ResponseWriter, request *http.Request) *result.WebResult {
80
81 uuidArray := util.ExtractRequestArray(request, "matterUuids")
82 expireInfinity := util.ExtractRequestBool(request, "expireInfinity")
83 spaceUuid := util.ExtractRequestString(request, "spaceUuid")
84
85 var expireTime = time.Now()
86 if !expireInfinity {
87 expireTime = util.ExtractRequestTime(request, "expireTime")
88 if expireTime.Before(time.Now()) {
89 panic(result.BadRequest("expire time cannot before now"))
90 }
91 }
92
93 if len(uuidArray) > SHARE_MAX_NUM {
94 panic(result.BadRequestI18n(request, i18n.ShareNumExceedLimit, len(uuidArray), SHARE_MAX_NUM))
95 }
96
97 var name string
98 shareType := SHARE_TYPE_MIX
99 user := this.checkUser(request)
100 var puuid string
101 var matters []*Matter
102 for key, uuid := range uuidArray {
103
104 matter := this.matterDao.CheckByUuid(uuid)
105
106 if matter.UserUuid != user.Uuid {
107 panic(result.UNAUTHORIZED)
108 }
109
110 matters = append(matters, matter)
111
112 if key == 0 {
113 puuid = matter.Puuid
114 name = matter.Name
115 if matter.Dir {
116 shareType = SHARE_TYPE_DIRECTORY
117 } else {
118 shareType = SHARE_TYPE_FILE
119 }
120 } else {
121 if matter.Puuid != puuid {
122 panic(result.Unauthorized("you can only share files in the same directory"))
123 }
124 }
125
126 }
127
128 if len(matters) > 1 {
129 shareType = SHARE_TYPE_MIX
130 name = matters[0].Name + "," + matters[1].Name + " ..."
131 }
132
133 share := &Share{
134 Name: name,
135 ShareType: shareType,
136 UserUuid: user.Uuid,

Callers

nothing calls this directly

Calls 12

ExtractRequestArrayFunction · 0.92
ExtractRequestBoolFunction · 0.92
ExtractRequestStringFunction · 0.92
ExtractRequestTimeFunction · 0.92
BadRequestFunction · 0.92
BadRequestI18nFunction · 0.92
UnauthorizedFunction · 0.92
RandomString4Function · 0.92
checkUserMethod · 0.80
SuccessMethod · 0.80
CreateMethod · 0.65
CheckByUuidMethod · 0.45

Tested by

no test coverage detected