aboutsummaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2016-06-06 14:54:52 +0200
committerChocobozzz <florian.bigard@gmail.com>2016-06-06 14:54:52 +0200
commit8d199cb823e1e47de87fdf421964e260b0ba6eb7 (patch)
tree563c5bd10235e69d84514a9b8348b525cc6d8765 /server
parentbe587647f98a4b83ca06a61fe55c7ac5d60927c6 (diff)
downloadPeerTube-8d199cb823e1e47de87fdf421964e260b0ba6eb7.tar.gz
PeerTube-8d199cb823e1e47de87fdf421964e260b0ba6eb7.tar.zst
PeerTube-8d199cb823e1e47de87fdf421964e260b0ba6eb7.zip
Add tag search support to server
Diffstat (limited to 'server')
-rw-r--r--server/initializers/constants.js2
-rw-r--r--server/models/videos.js2
-rw-r--r--server/tests/api/singlePod.js38
3 files changed, 40 insertions, 2 deletions
diff --git a/server/initializers/constants.js b/server/initializers/constants.js
index 97d22abdb..c6a6ac966 100644
--- a/server/initializers/constants.js
+++ b/server/initializers/constants.js
@@ -23,7 +23,7 @@ let REQUEST_RETRIES = 10
23 23
24// Sortable columns per schema 24// Sortable columns per schema
25const SEARCHABLE_COLUMNS = { 25const SEARCHABLE_COLUMNS = {
26 VIDEOS: [ 'name', 'magnetUri', 'podUrl', 'author' ] 26 VIDEOS: [ 'name', 'magnetUri', 'podUrl', 'author', 'tags' ]
27} 27}
28 28
29// Sortable columns per schema 29// Sortable columns per schema
diff --git a/server/models/videos.js b/server/models/videos.js
index f4658c371..d6b743c7c 100644
--- a/server/models/videos.js
+++ b/server/models/videos.js
@@ -128,7 +128,7 @@ function removeByIds (ids, callback) {
128function search (value, field, start, count, sort, callback) { 128function search (value, field, start, count, sort, callback) {
129 const query = {} 129 const query = {}
130 // Make an exact search with the magnet 130 // Make an exact search with the magnet
131 if (field === 'magnetUri') { 131 if (field === 'magnetUri' || field === 'tags') {
132 query[field] = value 132 query[field] = value
133 } else { 133 } else {
134 query[field] = new RegExp(value) 134 query[field] = new RegExp(value)
diff --git a/server/tests/api/singlePod.js b/server/tests/api/singlePod.js
index ef882b080..5fcf5557f 100644
--- a/server/tests/api/singlePod.js
+++ b/server/tests/api/singlePod.js
@@ -187,6 +187,32 @@ describe('Test a single pod', function () {
187 }) 187 })
188 }) 188 })
189 189
190 it('Should search the video by tag', function (done) {
191 utils.searchVideo(server.url, 'tag1', 'tags', function (err, res) {
192 if (err) throw err
193
194 expect(res.body.total).to.equal(1)
195 expect(res.body.data).to.be.an('array')
196 expect(res.body.data.length).to.equal(1)
197
198 const video = res.body.data[0]
199 expect(video.name).to.equal('my super name')
200 expect(video.description).to.equal('my super description')
201 expect(video.podUrl).to.equal('localhost:9001')
202 expect(video.author).to.equal('root')
203 expect(video.isLocal).to.be.true
204 expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ])
205 expect(utils.dateIsValid(video.createdDate)).to.be.true
206
207 utils.testImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) {
208 if (err) throw err
209 expect(test).to.equal(true)
210
211 done()
212 })
213 })
214 })
215
190 it('Should not find a search by name by default', function (done) { 216 it('Should not find a search by name by default', function (done) {
191 utils.searchVideo(server.url, 'hello', function (err, res) { 217 utils.searchVideo(server.url, 'hello', function (err, res) {
192 if (err) throw err 218 if (err) throw err
@@ -211,6 +237,18 @@ describe('Test a single pod', function () {
211 }) 237 })
212 }) 238 })
213 239
240 it('Should not find a search by tag', function (done) {
241 utils.searchVideo(server.url, 'tag', 'tags', function (err, res) {
242 if (err) throw err
243
244 expect(res.body.total).to.equal(0)
245 expect(res.body.data).to.be.an('array')
246 expect(res.body.data.length).to.equal(0)
247
248 done()
249 })
250 })
251
214 it('Should remove the video', function (done) { 252 it('Should remove the video', function (done) {
215 utils.removeVideo(server.url, server.accessToken, videoId, function (err) { 253 utils.removeVideo(server.url, server.accessToken, videoId, function (err) {
216 if (err) throw err 254 if (err) throw err