2023-01-25 22:41:11 +05:30
|
|
|
import { env } from "$env/dynamic/private";
|
|
|
|
import axios from "axios";
|
|
|
|
import { Agent } from "https";
|
|
|
|
|
|
|
|
const agent = new Agent({
|
|
|
|
family: 4
|
|
|
|
});
|
|
|
|
|
2023-02-03 23:25:33 +05:30
|
|
|
const fetchGhost = async (action: string, additional?: string) => {
|
2023-01-25 22:41:11 +05:30
|
|
|
try {
|
2023-02-03 23:25:33 +05:30
|
|
|
const request = await axios(
|
|
|
|
env.GHOST_URL +
|
|
|
|
"/ghost/api/content/" +
|
|
|
|
action +
|
|
|
|
"/?key=" +
|
|
|
|
env.GHOST_API_KEY +
|
|
|
|
"&include=authors,tags&limit=all&formats=html,plaintext" +
|
|
|
|
(additional ? additional : ""),
|
|
|
|
{ httpsAgent: agent }
|
|
|
|
);
|
2023-01-25 22:41:11 +05:30
|
|
|
|
|
|
|
if (request.status === 200) {
|
|
|
|
return request.data;
|
|
|
|
} else {
|
|
|
|
return { error: true, message: "Error: " + request.status };
|
|
|
|
}
|
|
|
|
} catch (err) {
|
|
|
|
return { error: true, message: "Error: " + err };
|
|
|
|
}
|
2023-02-03 23:25:33 +05:30
|
|
|
};
|
2023-01-25 22:41:11 +05:30
|
|
|
|
2023-02-03 23:25:33 +05:30
|
|
|
export default fetchGhost;
|