schema.ts 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. import { Model, Schema, SchemaTypes, Types } from "mongoose";
  2. import { GetData } from "@/modules/DataModule/plugins/getData";
  3. import { BaseSchema } from "@/modules/DataModule/types/Schemas";
  4. import { StationType } from "./StationType";
  5. import { StationPrivacy } from "./StationPrivacy";
  6. import { StationTheme } from "./StationTheme";
  7. import { StationRequestsAccess } from "./StationRequestsAccess";
  8. import { StationAutofillMode } from "./StationAutofillMode";
  9. import config from "./config";
  10. export interface StationSchema extends BaseSchema {
  11. type: StationType;
  12. name: string;
  13. displayName: string;
  14. description: string;
  15. privacy: StationPrivacy;
  16. theme: StationTheme;
  17. owner?: Types.ObjectId;
  18. djs: Types.ObjectId[];
  19. currentSong?: Types.ObjectId;
  20. currentSongIndex?: number;
  21. startedAt?: NativeDate;
  22. paused: boolean;
  23. timePaused: number;
  24. pausedAt?: NativeDate;
  25. playlist: Types.ObjectId;
  26. queue: Types.ObjectId[];
  27. blacklist: Types.ObjectId[];
  28. requests?: {
  29. enabled: boolean;
  30. access: StationRequestsAccess;
  31. limit: number;
  32. };
  33. autofill?: {
  34. enabled: boolean;
  35. playlists: Types.ObjectId[];
  36. limit: number;
  37. mode: StationAutofillMode;
  38. };
  39. }
  40. export interface StationModel extends Model<StationSchema>, GetData {}
  41. export const schema = new Schema<StationSchema, StationModel>(
  42. {
  43. type: {
  44. type: SchemaTypes.String,
  45. enum: Object.values(StationType),
  46. required: true
  47. },
  48. name: {
  49. type: SchemaTypes.String,
  50. unique: true,
  51. minLength: 2,
  52. maxLength: 16,
  53. required: true
  54. },
  55. displayName: {
  56. type: SchemaTypes.String,
  57. unique: true,
  58. minLength: 2,
  59. maxLength: 32,
  60. required: true
  61. },
  62. description: {
  63. type: SchemaTypes.String,
  64. minLength: 2,
  65. maxLength: 128,
  66. required: true
  67. },
  68. privacy: {
  69. type: SchemaTypes.String,
  70. default: StationPrivacy.PRIVATE,
  71. enum: Object.values(StationPrivacy),
  72. required: true
  73. },
  74. theme: {
  75. type: SchemaTypes.String,
  76. default: StationTheme.BLUE,
  77. enum: Object.values(StationTheme),
  78. required: true
  79. },
  80. owner: {
  81. type: SchemaTypes.ObjectId,
  82. ref: "users",
  83. required: false
  84. },
  85. djs: [{ type: SchemaTypes.ObjectId, ref: "users" }],
  86. currentSong: {
  87. type: SchemaTypes.ObjectId,
  88. required: false
  89. },
  90. currentSongIndex: {
  91. type: SchemaTypes.Number,
  92. required: false
  93. },
  94. startedAt: {
  95. type: SchemaTypes.Date,
  96. required: false
  97. },
  98. paused: {
  99. type: SchemaTypes.Boolean,
  100. default: false
  101. },
  102. timePaused: {
  103. type: SchemaTypes.Number,
  104. default: 0
  105. },
  106. pausedAt: {
  107. type: SchemaTypes.Date,
  108. required: false
  109. },
  110. playlist: {
  111. type: SchemaTypes.ObjectId
  112. },
  113. queue: [{ type: SchemaTypes.ObjectId }],
  114. blacklist: [{ type: SchemaTypes.ObjectId }],
  115. requests: {
  116. enabled: {
  117. type: SchemaTypes.Boolean,
  118. default: true
  119. },
  120. access: {
  121. type: SchemaTypes.String,
  122. default: StationRequestsAccess.OWNER,
  123. enum: Object.values(StationRequestsAccess)
  124. },
  125. limit: {
  126. type: SchemaTypes.Number,
  127. default: 5,
  128. min: 1,
  129. max: 50
  130. }
  131. },
  132. autofill: {
  133. enabled: {
  134. type: SchemaTypes.Boolean,
  135. default: true
  136. },
  137. playlists: [{ type: SchemaTypes.ObjectId }],
  138. limit: {
  139. type: SchemaTypes.Number,
  140. default: 30,
  141. min: 1,
  142. max: 50
  143. },
  144. mode: {
  145. type: SchemaTypes.String,
  146. default: StationAutofillMode.RANDOM,
  147. enum: Object.values(StationAutofillMode)
  148. }
  149. }
  150. },
  151. config
  152. );
  153. export type StationSchemaType = typeof schema;