database.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package repo
  2. import (
  3. "assetcenter/db/model"
  4. "infish.cn/comm"
  5. )
  6. func GetDatabaseCollection(ctx *RepoSession, dbId string, assetId string) (db *comm.Database, assetConf *comm.DbAsset) {
  7. database := &comm.Database{}
  8. ok, _ := RepoSeachDoc(ctx, &DocSearchOptions{CollectName: CollectionDatabase, Query: Map{"_id": dbId}, Project: []string{"assets", "name", "categories"}}, database)
  9. if !ok {
  10. return
  11. }
  12. db = database
  13. for _, v := range database.Assets {
  14. if v.Id == assetId {
  15. assetConf = v
  16. break
  17. }
  18. }
  19. return
  20. }
  21. func GetDatabaseCollectionSimple(ctx *RepoSession, dbId string, assetId string) *comm.AssetDbConf {
  22. out := &comm.AssetDbConf{}
  23. database := &comm.Database{}
  24. ok, _ := RepoSeachDoc(ctx, &DocSearchOptions{CollectName: CollectionDatabase, Query: Map{"_id": dbId}, Project: []string{"assets", "name"}}, database)
  25. if !ok {
  26. return nil
  27. }
  28. out.Db = database
  29. find := false
  30. for _, v := range database.Assets {
  31. if v.Id == assetId {
  32. out.AssetConf = v
  33. find = true
  34. break
  35. }
  36. }
  37. if find {
  38. return out
  39. }
  40. return nil
  41. }
  42. func RepoCreateDefaultAssetValue(asset *comm.DbAsset) interface{} {
  43. switch asset.Type {
  44. case model.AssetTypeMesh:
  45. return &model.AssetStaticMesh{}
  46. }
  47. return nil
  48. }