aboutsummaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
Diffstat (limited to 'server')
-rw-r--r--server/controllers/api/search/search-video-channels.ts3
-rw-r--r--server/controllers/api/search/search-video-playlists.ts3
-rw-r--r--server/controllers/api/search/search-videos.ts3
-rw-r--r--server/controllers/api/search/shared/index.ts1
-rw-r--r--server/controllers/api/search/shared/utils.ts16
-rw-r--r--server/helpers/express-utils.ts2
-rw-r--r--server/lib/activitypub/playlists/get.ts2
-rw-r--r--server/tests/api/search/search-activitypub-video-channels.ts39
-rw-r--r--server/tests/api/search/search-activitypub-video-playlists.ts39
-rw-r--r--server/tests/api/search/search-activitypub-videos.ts34
10 files changed, 109 insertions, 33 deletions
diff --git a/server/controllers/api/search/search-video-channels.ts b/server/controllers/api/search/search-video-channels.ts
index 089feed65..c9e81bffa 100644
--- a/server/controllers/api/search/search-video-channels.ts
+++ b/server/controllers/api/search/search-video-channels.ts
@@ -25,6 +25,7 @@ import {
25} from '../../../middlewares' 25} from '../../../middlewares'
26import { VideoChannelModel } from '../../../models/video/video-channel' 26import { VideoChannelModel } from '../../../models/video/video-channel'
27import { MChannelAccountDefault } from '../../../types/models' 27import { MChannelAccountDefault } from '../../../types/models'
28import { searchLocalUrl } from './shared'
28 29
29const searchChannelsRouter = express.Router() 30const searchChannelsRouter = express.Router()
30 31
@@ -131,7 +132,7 @@ async function searchVideoChannelURI (search: string, isWebfingerSearch: boolean
131 logger.info('Cannot search remote video channel %s.', uri, { err }) 132 logger.info('Cannot search remote video channel %s.', uri, { err })
132 } 133 }
133 } else { 134 } else {
134 videoChannel = await VideoChannelModel.loadByUrlAndPopulateAccount(sanitizeLocalUrl(uri)) 135 videoChannel = await searchLocalUrl(sanitizeLocalUrl(uri), url => VideoChannelModel.loadByUrlAndPopulateAccount(url))
135 } 136 }
136 137
137 return res.json({ 138 return res.json({
diff --git a/server/controllers/api/search/search-video-playlists.ts b/server/controllers/api/search/search-video-playlists.ts
index b28f11c79..61a11c74a 100644
--- a/server/controllers/api/search/search-video-playlists.ts
+++ b/server/controllers/api/search/search-video-playlists.ts
@@ -24,6 +24,7 @@ import {
24 videoPlaylistsListSearchValidator, 24 videoPlaylistsListSearchValidator,
25 videoPlaylistsSearchSortValidator 25 videoPlaylistsSearchSortValidator
26} from '../../../middlewares' 26} from '../../../middlewares'
27import { searchLocalUrl } from './shared'
27 28
28const searchPlaylistsRouter = express.Router() 29const searchPlaylistsRouter = express.Router()
29 30
@@ -109,7 +110,7 @@ async function searchVideoPlaylistsURI (search: string, res: express.Response) {
109 logger.info('Cannot search remote video playlist %s.', search, { err }) 110 logger.info('Cannot search remote video playlist %s.', search, { err })
110 } 111 }
111 } else { 112 } else {
112 videoPlaylist = await VideoPlaylistModel.loadByUrlWithAccountAndChannelSummary(sanitizeLocalUrl(search)) 113 videoPlaylist = await searchLocalUrl(sanitizeLocalUrl(search), url => VideoPlaylistModel.loadByUrlWithAccountAndChannelSummary(url))
113 } 114 }
114 115
115 return res.json({ 116 return res.json({
diff --git a/server/controllers/api/search/search-videos.ts b/server/controllers/api/search/search-videos.ts
index eb7ce0841..90946cb74 100644
--- a/server/controllers/api/search/search-videos.ts
+++ b/server/controllers/api/search/search-videos.ts
@@ -25,6 +25,7 @@ import {
25} from '../../../middlewares' 25} from '../../../middlewares'
26import { VideoModel } from '../../../models/video/video' 26import { VideoModel } from '../../../models/video/video'
27import { MVideoAccountLightBlacklistAllFiles } from '../../../types/models' 27import { MVideoAccountLightBlacklistAllFiles } from '../../../types/models'
28import { searchLocalUrl } from './shared'
28 29
29const searchVideosRouter = express.Router() 30const searchVideosRouter = express.Router()
30 31
@@ -141,7 +142,7 @@ async function searchVideoURI (url: string, res: express.Response) {
141 logger.info('Cannot search remote video %s.', url, { err }) 142 logger.info('Cannot search remote video %s.', url, { err })
142 } 143 }
143 } else { 144 } else {
144 video = await VideoModel.loadByUrlAndPopulateAccount(sanitizeLocalUrl(url)) 145 video = await searchLocalUrl(sanitizeLocalUrl(url), url => VideoModel.loadByUrlAndPopulateAccount(url))
145 } 146 }
146 147
147 return res.json({ 148 return res.json({
diff --git a/server/controllers/api/search/shared/index.ts b/server/controllers/api/search/shared/index.ts
new file mode 100644
index 000000000..9c56149ef
--- /dev/null
+++ b/server/controllers/api/search/shared/index.ts
@@ -0,0 +1 @@
export * from './utils'
diff --git a/server/controllers/api/search/shared/utils.ts b/server/controllers/api/search/shared/utils.ts
new file mode 100644
index 000000000..e02e84f31
--- /dev/null
+++ b/server/controllers/api/search/shared/utils.ts
@@ -0,0 +1,16 @@
1async function searchLocalUrl <T> (url: string, finder: (url: string) => Promise<T>) {
2 const data = await finder(url)
3 if (data) return data
4
5 return finder(removeQueryParams(url))
6}
7
8export {
9 searchLocalUrl
10}
11
12// ---------------------------------------------------------------------------
13
14function removeQueryParams (url: string) {
15 return url.split('?').shift()
16}
diff --git a/server/helpers/express-utils.ts b/server/helpers/express-utils.ts
index 38fe6926b..7b81ed71b 100644
--- a/server/helpers/express-utils.ts
+++ b/server/helpers/express-utils.ts
@@ -59,7 +59,7 @@ function getHostWithPort (host: string) {
59 return host 59 return host
60} 60}
61 61
62function badRequest (req: express.Request, res: express.Response) { 62function badRequest (_req: express.Request, res: express.Response) {
63 return res.type('json') 63 return res.type('json')
64 .status(HttpStatusCode.BAD_REQUEST_400) 64 .status(HttpStatusCode.BAD_REQUEST_400)
65 .end() 65 .end()
diff --git a/server/lib/activitypub/playlists/get.ts b/server/lib/activitypub/playlists/get.ts
index 2c19c503a..be8456b19 100644
--- a/server/lib/activitypub/playlists/get.ts
+++ b/server/lib/activitypub/playlists/get.ts
@@ -20,7 +20,7 @@ async function getOrCreateAPVideoPlaylist (playlistObjectArg: APObject): Promise
20 const { playlistObject } = await fetchRemoteVideoPlaylist(playlistUrl) 20 const { playlistObject } = await fetchRemoteVideoPlaylist(playlistUrl)
21 if (!playlistObject) throw new Error('Cannot fetch remote playlist with url: ' + playlistUrl) 21 if (!playlistObject) throw new Error('Cannot fetch remote playlist with url: ' + playlistUrl)
22 22
23 // playlistUrl is just an alias/rediraction, so process object id instead 23 // playlistUrl is just an alias/redirection, so process object id instead
24 if (playlistObject.id !== playlistUrl) return getOrCreateAPVideoPlaylist(playlistObject) 24 if (playlistObject.id !== playlistUrl) return getOrCreateAPVideoPlaylist(playlistObject)
25 25
26 const playlistCreated = await createOrUpdateVideoPlaylist(playlistObject) 26 const playlistCreated = await createOrUpdateVideoPlaylist(playlistObject)
diff --git a/server/tests/api/search/search-activitypub-video-channels.ts b/server/tests/api/search/search-activitypub-video-channels.ts
index 426cbc8e1..efcdb33dc 100644
--- a/server/tests/api/search/search-activitypub-video-channels.ts
+++ b/server/tests/api/search/search-activitypub-video-channels.ts
@@ -64,7 +64,7 @@ describe('Test ActivityPub video channels search', function () {
64 this.timeout(15000) 64 this.timeout(15000)
65 65
66 { 66 {
67 const search = 'http://localhost:' + servers[1].port + '/video-channels/channel1_server3' 67 const search = servers[1].url + '/video-channels/channel1_server3'
68 const body = await command.searchChannels({ search, token: servers[0].accessToken }) 68 const body = await command.searchChannels({ search, token: servers[0].accessToken })
69 69
70 expect(body.total).to.equal(0) 70 expect(body.total).to.equal(0)
@@ -74,7 +74,7 @@ describe('Test ActivityPub video channels search', function () {
74 74
75 { 75 {
76 // Without token 76 // Without token
77 const search = 'http://localhost:' + servers[1].port + '/video-channels/channel1_server2' 77 const search = servers[1].url + '/video-channels/channel1_server2'
78 const body = await command.searchChannels({ search }) 78 const body = await command.searchChannels({ search })
79 79
80 expect(body.total).to.equal(0) 80 expect(body.total).to.equal(0)
@@ -85,7 +85,7 @@ describe('Test ActivityPub video channels search', function () {
85 85
86 it('Should search a local video channel', async function () { 86 it('Should search a local video channel', async function () {
87 const searches = [ 87 const searches = [
88 'http://localhost:' + servers[0].port + '/video-channels/channel1_server1', 88 servers[0].url + '/video-channels/channel1_server1',
89 'channel1_server1@localhost:' + servers[0].port 89 'channel1_server1@localhost:' + servers[0].port
90 ] 90 ]
91 91
@@ -101,7 +101,7 @@ describe('Test ActivityPub video channels search', function () {
101 }) 101 })
102 102
103 it('Should search a local video channel with an alternative URL', async function () { 103 it('Should search a local video channel with an alternative URL', async function () {
104 const search = 'http://localhost:' + servers[0].port + '/c/channel1_server1' 104 const search = servers[0].url + '/c/channel1_server1'
105 105
106 for (const token of [ undefined, servers[0].accessToken ]) { 106 for (const token of [ undefined, servers[0].accessToken ]) {
107 const body = await command.searchChannels({ search, token }) 107 const body = await command.searchChannels({ search, token })
@@ -114,11 +114,30 @@ describe('Test ActivityPub video channels search', function () {
114 } 114 }
115 }) 115 })
116 116
117 it('Should search a local video channel with a query in URL', async function () {
118 const searches = [
119 servers[0].url + '/video-channels/channel1_server1',
120 servers[0].url + '/c/channel1_server1'
121 ]
122
123 for (const search of searches) {
124 for (const token of [ undefined, servers[0].accessToken ]) {
125 const body = await command.searchChannels({ search: search + '?param=2', token })
126
127 expect(body.total).to.equal(1)
128 expect(body.data).to.be.an('array')
129 expect(body.data).to.have.lengthOf(1)
130 expect(body.data[0].name).to.equal('channel1_server1')
131 expect(body.data[0].displayName).to.equal('Channel 1 server 1')
132 }
133 }
134 })
135
117 it('Should search a remote video channel with URL or handle', async function () { 136 it('Should search a remote video channel with URL or handle', async function () {
118 const searches = [ 137 const searches = [
119 'http://localhost:' + servers[1].port + '/video-channels/channel1_server2', 138 servers[1].url + '/video-channels/channel1_server2',
120 'http://localhost:' + servers[1].port + '/c/channel1_server2', 139 servers[1].url + '/c/channel1_server2',
121 'http://localhost:' + servers[1].port + '/c/channel1_server2/videos', 140 servers[1].url + '/c/channel1_server2/videos',
122 'channel1_server2@localhost:' + servers[1].port 141 'channel1_server2@localhost:' + servers[1].port
123 ] 142 ]
124 143
@@ -178,7 +197,7 @@ describe('Test ActivityPub video channels search', function () {
178 // Expire video channel 197 // Expire video channel
179 await wait(10000) 198 await wait(10000)
180 199
181 const search = 'http://localhost:' + servers[1].port + '/video-channels/channel1_server2' 200 const search = servers[1].url + '/video-channels/channel1_server2'
182 const body = await command.searchChannels({ search, token: servers[0].accessToken }) 201 const body = await command.searchChannels({ search, token: servers[0].accessToken })
183 expect(body.total).to.equal(1) 202 expect(body.total).to.equal(1)
184 expect(body.data).to.have.lengthOf(1) 203 expect(body.data).to.have.lengthOf(1)
@@ -201,7 +220,7 @@ describe('Test ActivityPub video channels search', function () {
201 // Expire video channel 220 // Expire video channel
202 await wait(10000) 221 await wait(10000)
203 222
204 const search = 'http://localhost:' + servers[1].port + '/video-channels/channel1_server2' 223 const search = servers[1].url + '/video-channels/channel1_server2'
205 await command.searchChannels({ search, token: servers[0].accessToken }) 224 await command.searchChannels({ search, token: servers[0].accessToken })
206 225
207 await waitJobs(servers) 226 await waitJobs(servers)
@@ -223,7 +242,7 @@ describe('Test ActivityPub video channels search', function () {
223 // Expire video 242 // Expire video
224 await wait(10000) 243 await wait(10000)
225 244
226 const search = 'http://localhost:' + servers[1].port + '/video-channels/channel1_server2' 245 const search = servers[1].url + '/video-channels/channel1_server2'
227 const body = await command.searchChannels({ search, token: servers[0].accessToken }) 246 const body = await command.searchChannels({ search, token: servers[0].accessToken })
228 expect(body.total).to.equal(0) 247 expect(body.total).to.equal(0)
229 expect(body.data).to.have.lengthOf(0) 248 expect(body.data).to.have.lengthOf(0)
diff --git a/server/tests/api/search/search-activitypub-video-playlists.ts b/server/tests/api/search/search-activitypub-video-playlists.ts
index 33ca7be12..34b318268 100644
--- a/server/tests/api/search/search-activitypub-video-playlists.ts
+++ b/server/tests/api/search/search-activitypub-video-playlists.ts
@@ -71,7 +71,7 @@ describe('Test ActivityPub playlists search', function () {
71 71
72 it('Should not find a remote playlist', async function () { 72 it('Should not find a remote playlist', async function () {
73 { 73 {
74 const search = 'http://localhost:' + servers[1].port + '/video-playlists/43' 74 const search = servers[1].url + '/video-playlists/43'
75 const body = await command.searchPlaylists({ search, token: servers[0].accessToken }) 75 const body = await command.searchPlaylists({ search, token: servers[0].accessToken })
76 76
77 expect(body.total).to.equal(0) 77 expect(body.total).to.equal(0)
@@ -81,7 +81,7 @@ describe('Test ActivityPub playlists search', function () {
81 81
82 { 82 {
83 // Without token 83 // Without token
84 const search = 'http://localhost:' + servers[1].port + '/video-playlists/' + playlistServer2UUID 84 const search = servers[1].url + '/video-playlists/' + playlistServer2UUID
85 const body = await command.searchPlaylists({ search }) 85 const body = await command.searchPlaylists({ search })
86 86
87 expect(body.total).to.equal(0) 87 expect(body.total).to.equal(0)
@@ -91,7 +91,7 @@ describe('Test ActivityPub playlists search', function () {
91 }) 91 })
92 92
93 it('Should search a local playlist', async function () { 93 it('Should search a local playlist', async function () {
94 const search = 'http://localhost:' + servers[0].port + '/video-playlists/' + playlistServer1UUID 94 const search = servers[0].url + '/video-playlists/' + playlistServer1UUID
95 const body = await command.searchPlaylists({ search }) 95 const body = await command.searchPlaylists({ search })
96 96
97 expect(body.total).to.equal(1) 97 expect(body.total).to.equal(1)
@@ -103,8 +103,8 @@ describe('Test ActivityPub playlists search', function () {
103 103
104 it('Should search a local playlist with an alternative URL', async function () { 104 it('Should search a local playlist with an alternative URL', async function () {
105 const searches = [ 105 const searches = [
106 'http://localhost:' + servers[0].port + '/videos/watch/playlist/' + playlistServer1UUID, 106 servers[0].url + '/videos/watch/playlist/' + playlistServer1UUID,
107 'http://localhost:' + servers[0].port + '/w/p/' + playlistServer1UUID 107 servers[0].url + '/w/p/' + playlistServer1UUID
108 ] 108 ]
109 109
110 for (const search of searches) { 110 for (const search of searches) {
@@ -120,11 +120,30 @@ describe('Test ActivityPub playlists search', function () {
120 } 120 }
121 }) 121 })
122 122
123 it('Should search a local playlist with a query in URL', async function () {
124 const searches = [
125 servers[0].url + '/videos/watch/playlist/' + playlistServer1UUID,
126 servers[0].url + '/w/p/' + playlistServer1UUID
127 ]
128
129 for (const search of searches) {
130 for (const token of [ undefined, servers[0].accessToken ]) {
131 const body = await command.searchPlaylists({ search: search + '?param=1', token })
132
133 expect(body.total).to.equal(1)
134 expect(body.data).to.be.an('array')
135 expect(body.data).to.have.lengthOf(1)
136 expect(body.data[0].displayName).to.equal('playlist 1 on server 1')
137 expect(body.data[0].videosLength).to.equal(2)
138 }
139 }
140 })
141
123 it('Should search a remote playlist', async function () { 142 it('Should search a remote playlist', async function () {
124 const searches = [ 143 const searches = [
125 'http://localhost:' + servers[1].port + '/video-playlists/' + playlistServer2UUID, 144 servers[1].url + '/video-playlists/' + playlistServer2UUID,
126 'http://localhost:' + servers[1].port + '/videos/watch/playlist/' + playlistServer2UUID, 145 servers[1].url + '/videos/watch/playlist/' + playlistServer2UUID,
127 'http://localhost:' + servers[1].port + '/w/p/' + playlistServer2UUID 146 servers[1].url + '/w/p/' + playlistServer2UUID
128 ] 147 ]
129 148
130 for (const search of searches) { 149 for (const search of searches) {
@@ -155,7 +174,7 @@ describe('Test ActivityPub playlists search', function () {
155 await wait(10000) 174 await wait(10000)
156 175
157 // Will run refresh async 176 // Will run refresh async
158 const search = 'http://localhost:' + servers[1].port + '/video-playlists/' + playlistServer2UUID 177 const search = servers[1].url + '/video-playlists/' + playlistServer2UUID
159 await command.searchPlaylists({ search, token: servers[0].accessToken }) 178 await command.searchPlaylists({ search, token: servers[0].accessToken })
160 179
161 // Wait refresh 180 // Wait refresh
@@ -179,7 +198,7 @@ describe('Test ActivityPub playlists search', function () {
179 await wait(10000) 198 await wait(10000)
180 199
181 // Will run refresh async 200 // Will run refresh async
182 const search = 'http://localhost:' + servers[1].port + '/video-playlists/' + playlistServer2UUID 201 const search = servers[1].url + '/video-playlists/' + playlistServer2UUID
183 await command.searchPlaylists({ search, token: servers[0].accessToken }) 202 await command.searchPlaylists({ search, token: servers[0].accessToken })
184 203
185 // Wait refresh 204 // Wait refresh
diff --git a/server/tests/api/search/search-activitypub-videos.ts b/server/tests/api/search/search-activitypub-videos.ts
index b3cfcacca..a2e6e70fe 100644
--- a/server/tests/api/search/search-activitypub-videos.ts
+++ b/server/tests/api/search/search-activitypub-videos.ts
@@ -46,7 +46,7 @@ describe('Test ActivityPub videos search', function () {
46 46
47 it('Should not find a remote video', async function () { 47 it('Should not find a remote video', async function () {
48 { 48 {
49 const search = 'http://localhost:' + servers[1].port + '/videos/watch/43' 49 const search = servers[1].url + '/videos/watch/43'
50 const body = await command.searchVideos({ search, token: servers[0].accessToken }) 50 const body = await command.searchVideos({ search, token: servers[0].accessToken })
51 51
52 expect(body.total).to.equal(0) 52 expect(body.total).to.equal(0)
@@ -56,7 +56,7 @@ describe('Test ActivityPub videos search', function () {
56 56
57 { 57 {
58 // Without token 58 // Without token
59 const search = 'http://localhost:' + servers[1].port + '/videos/watch/' + videoServer2UUID 59 const search = servers[1].url + '/videos/watch/' + videoServer2UUID
60 const body = await command.searchVideos({ search }) 60 const body = await command.searchVideos({ search })
61 61
62 expect(body.total).to.equal(0) 62 expect(body.total).to.equal(0)
@@ -66,7 +66,7 @@ describe('Test ActivityPub videos search', function () {
66 }) 66 })
67 67
68 it('Should search a local video', async function () { 68 it('Should search a local video', async function () {
69 const search = 'http://localhost:' + servers[0].port + '/videos/watch/' + videoServer1UUID 69 const search = servers[0].url + '/videos/watch/' + videoServer1UUID
70 const body = await command.searchVideos({ search }) 70 const body = await command.searchVideos({ search })
71 71
72 expect(body.total).to.equal(1) 72 expect(body.total).to.equal(1)
@@ -76,7 +76,7 @@ describe('Test ActivityPub videos search', function () {
76 }) 76 })
77 77
78 it('Should search a local video with an alternative URL', async function () { 78 it('Should search a local video with an alternative URL', async function () {
79 const search = 'http://localhost:' + servers[0].port + '/w/' + videoServer1UUID 79 const search = servers[0].url + '/w/' + videoServer1UUID
80 const body1 = await command.searchVideos({ search }) 80 const body1 = await command.searchVideos({ search })
81 const body2 = await command.searchVideos({ search, token: servers[0].accessToken }) 81 const body2 = await command.searchVideos({ search, token: servers[0].accessToken })
82 82
@@ -88,10 +88,28 @@ describe('Test ActivityPub videos search', function () {
88 } 88 }
89 }) 89 })
90 90
91 it('Should search a local video with a query in URL', async function () {
92 const searches = [
93 servers[0].url + '/w/' + videoServer1UUID,
94 servers[0].url + '/videos/watch/' + videoServer1UUID
95 ]
96
97 for (const search of searches) {
98 for (const token of [ undefined, servers[0].accessToken ]) {
99 const body = await command.searchVideos({ search: search + '?startTime=4', token })
100
101 expect(body.total).to.equal(1)
102 expect(body.data).to.be.an('array')
103 expect(body.data).to.have.lengthOf(1)
104 expect(body.data[0].name).to.equal('video 1 on server 1')
105 }
106 }
107 })
108
91 it('Should search a remote video', async function () { 109 it('Should search a remote video', async function () {
92 const searches = [ 110 const searches = [
93 'http://localhost:' + servers[1].port + '/w/' + videoServer2UUID, 111 servers[1].url + '/w/' + videoServer2UUID,
94 'http://localhost:' + servers[1].port + '/videos/watch/' + videoServer2UUID 112 servers[1].url + '/videos/watch/' + videoServer2UUID
95 ] 113 ]
96 114
97 for (const search of searches) { 115 for (const search of searches) {
@@ -134,7 +152,7 @@ describe('Test ActivityPub videos search', function () {
134 await wait(10000) 152 await wait(10000)
135 153
136 // Will run refresh async 154 // Will run refresh async
137 const search = 'http://localhost:' + servers[1].port + '/videos/watch/' + videoServer2UUID 155 const search = servers[1].url + '/videos/watch/' + videoServer2UUID
138 await command.searchVideos({ search, token: servers[0].accessToken }) 156 await command.searchVideos({ search, token: servers[0].accessToken })
139 157
140 // Wait refresh 158 // Wait refresh
@@ -160,7 +178,7 @@ describe('Test ActivityPub videos search', function () {
160 await wait(10000) 178 await wait(10000)
161 179
162 // Will run refresh async 180 // Will run refresh async
163 const search = 'http://localhost:' + servers[1].port + '/videos/watch/' + videoServer2UUID 181 const search = servers[1].url + '/videos/watch/' + videoServer2UUID
164 await command.searchVideos({ search, token: servers[0].accessToken }) 182 await command.searchVideos({ search, token: servers[0].accessToken })
165 183
166 // Wait refresh 184 // Wait refresh