package api import ( "assetcenter/conf" "assetcenter/db/model" "assetcenter/db/repo" "time" "go.mongodb.org/mongo-driver/bson/primitive" "infish.cn/comm" ) func UploadMaterial(apictx *ApiSession, dbConf *comm.AssetDbConf, body *comm.AssetMat) (interface{}, error) { asset := body // source := asset.Source asset.Enable = BoolValue(false) asset.AssetState = model.AssetState_Succ if conf.AppConfig.IsSaveLocal() { body.UpdateSourceUrl(conf.AppConfig.TrimSaveLocalUrl) } asset.CreateTime = time.Now() asset.UpdateTime = time.Now() collectionName := dbConf.AssetConf.Collection return repo.RepoDbAddDoc(apictx.CreateRepoCtx(), dbConf.Db.Name, collectionName, asset) } func UploadMaterialGroup(apictx *ApiSession, dbConf *comm.AssetDbConf, body *comm.AssetMatGroup) (interface{}, error) { asset := body // source := asset.Source asset.Enable = BoolValue(false) asset.AssetState = model.AssetState_Succ if conf.AppConfig.IsSaveLocal() { body.UpdateSourceUrl(conf.AppConfig.TrimSaveLocalUrl) } asset.CreateTime = time.Now() asset.UpdateTime = time.Now() collectionName := dbConf.AssetConf.Collection return repo.RepoDbAddDoc(apictx.CreateRepoCtx(), dbConf.Db.Name, collectionName, asset) } func UpdateMaterialGroup(apictx *ApiSession, dbConf *comm.AssetDbConf, body *comm.AssetMatGroup) (interface{}, error) { asset := body asset.UpdateTime = time.Now() id := asset.Id.Hex() asset.Id = primitive.NilObjectID if conf.AppConfig.IsSaveLocal() { body.UpdateSourceUrl(conf.AppConfig.TrimSaveLocalUrl) } collectionName := dbConf.AssetConf.Collection return repo.RepoUpdateSeDbDoc(apictx.CreateRepoCtx(), dbConf.Db.Name, collectionName, id, asset) } func UpdateMaterialComm(apictx *ApiSession, dbConf *comm.AssetDbConf, body *comm.AssetMat) (interface{}, error) { asset := body asset.UpdateTime = time.Now() id := asset.Id.Hex() asset.Id = primitive.NilObjectID if conf.AppConfig.IsSaveLocal() { body.UpdateSourceUrl(conf.AppConfig.TrimSaveLocalUrl) } collectionName := dbConf.AssetConf.Collection return repo.RepoUpdateSeDbDoc(apictx.CreateRepoCtx(), dbConf.Db.Name, collectionName, id, asset) } func UpdateMaterialSource(apictx *ApiSession, dbConf *comm.AssetDbConf, body *comm.AssetMat) (interface{}, error) { asset := body asset.UpdateTime = time.Now() id := asset.Id.Hex() asset.Id = primitive.NilObjectID if conf.AppConfig.IsSaveLocal() { body.UpdateSourceUrl(conf.AppConfig.TrimSaveLocalUrl) } collectionName := dbConf.AssetConf.Collection return repo.RepoUpdateSeDbDoc(apictx.CreateRepoCtx(), dbConf.Db.Name, collectionName, id, asset) } func ProcessMat(apictx *ApiSession, dbConf *comm.AssetDbConf, id string) (interface{}, error) { // mesh := &model.AssetMat{} // ok, err := repo.RepoSeachDoc(apictx.CreateRepoCtx(), &repo.DocSearchOptions{ // Db: dbConf.DbName, // CollectName: dbConf.AssetConf.Collection, // Query: repo.Map{"_id": id}, // Project: []string{"source.file"}, // }, mesh) // if err != nil { // return nil, err // } // if !ok { // return nil, NewError("hdr已删除!") // } // err = bus.NatsCenter.HdrAssetProcessReq(dbConf.DbName, dbConf.AssetConf.Collection, id, mesh.Source.File.Url) // assetState := model.AssetState_Waiting // if err != nil { // assetState = model.AssetState_Failed // } // update := bson.M{"$set": bson.M{"assetState": assetState}} // return repo.RepoUpdateSetDbDocProps(apictx.CreateRepoCtx(), dbConf.DbName, dbConf.AssetConf.Collection, id, update) return nil, NewError("no impl!") }