2022-06-12 15:12:28 +10:00
|
|
|
import getConfig from 'next/config'
|
|
|
|
|
|
2022-06-14 20:58:06 +10:00
|
|
|
export const getAllPosts = async (filter, page, limit) => {
|
2022-06-12 15:12:28 +10:00
|
|
|
|
|
|
|
|
const { serverRuntimeConfig, publicRuntimeConfig } = getConfig()
|
|
|
|
|
const qs = require('qs')
|
|
|
|
|
const qVal = []
|
|
|
|
|
|
2022-06-14 20:58:06 +10:00
|
|
|
if (page == null) {
|
|
|
|
|
page = 0
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (limit == null) {
|
|
|
|
|
limit = 50;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var filters = {}
|
|
|
|
|
|
|
|
|
|
if (filter) {
|
2022-06-18 15:14:44 +10:00
|
|
|
|
2022-06-14 20:58:06 +10:00
|
|
|
filters = {
|
2022-06-20 15:22:16 +10:00
|
|
|
project: {
|
2022-06-12 15:12:28 +10:00
|
|
|
Slug: {
|
2022-06-20 15:22:16 +10:00
|
|
|
$in: filter
|
2022-06-12 15:12:28 +10:00
|
|
|
}
|
|
|
|
|
}
|
2022-06-14 20:58:06 +10:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const qArray = {
|
|
|
|
|
sort: ['publishedAt:desc'],
|
|
|
|
|
pagination: {
|
|
|
|
|
page: page,
|
|
|
|
|
pageSize: limit
|
|
|
|
|
},
|
|
|
|
|
filters
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const query = qs.stringify( qArray, {
|
2022-06-12 15:12:28 +10:00
|
|
|
encodeValuesOnly: true,
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
const res = await fetch(serverRuntimeConfig.base_path + `articles?${query}`, {
|
|
|
|
|
headers: new Headers({
|
|
|
|
|
'Authorization': serverRuntimeConfig.strapi_token,
|
|
|
|
|
'Content-Type': 'application/x-www-form-urlencoded'
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
return await res.json()
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-17 21:57:06 +10:00
|
|
|
export const getSinglePost = async (postId) => {
|
|
|
|
|
const { serverRuntimeConfig} = getConfig()
|
|
|
|
|
const url = serverRuntimeConfig.base_path + 'articles?filters[Slug][$eq]=' + postId + '&populate=*'
|
|
|
|
|
|
|
|
|
|
const res = await fetch(url, {
|
|
|
|
|
headers: new Headers({
|
|
|
|
|
'Authorization': serverRuntimeConfig.strapi_token,
|
|
|
|
|
'Content-Type': 'application/x-www-form-urlencoded'
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
const artdata = await res.json()
|
|
|
|
|
return artdata.data[0].attributes
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-12 15:12:28 +10:00
|
|
|
export const getAllPodcastSeries = async () => {
|
|
|
|
|
const { serverRuntimeConfig } = getConfig()
|
|
|
|
|
const qs = require('qs')
|
|
|
|
|
const query = qs.stringify({
|
|
|
|
|
populate: {
|
|
|
|
|
podcast_episodes: {
|
2022-06-22 21:37:22 +10:00
|
|
|
populate:['Audio_MP3']
|
2022-06-12 15:12:28 +10:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}, {
|
|
|
|
|
encodeValuesOnly: true,
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
const res = await fetch(serverRuntimeConfig.base_path + `podcast-series?${query}`, {
|
|
|
|
|
headers: new Headers({
|
|
|
|
|
'Authorization': serverRuntimeConfig.strapi_token,
|
|
|
|
|
'Content-Type': 'application/x-www-form-urlencoded'
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
2022-06-18 15:14:44 +10:00
|
|
|
return await res.json()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const getProjectDetails = async (projectId) => {
|
|
|
|
|
const { serverRuntimeConfig } = getConfig()
|
|
|
|
|
const qs = require('qs')
|
|
|
|
|
const query = qs.stringify({
|
|
|
|
|
filters: {
|
|
|
|
|
Slug: {
|
|
|
|
|
$eq: projectId
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
populate: '*'
|
|
|
|
|
}, {
|
|
|
|
|
encodeValuesOnly: true,
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
const res = await fetch(serverRuntimeConfig.base_path + `projects?${query}`, {
|
|
|
|
|
headers: new Headers({
|
|
|
|
|
'Authorization': serverRuntimeConfig.strapi_token,
|
|
|
|
|
'Content-Type': 'application/x-www-form-urlencoded'
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
2022-06-12 15:12:28 +10:00
|
|
|
return await res.json()
|
2022-06-20 15:22:16 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const getPodcastEpisode = async (episodeId) => {
|
2022-06-22 21:37:22 +10:00
|
|
|
const { serverRuntimeConfig} = getConfig()
|
|
|
|
|
const qs = require('qs')
|
|
|
|
|
const query = qs.stringify({
|
|
|
|
|
filters: {
|
|
|
|
|
Slug: {
|
|
|
|
|
$eq: episodeId
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
populate: '*'
|
|
|
|
|
}, {
|
|
|
|
|
encodeValuesOnly: true,
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
const epres = await fetch(serverRuntimeConfig.base_path + `podcast-episodes?${query}`, {
|
|
|
|
|
headers: new Headers({
|
|
|
|
|
'Authorization':serverRuntimeConfig.strapi_token,
|
|
|
|
|
'Content-Type': 'application/x-www-form-urlencoded'
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
return await epres.json()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const getPodcastSeries = async (podcastId) => {
|
|
|
|
|
const { serverRuntimeConfig} = getConfig()
|
|
|
|
|
const qs = require('qs')
|
|
|
|
|
const query = qs.stringify({
|
|
|
|
|
filters: {
|
|
|
|
|
Slug: {
|
|
|
|
|
$eq: podcastId
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
populate: '*'
|
|
|
|
|
}, {
|
|
|
|
|
encodeValuesOnly: true,
|
|
|
|
|
})
|
2022-06-26 14:59:45 +10:00
|
|
|
const url = serverRuntimeConfig.base_path + `podcast-series?${query}`;
|
2022-06-22 21:37:22 +10:00
|
|
|
const showres = await fetch(url, {
|
|
|
|
|
headers: new Headers({
|
|
|
|
|
'Authorization': serverRuntimeConfig.strapi_token,
|
|
|
|
|
'Content-Type': 'application/x-www-form-urlencoded'
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
return await showres.json()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const getPodcastSeriesEpisodes = async (podcastId, limit, page) => {
|
|
|
|
|
const { serverRuntimeConfig} = getConfig()
|
|
|
|
|
const qs = require('qs')
|
|
|
|
|
const query = qs.stringify({
|
|
|
|
|
filters: {
|
|
|
|
|
podcast_sery: {
|
|
|
|
|
Slug: {
|
|
|
|
|
$eq: podcastId
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
pagination: {
|
|
|
|
|
page: page,
|
|
|
|
|
pageSize: limit
|
|
|
|
|
},
|
|
|
|
|
sort: ['publishedAt:desc'],
|
|
|
|
|
populate: '*'
|
|
|
|
|
}, {
|
|
|
|
|
encodeValuesOnly: true,
|
|
|
|
|
})
|
|
|
|
|
const epres = await fetch(serverRuntimeConfig.base_path + `podcast-episodes?${query}`, {
|
|
|
|
|
headers: new Headers({
|
|
|
|
|
'Authorization': serverRuntimeConfig.strapi_token,
|
|
|
|
|
'Content-Type': 'application/x-www-form-urlencoded'
|
|
|
|
|
})
|
|
|
|
|
})
|
2022-06-20 15:22:16 +10:00
|
|
|
|
2022-06-22 21:37:22 +10:00
|
|
|
return await epres.json();
|
2022-06-26 14:59:45 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const getLatestPodcastEpisode = async () => {
|
|
|
|
|
const { serverRuntimeConfig} = getConfig()
|
|
|
|
|
const qs = require('qs')
|
|
|
|
|
var query = qs.stringify({
|
|
|
|
|
sort: ['publishedAt:desc'],
|
|
|
|
|
pagination: {
|
|
|
|
|
page: 1,
|
|
|
|
|
pageSize: 1,
|
|
|
|
|
},
|
|
|
|
|
populate: '*'
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
const epres = await fetch(serverRuntimeConfig.base_path + `podcast-episodes?${query}`, {
|
|
|
|
|
headers: new Headers({
|
|
|
|
|
'Authorization': serverRuntimeConfig.strapi_token,
|
|
|
|
|
'Content-Type': 'application/x-www-form-urlencoded'
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
const episode = await epres.json()
|
|
|
|
|
|
|
|
|
|
const seriesres = await getPodcastSeries(episode.data[0].attributes.podcast_sery.data.attributes.Slug)
|
|
|
|
|
|
|
|
|
|
const res = {
|
|
|
|
|
...episode,
|
|
|
|
|
...seriesres.data[0].attributes
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return res
|
2022-06-12 15:12:28 +10:00
|
|
|
}
|