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'
|
|
|
|
|
|
2023-07-22 13:19:48 +04:00
|
|
|
const headers = {
|
2022-05-17 08:59:36 +04:00
|
|
|
headers: {
|
|
|
|
|
Authorization: `Bearer ${readToken}`
|
|
|
|
|
}
|
2023-07-22 13:19:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function request(url, opts = {}) {
|
|
|
|
|
const {...options} = opts
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
const res = await fetch(`${OKI_API}${url}`, options)
|
|
|
|
|
return res.json()
|
|
|
|
|
} catch {
|
|
|
|
|
throw new Error('Eshwe pu jwenn done-a')
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-12-11 01:35:49 +01:00
|
|
|
|
2020-12-18 21:55:14 +01:00
|
|
|
export async function jwennTeksEpiSlug(slug) {
|
2022-05-20 02:10:00 +04:00
|
|
|
const query = qs.stringify({
|
2022-10-30 21:05:21 +04:00
|
|
|
populate: {
|
|
|
|
|
user: {
|
|
|
|
|
fields: ['username']
|
|
|
|
|
},
|
|
|
|
|
userAdmin: {
|
|
|
|
|
fields: ['username', 'firstname']
|
|
|
|
|
},
|
|
|
|
|
commentaires: {
|
|
|
|
|
fields: ['contenu', 'datePublication'],
|
|
|
|
|
populate: {
|
|
|
|
|
user: {
|
|
|
|
|
fields: ['username']
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
couverture: {
|
|
|
|
|
populate: '*'
|
|
|
|
|
},
|
|
|
|
|
artistes: {
|
2023-07-23 04:18:29 +04:00
|
|
|
fields: ['alias', 'slug', 'musicBrainzUrl', 'photo'],
|
|
|
|
|
populate: {
|
|
|
|
|
photo: {
|
|
|
|
|
fields: ['name', 'url'],
|
|
|
|
|
},
|
|
|
|
|
},
|
2022-10-30 21:05:21 +04:00
|
|
|
},
|
|
|
|
|
streamAudio: {
|
|
|
|
|
populate: '*'
|
|
|
|
|
},
|
|
|
|
|
streamVideo: {
|
|
|
|
|
populate: '*'
|
|
|
|
|
},
|
|
|
|
|
traductions: {
|
|
|
|
|
populate: '*'
|
2022-12-12 22:27:19 +04:00
|
|
|
},
|
|
|
|
|
difference: {
|
|
|
|
|
fileds: ['date', 'id', 'paroles', 'jsonDiff', 'source', 'admin_user'],
|
|
|
|
|
populate: {
|
|
|
|
|
admin_user: {
|
|
|
|
|
fields: ['firstname']
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-10-30 21:05:21 +04:00
|
|
|
}
|
|
|
|
|
},
|
2022-05-20 02:10:00 +04:00
|
|
|
filters: {
|
|
|
|
|
slug: {
|
|
|
|
|
$eq: slug
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}, {
|
|
|
|
|
encodeValuesOnly: true
|
|
|
|
|
})
|
2023-07-22 13:19:48 +04:00
|
|
|
|
|
|
|
|
const {data} = await request(`/paroles?${query}`, headers)
|
|
|
|
|
return data[0]
|
2020-12-11 01:35:49 +01:00
|
|
|
}
|
|
|
|
|
|
2022-05-11 03:09:46 +04:00
|
|
|
export async function jwennAwtisEpiSlug(slug) {
|
2022-05-20 02:10:00 +04:00
|
|
|
const query = qs.stringify({
|
2023-07-22 13:19:48 +04:00
|
|
|
populate: ['paroles', 'photo', 'paroles.couverture'],
|
2022-05-20 02:10:00 +04:00
|
|
|
filters: {
|
|
|
|
|
slug: {
|
|
|
|
|
$eq: slug
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}, {
|
|
|
|
|
encodeValuesOnly: true
|
|
|
|
|
})
|
2020-12-11 01:35:49 +01:00
|
|
|
|
2023-07-22 13:19:48 +04:00
|
|
|
const {data} = await request(`/artistes?${query}`, headers)
|
|
|
|
|
return data[0]
|
2020-12-23 20:29:59 +01:00
|
|
|
}
|
|
|
|
|
|
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-20 02:10:00 +04:00
|
|
|
const query = qs.stringify({
|
|
|
|
|
populate: ['paroles', 'photo'],
|
|
|
|
|
sort: ['publishedAt:desc'],
|
|
|
|
|
pagination: {
|
|
|
|
|
start,
|
|
|
|
|
limit: AWTIS_POU_CHAK_PAJ
|
|
|
|
|
}
|
|
|
|
|
}, {
|
|
|
|
|
encodeValuesOnly: true
|
|
|
|
|
})
|
2020-12-11 01:35:49 +01:00
|
|
|
|
2023-07-22 13:19:48 +04:00
|
|
|
const data = await request(`/artistes?${query}`, headers)
|
2022-05-20 02:10:00 +04:00
|
|
|
return data
|
2020-12-11 01:35:49 +01:00
|
|
|
}
|
|
|
|
|
|
2022-05-21 17:47:45 +04:00
|
|
|
export async function jwennToutAwtis() {
|
|
|
|
|
const query = qs.stringify({
|
|
|
|
|
populate: ['photo'],
|
|
|
|
|
sort: ['alias:asc'],
|
|
|
|
|
pagination: {
|
|
|
|
|
pageSize: 100
|
|
|
|
|
}
|
|
|
|
|
}, {
|
|
|
|
|
encodeValuesOnly: true
|
|
|
|
|
})
|
|
|
|
|
|
2023-07-22 13:19:48 +04:00
|
|
|
const {data} = await request(`/artistes?${query}`, headers)
|
2022-05-21 17:47:45 +04:00
|
|
|
return data
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-11 01:35:49 +01:00
|
|
|
export async function jwennTeks() {
|
2022-05-20 02:10:00 +04:00
|
|
|
const query = qs.stringify({
|
2022-05-20 05:27:39 +04:00
|
|
|
populate: {
|
|
|
|
|
user: {
|
|
|
|
|
fields: ['username']
|
|
|
|
|
},
|
|
|
|
|
userAdmin: {
|
2022-05-22 14:17:56 +04:00
|
|
|
fields: ['username', 'firstname']
|
2022-05-20 05:27:39 +04:00
|
|
|
},
|
|
|
|
|
commentaires: {
|
2022-05-22 22:15:38 +04:00
|
|
|
fields: ['contenu', 'datePublication'],
|
|
|
|
|
populate: {
|
|
|
|
|
user: {
|
|
|
|
|
fields: ['username']
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-05-20 05:27:39 +04:00
|
|
|
},
|
|
|
|
|
couverture: {
|
|
|
|
|
populate: '*'
|
|
|
|
|
},
|
|
|
|
|
artistes: {
|
2022-05-22 14:17:56 +04:00
|
|
|
fields: ['alias', 'slug']
|
2022-05-20 05:27:39 +04:00
|
|
|
},
|
|
|
|
|
streamAudio: {
|
|
|
|
|
populate: '*'
|
|
|
|
|
},
|
|
|
|
|
streamVideo: {
|
|
|
|
|
populate: '*'
|
|
|
|
|
},
|
|
|
|
|
traductions: {
|
|
|
|
|
populate: '*'
|
|
|
|
|
}
|
|
|
|
|
},
|
2022-05-20 02:10:00 +04:00
|
|
|
sort: ['titre:asc'],
|
|
|
|
|
pagination: {
|
|
|
|
|
pageSize: 100
|
|
|
|
|
}
|
|
|
|
|
}, {
|
|
|
|
|
encodeValuesOnly: true
|
|
|
|
|
})
|
2020-12-13 23:10:03 +01:00
|
|
|
|
2023-07-22 13:19:48 +04:00
|
|
|
const {data} = await request(`/paroles?${query}`, headers)
|
|
|
|
|
return data
|
2020-12-11 01:35:49 +01:00
|
|
|
}
|
2020-12-21 03:22:05 +01:00
|
|
|
|
2022-05-11 03:13:26 +04:00
|
|
|
export async function jwennAwtisSlug() {
|
2022-05-20 02:10:00 +04:00
|
|
|
const query = qs.stringify({
|
2022-05-20 03:38:40 +04:00
|
|
|
sort: ['publishedAt:desc'],
|
|
|
|
|
pagination: {
|
|
|
|
|
pageSize: 100
|
|
|
|
|
}
|
|
|
|
|
}, {
|
|
|
|
|
encodeValuesOnly: true
|
2022-05-20 02:10:00 +04:00
|
|
|
})
|
2022-05-11 03:13:26 +04:00
|
|
|
|
2023-07-22 13:19:48 +04:00
|
|
|
const {data} = await request(`/artistes?${query}`, headers)
|
|
|
|
|
return data.map(({attributes}) => attributes.slug)
|
2022-05-20 02:10:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function jwennTeksSlug() {
|
|
|
|
|
const query = qs.stringify({
|
2022-05-20 03:38:40 +04:00
|
|
|
sort: ['publishedAt:desc'],
|
|
|
|
|
pagination: {
|
|
|
|
|
pageSize: 100
|
|
|
|
|
}
|
|
|
|
|
}, {
|
|
|
|
|
encodeValuesOnly: true
|
2022-05-20 02:10:00 +04:00
|
|
|
})
|
|
|
|
|
|
2023-07-22 13:19:48 +04:00
|
|
|
const {data} = await request(`/paroles?${query}`, headers)
|
|
|
|
|
return data.map(({attributes}) => attributes.slug)
|
2022-05-11 03:13:26 +04:00
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
|
}
|
2022-05-20 02:10:00 +04:00
|
|
|
}, {
|
|
|
|
|
encodeValuesOnly: true
|
2022-05-17 09:00:40 +04:00
|
|
|
})
|
|
|
|
|
|
2023-07-22 13:19:48 +04:00
|
|
|
const {data} = await request(`/paroles?${query}`, headers)
|
|
|
|
|
|
|
|
|
|
return data
|
2022-05-08 23:47:31 +04:00
|
|
|
}
|
|
|
|
|
|
2022-05-20 02:10:00 +04:00
|
|
|
export async function jwennAnTeks(teksId, token) {
|
|
|
|
|
const headers = {
|
|
|
|
|
'content-type': 'application/json',
|
|
|
|
|
Authorization: `Bearer ${token}`
|
|
|
|
|
}
|
2021-05-24 02:58:04 +02:00
|
|
|
|
2023-07-22 13:19:48 +04:00
|
|
|
const {data} = await request(`/paroles/${teksId}`, {headers})
|
|
|
|
|
return data
|
2020-12-21 03:22:05 +01:00
|
|
|
}
|
2021-06-26 12:16:24 +02:00
|
|
|
|
|
|
|
|
export async function jwennKomanteEpiTeksId(teksId) {
|
2022-05-20 02:10:00 +04:00
|
|
|
const query = qs.stringify({
|
|
|
|
|
sort: ['publishedAt:desc'],
|
|
|
|
|
populate: ['paroles', 'user'],
|
|
|
|
|
filters: {
|
|
|
|
|
parole: {
|
|
|
|
|
id: {
|
|
|
|
|
$eq: teksId
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}, {
|
|
|
|
|
encodeValuesOnly: true
|
|
|
|
|
})
|
|
|
|
|
|
2023-07-22 13:19:48 +04:00
|
|
|
const {data} = await request(`/commentaires?${query}`, headers)
|
|
|
|
|
return data
|
2021-06-26 12:16:24 +02:00
|
|
|
}
|
2022-02-06 18:41:57 +04:00
|
|
|
|
2022-05-17 00:31:13 +04:00
|
|
|
export async function jwennUserEpiToken(userToken) {
|
2023-07-22 13:19:48 +04:00
|
|
|
const data = await request('/users/me', {
|
2022-05-17 00:31:13 +04:00
|
|
|
headers: {
|
|
|
|
|
Authorization: `Bearer ${userToken}`
|
|
|
|
|
}
|
|
|
|
|
})
|
2023-07-22 13:19:48 +04:00
|
|
|
|
|
|
|
|
return data
|
2022-05-17 00:31:13 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function jwennUserEpiUsername(username) {
|
2022-05-20 02:10:00 +04:00
|
|
|
const query = qs.stringify({
|
|
|
|
|
filters: {
|
|
|
|
|
username: {
|
|
|
|
|
$eq: username
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}, {
|
|
|
|
|
encodeValuesOnly: true
|
|
|
|
|
})
|
|
|
|
|
|
2023-07-22 13:19:48 +04:00
|
|
|
const data = await request(`/users?${query}`, headers)
|
|
|
|
|
return data[0]
|
2022-02-07 16:26:34 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function jwennUserEpiEmail(email) {
|
2022-05-20 02:10:00 +04:00
|
|
|
const query = qs.stringify({
|
|
|
|
|
filters: {
|
|
|
|
|
email: {
|
|
|
|
|
$eq: email
|
|
|
|
|
},
|
|
|
|
|
confirmed: {
|
|
|
|
|
$eq: false
|
|
|
|
|
},
|
|
|
|
|
blocked: {
|
|
|
|
|
$eq: false
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}, {
|
|
|
|
|
encodeValuesOnly: true
|
|
|
|
|
})
|
|
|
|
|
|
2023-07-22 13:19:48 +04:00
|
|
|
const {data} = await request(`/users?${query}`, headers)
|
|
|
|
|
return data[0]
|
2022-02-06 18:41:57 +04:00
|
|
|
}
|
2022-05-20 02:10:00 +04:00
|
|
|
|
|
|
|
|
export async function passwordRequest(lyen, email) {
|
2023-07-22 13:19:48 +04:00
|
|
|
await request(`/auth/${lyen}`, {
|
|
|
|
|
method: 'POST',
|
|
|
|
|
body: {email}
|
2022-05-20 02:10:00 +04:00
|
|
|
})
|
|
|
|
|
}
|
2022-05-23 00:25:18 +04:00
|
|
|
|
|
|
|
|
export async function jwennStats() {
|
2023-07-22 13:19:48 +04:00
|
|
|
return request('/stats')
|
2022-05-23 00:25:18 +04:00
|
|
|
}
|