service-database-upload-image.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package api
  2. import (
  3. "assetcenter/conf"
  4. "assetcenter/db/model"
  5. "assetcenter/db/repo"
  6. "time"
  7. "go.mongodb.org/mongo-driver/bson/primitive"
  8. "infish.cn/comm"
  9. )
  10. func UploadImage(apictx *ApiSession, dbConf *comm.AssetDbConf, body *comm.AssetImage) (interface{}, error) {
  11. asset := body
  12. // source := asset.Source
  13. asset.Enable = BoolValue(false)
  14. asset.AssetState = model.AssetState_Succ
  15. if conf.AppConfig.IsSaveLocal() {
  16. asset.UpdateSourceUrl(conf.AppConfig.TrimSaveLocalUrl)
  17. }
  18. asset.CreateTime = time.Now()
  19. asset.UpdateTime = time.Now()
  20. collectionName := dbConf.AssetConf.Collection
  21. return repo.RepoDbAddDoc(apictx.CreateRepoCtx(), dbConf.Db.Name, collectionName, asset)
  22. }
  23. func UpdateImageComm(apictx *ApiSession, dbConf *comm.AssetDbConf, body *comm.AssetImage) (interface{}, error) {
  24. asset := body
  25. asset.UpdateTime = time.Now()
  26. id := asset.Id.Hex()
  27. asset.Id = primitive.NilObjectID
  28. if conf.AppConfig.IsSaveLocal() {
  29. asset.UpdateSourceUrl(conf.AppConfig.TrimSaveLocalUrl)
  30. }
  31. collectionName := dbConf.AssetConf.Collection
  32. return repo.RepoUpdateSeDbDoc(apictx.CreateRepoCtx(), dbConf.Db.Name, collectionName, id, asset)
  33. }
  34. func UpdateImageSource(apictx *ApiSession, dbConf *comm.AssetDbConf, body *comm.AssetImage) (interface{}, error) {
  35. asset := body
  36. asset.UpdateTime = time.Now()
  37. id := asset.Id.Hex()
  38. asset.Id = primitive.NilObjectID
  39. if conf.AppConfig.IsSaveLocal() {
  40. asset.UpdateSourceUrl(conf.AppConfig.TrimSaveLocalUrl)
  41. }
  42. collectionName := dbConf.AssetConf.Collection
  43. return repo.RepoUpdateSeDbDoc(apictx.CreateRepoCtx(), dbConf.Db.Name, collectionName, id, asset)
  44. }