Create profile-search.js
This commit is contained in:
41
api/v1/src/profile-search.js
Normal file
41
api/v1/src/profile-search.js
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
const axios = require('axios');
|
||||||
|
|
||||||
|
// Функция получения кастомного списка верифицированных пользователей
|
||||||
|
const getVerifiedUsers = require('./is_verified');
|
||||||
|
|
||||||
|
async function searchProfiles(page = 1, query = '', searchBy = 0, token = '') {
|
||||||
|
const url = `https://api.anixart.tv/search/profiles/${page}${token ? `?token=${token}` : ''}`;
|
||||||
|
const verifiedList = getVerifiedUsers();
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await axios.post(url, {
|
||||||
|
query,
|
||||||
|
searchBy,
|
||||||
|
});
|
||||||
|
|
||||||
|
const searchResult = response.data;
|
||||||
|
|
||||||
|
if (Array.isArray(searchResult.content)) {
|
||||||
|
searchResult.content = searchResult.content.map((profile) => {
|
||||||
|
const isVerified = verifiedList.includes(profile.id.toString());
|
||||||
|
return {
|
||||||
|
...profile,
|
||||||
|
is_verified: isVerified || profile.is_verified,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return searchResult;
|
||||||
|
} catch (error) {
|
||||||
|
return {
|
||||||
|
code: 2,
|
||||||
|
content: [],
|
||||||
|
total_count: 0,
|
||||||
|
total_page_count: 0,
|
||||||
|
current_page: page,
|
||||||
|
error: error.message,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = { searchProfiles };
|
||||||
Reference in New Issue
Block a user