url.ts 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. import { WEBSERVER } from '../../initializers/constants'
  2. import { ActorModel } from '../../models/activitypub/actor'
  3. import { ActorFollowModel } from '../../models/activitypub/actor-follow'
  4. import { VideoModel } from '../../models/video/video'
  5. import { VideoAbuseModel } from '../../models/video/video-abuse'
  6. import { VideoCommentModel } from '../../models/video/video-comment'
  7. import { VideoFileModel } from '../../models/video/video-file'
  8. import { VideoStreamingPlaylistModel } from '../../models/video/video-streaming-playlist'
  9. import { VideoPlaylistModel } from '../../models/video/video-playlist'
  10. function getVideoActivityPubUrl (video: VideoModel) {
  11. return WEBSERVER.URL + '/videos/watch/' + video.uuid
  12. }
  13. function getVideoPlaylistActivityPubUrl (videoPlaylist: VideoPlaylistModel) {
  14. return WEBSERVER.URL + '/video-playlists/' + videoPlaylist.uuid
  15. }
  16. function getVideoPlaylistElementActivityPubUrl (videoPlaylist: VideoPlaylistModel, video: VideoModel) {
  17. return WEBSERVER.URL + '/video-playlists/' + videoPlaylist.uuid + '/' + video.uuid
  18. }
  19. function getVideoCacheFileActivityPubUrl (videoFile: VideoFileModel) {
  20. const suffixFPS = videoFile.fps && videoFile.fps !== -1 ? '-' + videoFile.fps : ''
  21. return `${WEBSERVER.URL}/redundancy/videos/${videoFile.Video.uuid}/${videoFile.resolution}${suffixFPS}`
  22. }
  23. function getVideoCacheStreamingPlaylistActivityPubUrl (video: VideoModel, playlist: VideoStreamingPlaylistModel) {
  24. return `${WEBSERVER.URL}/redundancy/streaming-playlists/${playlist.getStringType()}/${video.uuid}`
  25. }
  26. function getVideoCommentActivityPubUrl (video: VideoModel, videoComment: VideoCommentModel) {
  27. return WEBSERVER.URL + '/videos/watch/' + video.uuid + '/comments/' + videoComment.id
  28. }
  29. function getVideoChannelActivityPubUrl (videoChannelName: string) {
  30. return WEBSERVER.URL + '/video-channels/' + videoChannelName
  31. }
  32. function getAccountActivityPubUrl (accountName: string) {
  33. return WEBSERVER.URL + '/accounts/' + accountName
  34. }
  35. function getVideoAbuseActivityPubUrl (videoAbuse: VideoAbuseModel) {
  36. return WEBSERVER.URL + '/admin/video-abuses/' + videoAbuse.id
  37. }
  38. function getVideoViewActivityPubUrl (byActor: ActorModel, video: VideoModel) {
  39. return byActor.url + '/views/videos/' + video.id + '/' + new Date().toISOString()
  40. }
  41. function getVideoLikeActivityPubUrl (byActor: ActorModel, video: VideoModel | { id: number }) {
  42. return byActor.url + '/likes/' + video.id
  43. }
  44. function getVideoDislikeActivityPubUrl (byActor: ActorModel, video: VideoModel | { id: number }) {
  45. return byActor.url + '/dislikes/' + video.id
  46. }
  47. function getVideoSharesActivityPubUrl (video: VideoModel) {
  48. return video.url + '/announces'
  49. }
  50. function getVideoCommentsActivityPubUrl (video: VideoModel) {
  51. return video.url + '/comments'
  52. }
  53. function getVideoLikesActivityPubUrl (video: VideoModel) {
  54. return video.url + '/likes'
  55. }
  56. function getVideoDislikesActivityPubUrl (video: VideoModel) {
  57. return video.url + '/dislikes'
  58. }
  59. function getActorFollowActivityPubUrl (follower: ActorModel, following: ActorModel) {
  60. return follower.url + '/follows/' + following.id
  61. }
  62. function getActorFollowAcceptActivityPubUrl (actorFollow: ActorFollowModel) {
  63. const follower = actorFollow.ActorFollower
  64. const me = actorFollow.ActorFollowing
  65. return follower.url + '/accepts/follows/' + me.id
  66. }
  67. function getActorFollowRejectActivityPubUrl (follower: ActorModel, following: ActorModel) {
  68. return follower.url + '/rejects/follows/' + following.id
  69. }
  70. function getVideoAnnounceActivityPubUrl (byActor: ActorModel, video: VideoModel) {
  71. return video.url + '/announces/' + byActor.id
  72. }
  73. function getDeleteActivityPubUrl (originalUrl: string) {
  74. return originalUrl + '/delete'
  75. }
  76. function getUpdateActivityPubUrl (originalUrl: string, updatedAt: string) {
  77. return originalUrl + '/updates/' + updatedAt
  78. }
  79. function getUndoActivityPubUrl (originalUrl: string) {
  80. return originalUrl + '/undo'
  81. }
  82. export {
  83. getVideoActivityPubUrl,
  84. getVideoPlaylistElementActivityPubUrl,
  85. getVideoPlaylistActivityPubUrl,
  86. getVideoCacheStreamingPlaylistActivityPubUrl,
  87. getVideoChannelActivityPubUrl,
  88. getAccountActivityPubUrl,
  89. getVideoAbuseActivityPubUrl,
  90. getActorFollowActivityPubUrl,
  91. getActorFollowAcceptActivityPubUrl,
  92. getVideoAnnounceActivityPubUrl,
  93. getUpdateActivityPubUrl,
  94. getUndoActivityPubUrl,
  95. getVideoViewActivityPubUrl,
  96. getVideoLikeActivityPubUrl,
  97. getVideoDislikeActivityPubUrl,
  98. getActorFollowRejectActivityPubUrl,
  99. getVideoCommentActivityPubUrl,
  100. getDeleteActivityPubUrl,
  101. getVideoSharesActivityPubUrl,
  102. getVideoCommentsActivityPubUrl,
  103. getVideoLikesActivityPubUrl,
  104. getVideoDislikesActivityPubUrl,
  105. getVideoCacheFileActivityPubUrl
  106. }