aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2020-06-12 16:24:58 +0200
committerChocobozzz <me@florianbigard.com>2020-06-12 16:27:41 +0200
commit1a40132c67e50c94a7bd3f6b63c075f471b3d6cc (patch)
tree95e4c4c36fcff9eab74648dd3bfb0f33dae9e0e9
parent5a61ffbb7c72dd7ecfa16c7944dac45411c1bbe9 (diff)
downloadPeerTube-1a40132c67e50c94a7bd3f6b63c075f471b3d6cc.tar.gz
PeerTube-1a40132c67e50c94a7bd3f6b63c075f471b3d6cc.tar.zst
PeerTube-1a40132c67e50c94a7bd3f6b63c075f471b3d6cc.zip
Use default nsfw instance policy for search index
-rw-r--r--server/controllers/api/search.ts9
-rw-r--r--server/tests/api/search/search-index.ts31
2 files changed, 39 insertions, 1 deletions
diff --git a/server/controllers/api/search.ts b/server/controllers/api/search.ts
index 1dea77d29..e35a7346e 100644
--- a/server/controllers/api/search.ts
+++ b/server/controllers/api/search.ts
@@ -169,7 +169,14 @@ async function searchVideosIndex (query: VideosSearchQuery, res: express.Respons
169 169
170 const result = await buildMutedForSearchIndex(res) 170 const result = await buildMutedForSearchIndex(res)
171 171
172 const body = Object.assign(query, result) 172 const body: VideosSearchQuery = Object.assign(query, result)
173
174 // Use the default instance NSFW policy if not specified
175 if (!body.nsfw) {
176 body.nsfw = CONFIG.INSTANCE.DEFAULT_NSFW_POLICY === 'do_not_list'
177 ? 'false'
178 : 'both'
179 }
173 180
174 const url = sanitizeUrl(CONFIG.SEARCH.SEARCH_INDEX.URL) + '/api/v1/search/videos' 181 const url = sanitizeUrl(CONFIG.SEARCH.SEARCH_INDEX.URL) + '/api/v1/search/videos'
175 182
diff --git a/server/tests/api/search/search-index.ts b/server/tests/api/search/search-index.ts
index 2354aaa8b..40065d162 100644
--- a/server/tests/api/search/search-index.ts
+++ b/server/tests/api/search/search-index.ts
@@ -209,6 +209,37 @@ describe('Test videos search', function () {
209 expect(res.body.total).to.be.greaterThan(5) 209 expect(res.body.total).to.be.greaterThan(5)
210 expect(res.body.data).to.have.lengthOf(5) 210 expect(res.body.data).to.have.lengthOf(5)
211 }) 211 })
212
213 it('Should use the nsfw instance policy as default', async function () {
214 let nsfwUUID: string
215
216 {
217 await updateCustomSubConfig(server.url, server.accessToken, { instance: { defaultNSFWPolicy: 'display' } })
218
219 const res = await searchVideo(server.url, 'NSFW search index')
220 const video = res.body.data[0] as Video
221
222 expect(res.body.data).to.have.length.greaterThan(0)
223 expect(video.nsfw).to.be.true
224
225 nsfwUUID = video.uuid
226 }
227
228 {
229 await updateCustomSubConfig(server.url, server.accessToken, { instance: { defaultNSFWPolicy: 'do_not_list' } })
230
231 const res = await searchVideo(server.url, 'NSFW search index')
232
233 try {
234 expect(res.body.data).to.have.lengthOf(0)
235 } catch (err) {
236 //
237 const video = res.body.data[0] as Video
238
239 expect(video.uuid).not.equal(nsfwUUID)
240 }
241 }
242 })
212 }) 243 })
213 244
214 describe('Channels search', async function () { 245 describe('Channels search', async function () {