You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

model.go 3.2 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. package model
  2. import (
  3. "fmt"
  4. "reflect"
  5. "time"
  6. cdssdk "gitlink.org.cn/cloudream/common/sdks/storage"
  7. "gitlink.org.cn/cloudream/common/utils/serder"
  8. stgmod "gitlink.org.cn/cloudream/storage/common/models"
  9. )
  10. // TODO 可以考虑逐步迁移到cdssdk中。迁移思路:数据对象应该包含的字段都迁移到cdssdk中,内部使用的一些特殊字段则留在这里
  11. type Storage struct {
  12. StorageID cdssdk.StorageID `db:"StorageID" json:"storageID"`
  13. Name string `db:"Name" json:"name"`
  14. NodeID cdssdk.NodeID `db:"NodeID" json:"nodeID"`
  15. Directory string `db:"Directory" json:"directory"`
  16. State string `db:"State" json:"state"`
  17. }
  18. type User struct {
  19. UserID cdssdk.UserID `db:"UserID" json:"userID"`
  20. Password string `db:"PassWord" json:"password"`
  21. }
  22. type UserBucket struct {
  23. UserID cdssdk.UserID `db:"UserID" json:"userID"`
  24. BucketID cdssdk.BucketID `db:"BucketID" json:"bucketID"`
  25. }
  26. type UserNode struct {
  27. UserID cdssdk.UserID `db:"UserID" json:"userID"`
  28. NodeID cdssdk.NodeID `db:"NodeID" json:"nodeID"`
  29. }
  30. type UserStorage struct {
  31. UserID cdssdk.UserID `db:"UserID" json:"userID"`
  32. StorageID cdssdk.StorageID `db:"StorageID" json:"storageID"`
  33. }
  34. type Bucket = cdssdk.Bucket
  35. type Package = cdssdk.Package
  36. type Object = cdssdk.Object
  37. type NodeConnectivity = cdssdk.NodeConnectivity
  38. // 由于Object的Redundancy字段是interface,所以不能直接将查询结果scan成Object,必须先scan成TempObject,
  39. // 再.ToObject()转成Object
  40. type TempObject struct {
  41. cdssdk.Object
  42. Redundancy RedundancyWarpper `db:"Redundancy"`
  43. }
  44. func (o *TempObject) ToObject() cdssdk.Object {
  45. obj := o.Object
  46. obj.Redundancy = o.Redundancy.Value
  47. return obj
  48. }
  49. type RedundancyWarpper struct {
  50. Value cdssdk.Redundancy
  51. }
  52. func (o *RedundancyWarpper) Scan(src interface{}) error {
  53. data, ok := src.([]uint8)
  54. if !ok {
  55. return fmt.Errorf("unknow src type: %v", reflect.TypeOf(data))
  56. }
  57. red, err := serder.JSONToObjectEx[cdssdk.Redundancy](data)
  58. if err != nil {
  59. return err
  60. }
  61. o.Value = red
  62. return nil
  63. }
  64. type ObjectBlock = stgmod.ObjectBlock
  65. type Cache struct {
  66. FileHash string `db:"FileHash" json:"fileHash"`
  67. NodeID cdssdk.NodeID `db:"NodeID" json:"nodeID"`
  68. CreateTime time.Time `db:"CreateTime" json:"createTime"`
  69. Priority int `db:"Priority" json:"priority"`
  70. }
  71. const (
  72. StoragePackageStateNormal = "Normal"
  73. StoragePackageStateDeleted = "Deleted"
  74. StoragePackageStateOutdated = "Outdated"
  75. )
  76. // Storage当前加载的Package
  77. type StoragePackage struct {
  78. StorageID cdssdk.StorageID `db:"StorageID" json:"storageID"`
  79. PackageID cdssdk.PackageID `db:"PackageID" json:"packageID"`
  80. UserID cdssdk.UserID `db:"UserID" json:"userID"`
  81. State string `db:"State" json:"state"`
  82. }
  83. type StoragePackageLog struct {
  84. StorageID cdssdk.StorageID `db:"StorageID" json:"storageID"`
  85. PackageID cdssdk.PackageID `db:"PackageID" json:"packageID"`
  86. UserID cdssdk.UserID `db:"UserID" json:"userID"`
  87. CreateTime time.Time `db:"CreateTime" json:"createTime"`
  88. }
  89. type Location struct {
  90. LocationID cdssdk.LocationID `db:"LocationID" json:"locationID"`
  91. Name string `db:"Name" json:"name"`
  92. }

本项目旨在将云际存储公共基础设施化,使个人及企业可低门槛使用高效的云际存储服务(安装开箱即用云际存储客户端即可,无需关注其他组件的部署),同时支持用户灵活便捷定制云际存储的功能细节。