url.ts 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. import { WEBSERVER } from '../../initializers/constants'
  2. import {
  3. MAbuseId,
  4. MActor,
  5. MActorFollowActors,
  6. MActorId,
  7. MActorUrl,
  8. MCommentId,
  9. MVideoId,
  10. MVideoPlaylistElement,
  11. MVideoUrl,
  12. MVideoUUID
  13. } from '../../types/models'
  14. import { MVideoFileVideoUUID } from '../../types/models/video/video-file'
  15. import { MVideoPlaylist, MVideoPlaylistUUID } from '../../types/models/video/video-playlist'
  16. import { MStreamingPlaylist } from '../../types/models/video/video-streaming-playlist'
  17. function getLocalVideoActivityPubUrl (video: MVideoUUID) {
  18. return WEBSERVER.URL + '/videos/watch/' + video.uuid
  19. }
  20. function getLocalVideoPlaylistActivityPubUrl (videoPlaylist: MVideoPlaylist) {
  21. return WEBSERVER.URL + '/video-playlists/' + videoPlaylist.uuid
  22. }
  23. function getLocalVideoPlaylistElementActivityPubUrl (videoPlaylist: MVideoPlaylistUUID, videoPlaylistElement: MVideoPlaylistElement) {
  24. return WEBSERVER.URL + '/video-playlists/' + videoPlaylist.uuid + '/videos/' + videoPlaylistElement.id
  25. }
  26. function getLocalVideoCacheFileActivityPubUrl (videoFile: MVideoFileVideoUUID) {
  27. const suffixFPS = videoFile.fps && videoFile.fps !== -1 ? '-' + videoFile.fps : ''
  28. return `${WEBSERVER.URL}/redundancy/videos/${videoFile.Video.uuid}/${videoFile.resolution}${suffixFPS}`
  29. }
  30. function getLocalVideoCacheStreamingPlaylistActivityPubUrl (video: MVideoUUID, playlist: MStreamingPlaylist) {
  31. return `${WEBSERVER.URL}/redundancy/streaming-playlists/${playlist.getStringType()}/${video.uuid}`
  32. }
  33. function getLocalVideoCommentActivityPubUrl (video: MVideoUUID, videoComment: MCommentId) {
  34. return WEBSERVER.URL + '/videos/watch/' + video.uuid + '/comments/' + videoComment.id
  35. }
  36. function getLocalVideoChannelActivityPubUrl (videoChannelName: string) {
  37. return WEBSERVER.URL + '/video-channels/' + videoChannelName
  38. }
  39. function getLocalAccountActivityPubUrl (accountName: string) {
  40. return WEBSERVER.URL + '/accounts/' + accountName
  41. }
  42. function getLocalAbuseActivityPubUrl (abuse: MAbuseId) {
  43. return WEBSERVER.URL + '/admin/abuses/' + abuse.id
  44. }
  45. function getLocalVideoViewActivityPubUrl (byActor: MActorUrl, video: MVideoId) {
  46. return byActor.url + '/views/videos/' + video.id + '/' + new Date().toISOString()
  47. }
  48. function getVideoLikeActivityPubUrlByLocalActor (byActor: MActorUrl, video: MVideoId) {
  49. return byActor.url + '/likes/' + video.id
  50. }
  51. function getVideoDislikeActivityPubUrlByLocalActor (byActor: MActorUrl, video: MVideoId) {
  52. return byActor.url + '/dislikes/' + video.id
  53. }
  54. function getLocalVideoSharesActivityPubUrl (video: MVideoUrl) {
  55. return video.url + '/announces'
  56. }
  57. function getLocalVideoCommentsActivityPubUrl (video: MVideoUrl) {
  58. return video.url + '/comments'
  59. }
  60. function getLocalVideoLikesActivityPubUrl (video: MVideoUrl) {
  61. return video.url + '/likes'
  62. }
  63. function getLocalVideoDislikesActivityPubUrl (video: MVideoUrl) {
  64. return video.url + '/dislikes'
  65. }
  66. function getLocalActorFollowActivityPubUrl (follower: MActor, following: MActorId) {
  67. return follower.url + '/follows/' + following.id
  68. }
  69. function getLocalActorFollowAcceptActivityPubUrl (actorFollow: MActorFollowActors) {
  70. const follower = actorFollow.ActorFollower
  71. const me = actorFollow.ActorFollowing
  72. return WEBSERVER.URL + '/accepts/follows/' + follower.id + '/' + me.id
  73. }
  74. function getLocalActorFollowRejectActivityPubUrl (follower: MActorId, following: MActorId) {
  75. return WEBSERVER.URL + '/rejects/follows/' + follower.id + '/' + following.id
  76. }
  77. function getLocalVideoAnnounceActivityPubUrl (byActor: MActorId, video: MVideoUrl) {
  78. return video.url + '/announces/' + byActor.id
  79. }
  80. function getDeleteActivityPubUrl (originalUrl: string) {
  81. return originalUrl + '/delete'
  82. }
  83. function getUpdateActivityPubUrl (originalUrl: string, updatedAt: string) {
  84. return originalUrl + '/updates/' + updatedAt
  85. }
  86. function getUndoActivityPubUrl (originalUrl: string) {
  87. return originalUrl + '/undo'
  88. }
  89. export {
  90. getLocalVideoActivityPubUrl,
  91. getLocalVideoPlaylistActivityPubUrl,
  92. getLocalVideoPlaylistElementActivityPubUrl,
  93. getLocalVideoCacheFileActivityPubUrl,
  94. getLocalVideoCacheStreamingPlaylistActivityPubUrl,
  95. getLocalVideoCommentActivityPubUrl,
  96. getLocalVideoChannelActivityPubUrl,
  97. getLocalAccountActivityPubUrl,
  98. getLocalAbuseActivityPubUrl,
  99. getLocalActorFollowActivityPubUrl,
  100. getLocalActorFollowAcceptActivityPubUrl,
  101. getLocalVideoAnnounceActivityPubUrl,
  102. getUpdateActivityPubUrl,
  103. getUndoActivityPubUrl,
  104. getVideoLikeActivityPubUrlByLocalActor,
  105. getLocalVideoViewActivityPubUrl,
  106. getVideoDislikeActivityPubUrlByLocalActor,
  107. getLocalActorFollowRejectActivityPubUrl,
  108. getDeleteActivityPubUrl,
  109. getLocalVideoSharesActivityPubUrl,
  110. getLocalVideoCommentsActivityPubUrl,
  111. getLocalVideoLikesActivityPubUrl,
  112. getLocalVideoDislikesActivityPubUrl
  113. }