mirror of
https://git.rdcenter.ru/RDCenter/skb-kit.git
synced 2026-12-05 02:39:45 +00:00
Микрофиксы, работа с api, вытягивание фотографий
This commit is contained in:
1 parent
26042d685d
commit
f8586547b9
7 files changed
+51
-35
No files matched your search
+29
-12
@@ -2,30 +2,47 @@ import * as WPAPI from 'wpapi';
|
||||
|
||||
import reactPress from './reactPress';
|
||||
|
||||
import { g1, g2, g3 } from './assets/images/gallery';
|
||||
const fbToken = 'ltvszr1EL7Q8lX9v4W7ivAEwJsFUvicFGtLepCDj';
|
||||
|
||||
const wp = new WPAPI(
|
||||
process.env.NODE_ENV === 'development'
|
||||
? {
|
||||
endpoint: reactPress.api.rest_url,
|
||||
username: 'admin',
|
||||
password: 'testapi',
|
||||
}
|
||||
endpoint: reactPress.api.rest_url,
|
||||
username: 'admin',
|
||||
password: 'admin',
|
||||
}
|
||||
: { endpoint: reactPress.api.rest_url, nonce: reactPress.api.nonce }
|
||||
);
|
||||
wp.setHeaders('Authorization', 'Bearer ' + fbToken);
|
||||
|
||||
export async function getContacts(q = '') {
|
||||
// Получаем категории медиафайлов
|
||||
const response = await wp.url(reactPress.api.rest_url + 'filebird/public/v1/folders')
|
||||
const { data: { folders } } = response;
|
||||
const mediaCategories = {};
|
||||
|
||||
// Деструктурируем объекты в формат {category: id}
|
||||
for (let { id, text } of folders) {
|
||||
mediaCategories[text] = id;
|
||||
}
|
||||
console.log(response);
|
||||
console.log(mediaCategories);
|
||||
export async function getPosts(q = '') {
|
||||
try {
|
||||
const users = await wp.users().search(q);
|
||||
return users;
|
||||
const posts = await wp.posts().search(q);
|
||||
return posts;
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
export async function getSliderImages() {
|
||||
const mock = [ g1, g2, g3 ];
|
||||
|
||||
return mock;
|
||||
export async function getMedia(category) {
|
||||
try {
|
||||
const response = await wp.url(reactPress.api.rest_url + 'filebird/public/v1/attachment-id/?folder_id=' + mediaCategories[category]);
|
||||
console.log(response);
|
||||
return [];
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
return [];
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user