szurubooru/client/js/models/post_list.js
rr- 7fa8593b0a client/general: improve URL escaping
Specifically, cater for /, + and % in URL components.
2016-09-04 02:07:22 +02:00

38 lines
1.1 KiB
JavaScript

'use strict';
const api = require('../api.js');
const AbstractList = require('./abstract_list.js');
const Post = require('./post.js');
class PostList extends AbstractList {
static getAround(id, searchQuery) {
const url =
`/post/${id}/around?fields=id` +
`&query=${encodeURIComponent(searchQuery)}`;
return api.get(url)
.then(response => {
return Promise.resolve(response);
}).catch(response => {
return Promise.reject(response.description);
});
}
static search(text, page, pageSize, fields) {
const url =
`/posts/?query=${encodeURIComponent(text)}` +
`&page=${page}` +
`&pageSize=${pageSize}` +
`&fields=${fields.join(',')}`;
return api.get(url).then(response => {
return Promise.resolve(Object.assign(
{},
response,
{results: PostList.fromResponse(response.results)}));
});
}
}
PostList._itemClass = Post;
PostList._itemName = 'post';
module.exports = PostList;