ニジカ投稿局 https://tv.nizika.tv
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.
 
 
 
 
 

57 lines
1.8 KiB

  1. import { VideoCommentPolicy, VideoCommentPolicyType } from '@peertube/peertube-models'
  2. import { CONFIG } from '@server/initializers/config.js'
  3. import { MEMOIZE_LENGTH, MEMOIZE_TTL } from '@server/initializers/constants.js'
  4. import { TagModel } from '@server/models/video/tag.js'
  5. import { VideoModel } from '@server/models/video/video.js'
  6. import { MVideoTag } from '@server/types/models/index.js'
  7. import memoizee from 'memoizee'
  8. import { Transaction } from 'sequelize'
  9. // ---------------------------------------------------------------------------
  10. export async function setVideoTags (options: {
  11. video: MVideoTag
  12. tags: string[]
  13. transaction?: Transaction
  14. }) {
  15. const { video, tags, transaction } = options
  16. const internalTags = tags || []
  17. const tagInstances = await TagModel.findOrCreateMultiple({ tags: internalTags, transaction })
  18. await video.$set('Tags', tagInstances, { transaction })
  19. video.Tags = tagInstances
  20. }
  21. // ---------------------------------------------------------------------------
  22. async function getVideoDuration (videoId: number | string) {
  23. const video = await VideoModel.load(videoId)
  24. const duration = video.isLive
  25. ? undefined
  26. : video.duration
  27. return { duration, isLive: video.isLive }
  28. }
  29. export const getCachedVideoDuration = memoizee(getVideoDuration, {
  30. promise: true,
  31. max: MEMOIZE_LENGTH.VIDEO_DURATION,
  32. maxAge: MEMOIZE_TTL.VIDEO_DURATION
  33. })
  34. // ---------------------------------------------------------------------------
  35. export function buildCommentsPolicy (options: {
  36. commentsEnabled?: boolean
  37. commentsPolicy?: VideoCommentPolicyType
  38. }) {
  39. if (options.commentsPolicy) return options.commentsPolicy
  40. if (options.commentsEnabled === true) return VideoCommentPolicy.ENABLED
  41. if (options.commentsEnabled === false) return VideoCommentPolicy.DISABLED
  42. return CONFIG.DEFAULTS.PUBLISH.COMMENTS_POLICY
  43. }