MCPcopy Create free account
hub / github.com/OpenCSGs/csghub-server / Show

Method Show

component/space.go:184–266  ·  view source on GitHub ↗
(ctx context.Context, namespace, name, currentUser string)

Source from the content-addressed store, hash-verified

182}
183
184func (c *SpaceComponent) Show(ctx context.Context, namespace, name, currentUser string) (*types.Space, error) {
185 var tags []types.RepoTag
186 space, err := c.ss.FindByPath(ctx, namespace, name)
187 if err != nil {
188 return nil, fmt.Errorf("failed to find space, error: %w", err)
189 }
190
191 permission, err := c.getUserRepoPermission(ctx, currentUser, space.Repository)
192 if err != nil {
193 return nil, fmt.Errorf("failed to get user repo permission, error: %w", err)
194 }
195 if !permission.CanRead {
196 return nil, ErrUnauthorized
197 }
198
199 ns, err := c.getNameSpaceInfo(ctx, namespace)
200 if err != nil {
201 return nil, fmt.Errorf("failed to get namespace info for model, error: %w", err)
202 }
203
204 var endpoint string
205 svcName, status, _ := c.status(ctx, space)
206 if len(svcName) > 0 {
207 if c.publicRootDomain == "" {
208 if space.Sdk == scheduler.STREAMLIT.Name || space.Sdk == scheduler.GRADIO.Name {
209 // if endpoint not ends with /, fastapi based app (gradio and streamlit) will redirect with http 307
210 // see issue: https://stackoverflow.com/questions/70351360/keep-getting-307-temporary-redirect-before-returning-status-200-hosted-on-fast
211 endpoint, _ = url.JoinPath(c.serverBaseUrl, "endpoint", svcName, "/")
212 } else {
213 endpoint, _ = url.JoinPath(c.serverBaseUrl, "endpoint", svcName)
214 }
215 endpoint = strings.Replace(endpoint, "http://", "", 1)
216 endpoint = strings.Replace(endpoint, "https://", "", 1)
217 } else {
218 endpoint = fmt.Sprintf("%s.%s", svcName, c.publicRootDomain)
219 }
220 }
221
222 likeExists, err := c.uls.IsExist(ctx, currentUser, space.Repository.ID)
223 if err != nil {
224 newError := fmt.Errorf("failed to check for the presence of the user likes,error:%w", err)
225 return nil, newError
226 }
227 repository := common.BuildCloneInfo(c.config, space.Repository)
228
229 resModel := &types.Space{
230 ID: space.ID,
231 Name: space.Repository.Name,
232 Nickname: space.Repository.Nickname,
233 Description: space.Repository.Description,
234 Likes: space.Repository.Likes,
235 Path: space.Repository.Path,
236 License: space.Repository.License,
237 DefaultBranch: space.Repository.DefaultBranch,
238 Repository: &repository,
239 Private: space.Repository.Private,
240 Tags: tags,
241 User: &types.User{

Callers

nothing calls this directly

Calls 6

statusMethod · 0.95
BuildCloneInfoFunction · 0.92
getUserRepoPermissionMethod · 0.80
getNameSpaceInfoMethod · 0.80
FindByPathMethod · 0.45
IsExistMethod · 0.45

Tested by

no test coverage detected