Federated video streaming platform using ActivityPub and P2P in the web browser with Angular. https://joinpeertube.org/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

102 lines
2.1 KiB

  1. import { DestroyOptions, Op, Transaction } from 'sequelize'
  2. import { AllowNull, BelongsTo, Column, CreatedAt, ForeignKey, IsInt, Model, Table, UpdatedAt } from 'sequelize-typescript'
  3. import { MUserAccountId, MUserId } from '@server/types/models'
  4. import { AttributesOnly } from '@shared/typescript-utils'
  5. import { VideoModel } from '../video/video'
  6. import { UserModel } from './user'
  7. import { getServerActor } from '../application/application'
  8. @Table({
  9. tableName: 'userVideoHistory',
  10. indexes: [
  11. {
  12. fields: [ 'userId', 'videoId' ],
  13. unique: true
  14. },
  15. {
  16. fields: [ 'userId' ]
  17. },
  18. {
  19. fields: [ 'videoId' ]
  20. }
  21. ]
  22. })
  23. export class UserVideoHistoryModel extends Model<Partial<AttributesOnly<UserVideoHistoryModel>>> {
  24. @CreatedAt
  25. createdAt: Date
  26. @UpdatedAt
  27. updatedAt: Date
  28. @AllowNull(false)
  29. @IsInt
  30. @Column
  31. currentTime: number
  32. @ForeignKey(() => VideoModel)
  33. @Column
  34. videoId: number
  35. @BelongsTo(() => VideoModel, {
  36. foreignKey: {
  37. allowNull: false
  38. },
  39. onDelete: 'CASCADE'
  40. })
  41. Video: VideoModel
  42. @ForeignKey(() => UserModel)
  43. @Column
  44. userId: number
  45. @BelongsTo(() => UserModel, {
  46. foreignKey: {
  47. allowNull: false
  48. },
  49. onDelete: 'CASCADE'
  50. })
  51. User: UserModel
  52. static listForApi (user: MUserAccountId, start: number, count: number, search?: string) {
  53. return VideoModel.listForApi({
  54. start,
  55. count,
  56. search,
  57. sort: '-"userVideoHistory"."updatedAt"',
  58. nsfw: null, // All
  59. displayOnlyForFollower: null,
  60. user,
  61. historyOfUser: user
  62. })
  63. }
  64. static removeUserHistoryBefore (user: MUserId, beforeDate: string, t: Transaction) {
  65. const query: DestroyOptions = {
  66. where: {
  67. userId: user.id
  68. },
  69. transaction: t
  70. }
  71. if (beforeDate) {
  72. query.where['updatedAt'] = {
  73. [Op.lt]: beforeDate
  74. }
  75. }
  76. return UserVideoHistoryModel.destroy(query)
  77. }
  78. static removeOldHistory (beforeDate: string) {
  79. const query: DestroyOptions = {
  80. where: {
  81. updatedAt: {
  82. [Op.lt]: beforeDate
  83. }
  84. }
  85. }
  86. return UserVideoHistoryModel.destroy(query)
  87. }
  88. }