Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
Xiph.Org
Icecast-Directory
Commits
1e19f887
Commit
1e19f887
authored
Jul 23, 2015
by
Marco Flowers
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Start of id pagination
Using stream ids to paginate searches through the stream.
parent
f8998e0e
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
77 additions
and
16 deletions
+77
-16
app.js
app.js
+3
-3
controllers/formats.js
controllers/formats.js
+13
-2
controllers/genres.js
controllers/genres.js
+14
-2
controllers/index.js
controllers/index.js
+1
-1
controllers/stream-api.js
controllers/stream-api.js
+39
-7
views/by_xx.html
views/by_xx.html
+7
-1
No files found.
app.js
View file @
1e19f887
...
...
@@ -59,11 +59,11 @@ function respond(res, err, rows, result) {
app
.
get
(
'
/streams/
'
,
function
(
req
,
res
){
res
.
set
(
'
Content-Type
'
,
'
application/json
'
);
var
params
=
req
.
query
;
streamsFindBy
(
params
.
format
,
params
.
genre
,
params
.
q
,
params
.
order
,
params
.
limit
,
1
,
function
(
err
,
rows
){
if
(
err
||
rows
[
0
].
array_to_json
==
null
)
{
streamsFindBy
(
params
.
format
,
params
.
genre
,
params
.
q
,
params
.
order
,
params
.
limit
,
params
.
next
,
params
.
prev
,
1
,
function
(
err
,
rows
){
if
(
err
||
rows
[
0
].
streams
==
null
)
{
res
.
send
([]);
}
else
{
res
.
send
(
rows
[
0
].
array_to_json
);
res
.
send
(
rows
[
0
].
streams
);
}
});
});
...
...
controllers/formats.js
View file @
1e19f887
...
...
@@ -9,7 +9,9 @@ function init(q, c, s) {
function
byFormat
(
req
,
res
)
{
var
format
=
req
.
param
(
"
format
"
);
streamsFindBy
(
format
,
undefined
,
undefined
,
1
,
10
,
0
,
function
(
err
,
rows
)
{
var
next
=
req
.
param
(
"
next
"
);
var
prev
=
req
.
param
(
"
prev
"
);
streamsFindBy
(
format
,
undefined
,
undefined
,
2
,
10
,
next
,
prev
,
0
,
function
(
err
,
rows
)
{
if
(
err
)
{
res
.
send
(
503
);
}
else
{
...
...
@@ -19,10 +21,19 @@ function byFormat(req, res) {
}
else
{
error
=
false
;
}
var
next_url
,
prev_url
;
if
(
rows
.
length
==
10
)
{
var
last_id
=
rows
[
9
].
id
;
var
prev_id
=
rows
[
0
].
id
;
next_url
=
req
.
path
+
'
?next=
'
+
last_id
;
prev_url
=
req
.
path
+
'
?prev=
'
+
prev_id
;
}
res
.
render
(
"
by_xx
"
,
{
title
:
format
,
servers
:
rows
,
error
:
error
error
:
error
,
next
:
next_url
,
prev
:
prev_url
});
}
});
...
...
controllers/genres.js
View file @
1e19f887
...
...
@@ -9,7 +9,10 @@ function init(q, c, s) {
function
byGenre
(
req
,
res
)
{
var
genre
=
req
.
param
(
"
genre
"
);
streamsFindBy
(
undefined
,
genre
,
undefined
,
1
,
10
,
0
,
function
(
err
,
rows
)
{
var
next
=
req
.
param
(
"
next
"
);
var
prev
=
req
.
param
(
"
prev
"
);
streamsFindBy
(
undefined
,
genre
,
undefined
,
2
,
10
,
next
,
prev
,
0
,
function
(
err
,
rows
)
{
console
.
log
(
req
);
if
(
err
)
{
res
.
send
(
503
);
}
else
{
...
...
@@ -19,10 +22,19 @@ function byGenre(req, res) {
}
else
{
error
=
false
;
}
var
next_url
,
prev_url
;
if
(
rows
.
length
==
10
)
{
var
last_id
=
rows
[
9
].
id
;
var
prev_id
=
rows
[
0
].
id
;
next_url
=
req
.
path
+
'
?next=
'
+
last_id
;
prev_url
=
req
.
path
+
'
?prev=
'
+
prev_id
;
}
res
.
render
(
"
by_xx
"
,
{
title
:
genre
,
servers
:
rows
,
error
:
error
error
:
error
,
next
:
next_url
,
prev
:
prev_url
});
}
});
...
...
controllers/index.js
View file @
1e19f887
...
...
@@ -8,7 +8,7 @@ function init(q, c, s) {
}
function
index
(
req
,
res
)
{
streamsFindBy
(
undefined
,
undefined
,
undefined
,
0
,
20
,
0
,
function
(
err
,
rows
)
{
streamsFindBy
(
undefined
,
undefined
,
undefined
,
0
,
20
,
undefined
,
undefined
,
0
,
function
(
err
,
rows
)
{
if
(
err
)
{
res
.
send
(
503
);
}
else
{
...
...
controllers/stream-api.js
View file @
1e19f887
...
...
@@ -8,12 +8,12 @@ function init(q, c) {
}
function
getCachedStreams
(
format
,
genre
,
q
,
order
,
limit
,
json
,
cb
)
{
var
cacheString
=
JSON
.
stringify
({
"
format
"
:
format
,
"
genre
"
:
genre
,
"
q
"
:
q
,
"
order
"
:
order
,
"
limit
"
:
limit
,
"
json
"
:
json
});
function
getCachedStreams
(
format
,
genre
,
q
,
order
,
limit
,
next
,
prev
,
json
,
cb
)
{
var
cacheString
=
JSON
.
stringify
({
"
format
"
:
format
,
"
genre
"
:
genre
,
"
q
"
:
q
,
"
order
"
:
order
,
"
limit
"
:
limit
,
"
next
"
:
next
,
"
prev
"
:
prev
,
"
json
"
:
json
});
console
.
log
(
cacheString
);
cache
.
wrap
(
cacheString
,
function
(
_cb
)
{
var
params
=
JSON
.
parse
(
cacheString
);
findBy
(
params
.
format
,
params
.
genre
,
params
.
q
,
params
.
order
,
params
.
limit
,
params
.
json
,
_cb
);
findBy
(
params
.
format
,
params
.
genre
,
params
.
q
,
params
.
order
,
params
.
limit
,
params
.
next
,
params
.
prev
,
params
.
json
,
_cb
);
},
5
,
cb
);
}
...
...
@@ -26,11 +26,11 @@ function getCachedStreams(format, genre, q, order, limit, json, cb) {
Turns parameters into a sql query on streams
*/
function
findBy
(
format
,
genre
,
q
,
order
,
limit
,
json
,
resultCallback
)
function
findBy
(
format
,
genre
,
q
,
order
,
limit
,
next
,
prev
,
json
,
resultCallback
)
{
console
.
log
(
format
);
console
.
log
(
genre
);
var
queryStringJsonBeg
=
'
SELECT array_to_json(array_agg(row_to_json(t))) FROM (
'
;
var
queryStringJsonBeg
=
'
SELECT array_to_json(array_agg(row_to_json(t)))
AS streams
FROM (
'
;
var
queryStringJsonEnd
=
'
) t
'
;
var
queryStringBeg
=
'
SELECT s.id, s.stream_name, s.stream_type, s.description
\
,s.songname, s.url, s.avg_listening_time, s.codec_sub_types, s.bitrate, s.hits,
\
...
...
@@ -104,15 +104,45 @@ function findBy(format, genre, q, order, limit, json, resultCallback)
return
;
}
}
if
(
next
&&
(
order
==
1
||
order
==
2
))
{
searchString
=
'
WHERE
'
;
if
(
countItems
>
1
)
{
searchString
=
'
AND
'
;
}
var
sign
;
if
(
order
==
1
){
sign
=
'
<
'
;
}
else
{
sign
=
'
>
'
;
}
queryString
+=
searchString
+
'
s.id
'
+
sign
+
'
'
+
'
$
'
+
countItems
+
'
'
;
items
.
push
(
next
);
countItems
++
;
}
else
if
(
prev
&&
(
order
==
1
||
order
==
2
))
{
searchString
=
'
WHERE
'
;
if
(
countItems
>
1
)
{
searchString
=
'
AND
'
;
}
var
sign
;
if
(
order
==
1
){
sign
=
'
>
'
;
}
else
{
sign
=
'
<
'
;
}
queryString
+=
searchString
+
'
s.id
'
+
sign
+
'
'
+
'
$
'
+
countItems
+
'
'
;
items
.
push
(
prev
);
countItems
++
;
}
// add in the Group BY
queryString
=
queryString
+
queryStringGroup
;
if
(
order
)
{
if
(
order
==
0
)
{
queryString
+=
'
ORDER BY random()
'
;
}
else
if
(
order
==
1
)
{
queryString
+=
'
ORDER BY
listeners DESC
'
;
queryString
+=
'
ORDER BY
s.id desc
'
;
}
else
if
(
order
==
2
)
{
queryString
+=
'
ORDER BY
listeners ASC
'
;
queryString
+=
'
ORDER BY
s.id asc
'
;
}
}
if
(
limit
)
{
...
...
@@ -124,6 +154,8 @@ function findBy(format, genre, q, order, limit, json, resultCallback)
queryString
+=
queryStringJsonEnd
;
}
console
.
log
(
queryString
);
console
.
log
(
items
)
console
.
log
(
resultCallback
)
query
(
queryString
,
items
,
resultCallback
);
}
...
...
views/by_xx.html
View file @
1e19f887
...
...
@@ -13,6 +13,12 @@
{% for server in servers %}
{% include "./stream.html" %}
{% endfor %}
{% if prev %}
<a
href=
"{{prev}}"
>
Prev
</a>
{% endif %}
{% if next %}
<a
href=
"{{next}}"
>
Next
</a>
{% endif %}
{% endif %}
</div>
{% endblock %}
\ No newline at end of file
{% endblock %}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment