2020-12-11 01:35:49 +01:00
|
|
|
import axios from 'axios'
|
2022-05-17 09:00:40 +04:00
|
|
|
import qs from 'qs'
|
2020-12-11 01:35:49 +01:00
|
|
|
|
|
|
|
|
const OKI_API = process.env.NEXT_PUBLIC_API_URL || 'http://localhost:1337'
|
2020-12-12 21:50:16 +01:00
|
|
|
const AWTIS_POU_CHAK_PAJ = process.env.NEXT_PUBLIC_AWTIS_POU_CHAK_PAJ || 6
|
2022-05-17 08:59:36 +04:00
|
|
|
const readToken = process.env.NEXT_PUBLIC_READ_TOKEN || 'read-token'
|
|
|
|
|
|
|
|
|
|
const readAxiosInstance = axios.create({
|
|
|
|
|
headers: {
|
|
|
|
|
Authorization: `Bearer ${readToken}`
|
|
|
|
|
}
|
|
|
|
|
})
|
2020-12-11 01:35:49 +01:00
|
|
|
|
2020-12-18 21:55:14 +01:00
|
|
|
export async function jwennTeksEpiSlug(slug) {
|
2020-12-23 20:38:15 +01:00
|
|
|
const response = await axios.get(`${OKI_API}/teks?slug=${slug}&_where[published_at_null]=false`)
|
2020-12-18 21:55:14 +01:00
|
|
|
return response.data[0]
|
2020-12-11 01:35:49 +01:00
|
|
|
}
|
|
|
|
|
|
2022-05-11 03:09:46 +04:00
|
|
|
export async function jwennAwtisEpiSlug(slug) {
|
|
|
|
|
const response = await axios.get(`${OKI_API}/awtis?slug=${slug}&_where[published_at_null]=false`)
|
|
|
|
|
return response.data[0]
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-11 01:35:49 +01:00
|
|
|
export async function jwennAwtisKantite() {
|
2020-12-23 20:29:04 +01:00
|
|
|
const response = await axios.get(`${OKI_API}/awtis/count?_where[published_at_null]=false`)
|
2020-12-11 01:35:49 +01:00
|
|
|
return response.data
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-23 20:29:59 +01:00
|
|
|
export async function jwennTeksKantite() {
|
|
|
|
|
const response = await axios.get(`${OKI_API}/teks/count?_where[published_at_null]=false`)
|
|
|
|
|
return response.data
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-11 01:35:49 +01:00
|
|
|
export async function jwennAwtisPajinasyon(paj) {
|
2020-12-12 21:50:16 +01:00
|
|
|
const start = AWTIS_POU_CHAK_PAJ * (paj - 1)
|
2022-05-10 00:26:51 +04:00
|
|
|
const query = `_sort=published_at:DESC&_start=${start}&_limit=${AWTIS_POU_CHAK_PAJ}&_where[published_at_null]=false`
|
2020-12-11 01:35:49 +01:00
|
|
|
|
|
|
|
|
const response = await axios.get(`${OKI_API}/awtis?${query}`)
|
|
|
|
|
return response.data
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function jwennTeks() {
|
2020-12-23 20:38:15 +01:00
|
|
|
const query = '_sort=tit:ASC&_where[published_at_null]=false'
|
2020-12-13 23:10:03 +01:00
|
|
|
|
2020-12-18 21:55:14 +01:00
|
|
|
const response = await axios.get(`${OKI_API}/teks?${query}`)
|
2020-12-11 01:35:49 +01:00
|
|
|
return response.data
|
|
|
|
|
}
|
2020-12-21 03:22:05 +01:00
|
|
|
|
2022-05-11 03:13:26 +04:00
|
|
|
export async function jwennAwtisSlug() {
|
|
|
|
|
const query = '_sort=published_at:DESC&_where[published_at_null]=false'
|
|
|
|
|
|
|
|
|
|
const response = await axios.get(`${OKI_API}/awtis?${query}`)
|
|
|
|
|
const {data} = response
|
|
|
|
|
return data.map(({slug}) => slug)
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-08 23:47:31 +04:00
|
|
|
export async function jwennDenyeTeks() {
|
2022-05-17 09:00:40 +04:00
|
|
|
const query = qs.stringify({
|
|
|
|
|
populate: ['artistes', 'couverture'],
|
|
|
|
|
sort: ['publishedAt:desc'],
|
|
|
|
|
pagination: {
|
|
|
|
|
limit: 6
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
const {data} = await readAxiosInstance.get(`${OKI_API}/paroles?${query}`)
|
|
|
|
|
return data.data
|
2022-05-08 23:47:31 +04:00
|
|
|
}
|
|
|
|
|
|
2022-03-25 00:04:52 +04:00
|
|
|
export async function jwennAnTeks(teksId) {
|
|
|
|
|
const response = await axios.get(`${OKI_API}/teks/${teksId}`)
|
|
|
|
|
return response.data
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-24 02:58:04 +02:00
|
|
|
export async function jwennTeksEpiUserId(userId) {
|
2022-03-25 00:04:30 +04:00
|
|
|
const query = `_sort=tit:ASC&_where[user.id]=${userId}&_publicationState=preview&published_at_null=true`
|
2021-05-24 02:58:04 +02:00
|
|
|
|
|
|
|
|
const response = await axios.get(`${OKI_API}/teks?${query}`)
|
|
|
|
|
return response.data
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-21 03:22:05 +01:00
|
|
|
export async function jwennSlugs() {
|
|
|
|
|
const response = await axios.get(`${OKI_API}/slugs`)
|
|
|
|
|
return response.data
|
|
|
|
|
}
|
2021-06-26 12:16:24 +02:00
|
|
|
|
|
|
|
|
export async function jwennKomanteEpiTeksId(teksId) {
|
|
|
|
|
const query = `_sort=published_at:DESC&_where[teks]=${teksId}&_where[published_at_null]=false`
|
|
|
|
|
const response = await axios.get(`${OKI_API}/komante?${query}`)
|
|
|
|
|
return response.data
|
|
|
|
|
}
|
2022-02-06 18:41:57 +04:00
|
|
|
|
2022-05-17 00:31:13 +04:00
|
|
|
export async function jwennUserEpiToken(userToken) {
|
|
|
|
|
const response = await axios.get(`${OKI_API}/users/me`, {
|
|
|
|
|
headers: {
|
|
|
|
|
Authorization: `Bearer ${userToken}`
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
return response.data
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function jwennUserEpiUsername(username) {
|
|
|
|
|
const query = `_where[username]=${username}&_where[confirmed]=true`
|
2022-02-07 16:26:34 +04:00
|
|
|
const response = await axios.get(`${OKI_API}/users?${query}`)
|
|
|
|
|
return response.data[0]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function jwennUserEpiEmail(email) {
|
|
|
|
|
const query = `_where[email]=${email}&_where[confirmed]=false&_where[blocked]=false`
|
2022-02-06 18:41:57 +04:00
|
|
|
const response = await axios.get(`${OKI_API}/users?${query}`)
|
|
|
|
|
return response.data[0]
|
|
|
|
|
}
|