ncd-bot/lib/api.js

33 lines
979 B
JavaScript
Raw Normal View History

2023-02-10 01:18:05 +00:00
// API reference: https://api.pleroma.social/ and https://docs-develop.pleroma.social/backend/development/API/pleroma_api/
'use strict';
import fetch from 'node-fetch';
export const getLatestStatuses = async (count) =>{
const headers = {Authorization: `Bearer ${process.env.ADMIN_BEARER}`};
const statusUrlArr = [];
if (!count){
count = 1;
}
try{
const res = await fetch(`https://${process.env.INSTANCE_NAME}/api/v1/pleroma/admin/statuses?page_size=${count}&godmode=false&local_only=false`, {
method: "GET",
headers: headers,
});
const data = await res.json();
for (let account in data){
statusUrlArr.push([
data[account].id,
data[account].account.username,
data[account].pleroma.conversation_id,
data[account].mentions,
]);
};
} catch (error){
throw new Error(error);
};
//console.log(statusUrlArr);
return statusUrlArr;
};