(c *gin.Context)
| 244 | ) |
| 245 | |
| 246 | func (service *SingleFileService) Get(c *gin.Context) (*GetFileResponse, error) { |
| 247 | dep := dependency.FromContext(c) |
| 248 | hasher := dep.HashIDEncoder() |
| 249 | fileClient := dep.FileClient() |
| 250 | |
| 251 | ctx := context.WithValue(c, inventory.LoadFileEntity{}, true) |
| 252 | ctx = context.WithValue(ctx, inventory.LoadFileMetadata{}, true) |
| 253 | ctx = context.WithValue(ctx, inventory.LoadFileShare{}, true) |
| 254 | ctx = context.WithValue(ctx, inventory.LoadFileUser{}, true) |
| 255 | ctx = context.WithValue(ctx, inventory.LoadEntityUser{}, true) |
| 256 | ctx = context.WithValue(ctx, inventory.LoadEntityStoragePolicy{}, true) |
| 257 | ctx = context.WithValue(ctx, inventory.LoadFileDirectLink{}, true) |
| 258 | |
| 259 | file, err := fileClient.GetByID(ctx, service.ID) |
| 260 | if err != nil { |
| 261 | if ent.IsNotFound(err) { |
| 262 | return nil, serializer.NewError(serializer.CodeNotFound, "File not found", nil) |
| 263 | } |
| 264 | |
| 265 | return nil, serializer.NewError(serializer.CodeDBError, "Failed to get file", err) |
| 266 | } |
| 267 | |
| 268 | directLinkMap := make(map[int]string) |
| 269 | siteURL := dep.SettingProvider().SiteURL(c) |
| 270 | for _, directLink := range file.Edges.DirectLinks { |
| 271 | directLinkMap[directLink.ID] = routes.MasterDirectLink(siteURL, hashid.EncodeSourceLinkID(hasher, directLink.ID), directLink.Name).String() |
| 272 | } |
| 273 | |
| 274 | return &GetFileResponse{ |
| 275 | File: file, |
| 276 | UserHashID: hashid.EncodeUserID(hasher, file.OwnerID), |
| 277 | FileHashID: hashid.EncodeFileID(hasher, file.ID), |
| 278 | DirectLinkMap: directLinkMap, |
| 279 | }, nil |
| 280 | } |
| 281 | |
| 282 | type ( |
| 283 | UpsertFileService struct { |
no test coverage detected