resource.go 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. package models
  2. import (
  3. "eta/eta_hub/global"
  4. "eta/eta_hub/utils"
  5. "time"
  6. )
  7. type Resource struct {
  8. Id int `orm:"column(id);" description:"资源id"`
  9. ResourceUrl string `description:"资源地址"`
  10. CreateTime time.Time `description:"创建时间"`
  11. ResourceType int `description:"资源类型,1:图片,2:音频,3:视频 ,4:ppt"`
  12. }
  13. type ResourceResp struct {
  14. Id int64 `orm:"column(id);" description:"用户id"`
  15. ResourceUrl string `description:"资源地址"`
  16. PlaySeconds uint32 `description:"播放时长,单位秒"`
  17. Source string
  18. CacheKey string
  19. ResourceName string `description:"资源名称"`
  20. OpenaiFileId string `description:"openai返回的文件id"`
  21. AiChatTopicId int `description:"主题id"`
  22. }
  23. func AddResource(item *Resource) (newId int64, err error) {
  24. //o := orm.NewOrmUsingDB("rddp")
  25. sql := "INSERT INTO resource(resource_url,create_time,resource_type) VALUES(?,?,?)"
  26. err = global.DbMap[utils.MYSQL_URL_RDDP].Exec(sql, item.ResourceUrl, item.CreateTime, item.ResourceType).Error
  27. if err != nil {
  28. return 0, err
  29. }
  30. //newId, err = res.LastInsertId()
  31. //if err != nil {
  32. // return 0, err
  33. //}
  34. return newId, err
  35. }
  36. func GetResourceById(id string) (item *Resource, err error) {
  37. //o := orm.NewOrmUsingDB("rddp")
  38. sql := "SELECT * FROM resource WHERE id=? "
  39. err = global.DbMap[utils.MYSQL_URL_RDDP].Raw(sql, id).Scan(&item).Error
  40. return
  41. }
  42. type ResourceBase64Resp struct {
  43. Image string `description:"图片,base64字符串"`
  44. }
  45. type PptResourceResp struct {
  46. Id int64 `orm:"column(id);" description:"用户id"`
  47. ResourceUrl []string `description:"资源地址"`
  48. PlaySeconds uint32 `description:"播放时长,单位秒"`
  49. }
  50. type ImageSvgToPngResp struct {
  51. Data struct {
  52. ResourceURL string `json:"ResourceUrl"`
  53. } `json:"Data"`
  54. ErrCode string `json:"ErrCode"`
  55. ErrMsg string `json:"ErrMsg"`
  56. IsSendEmail bool `json:"IsSendEmail"`
  57. Msg string `json:"Msg"`
  58. Ret int64 `json:"Ret"`
  59. Success bool `json:"Success"`
  60. }