117 lines
No EOL
2.8 KiB
JavaScript
Executable file
117 lines
No EOL
2.8 KiB
JavaScript
Executable file
import getConfig from 'next/config'
|
|
|
|
export const getAllPosts = async (filter, page, limit) => {
|
|
|
|
const { serverRuntimeConfig, publicRuntimeConfig } = getConfig()
|
|
const qs = require('qs')
|
|
const qVal = []
|
|
|
|
if (page == null) {
|
|
page = 0
|
|
}
|
|
|
|
if (limit == null) {
|
|
limit = 50;
|
|
}
|
|
|
|
var filters = {}
|
|
|
|
if (filter) {
|
|
const tagList = []
|
|
filter.data.forEach(tag => {
|
|
console.log(tag)
|
|
tagList.push(tag.attributes.Slug)
|
|
})
|
|
|
|
filters = {
|
|
tags: {
|
|
Slug: {
|
|
$in: tagList
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
const qArray = {
|
|
sort: ['publishedAt:desc'],
|
|
pagination: {
|
|
page: page,
|
|
pageSize: limit
|
|
},
|
|
filters
|
|
}
|
|
|
|
const query = qs.stringify( qArray, {
|
|
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()
|
|
}
|
|
|
|
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
|
|
}
|
|
|
|
export const getAllPodcastSeries = async () => {
|
|
const { serverRuntimeConfig } = getConfig()
|
|
const qs = require('qs')
|
|
const query = qs.stringify({
|
|
populate: {
|
|
podcast_episodes: {
|
|
populate:['Audio']
|
|
}
|
|
}
|
|
}, {
|
|
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'
|
|
})
|
|
})
|
|
|
|
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'
|
|
})
|
|
})
|
|
|
|
return await res.json()
|
|
} |