Files
drags-and-nerds/v1-com-officielle/src/data/msgData.js
T

53 lines
1.3 KiB
JavaScript

function idAndDate(str){
let data = str.split("T");
let date = data[0].split("-");
return {
date: date[2] +'/'+ date[1],
id: date[2] + date[1]
}
}
function titleAndContent(str){
let data = str.split(" :");
let title = data[0];
let contentData = data[1].split("<br>").filter(e => e);
let content = "";
for(let line of contentData){
content += line + '\n';
}
return {
title: title,
content: content
}
}
export async function loadMsgData() {
const res = await fetch("https://pouet.drags-nerds.net/api/v1/timelines/public?local=true&limit=40");
if(!res.ok) throw new Error(`Server responded with ${res.status} ${res.statusText}`);
const pouets = await res.json();
const filtered = pouets.filter(p => p.account.display_name === 'Drags and Nerds /Live');
//console.log(filtered);
let msgContent = [];
for (let pouet of filtered){
let textInfos = titleAndContent(pouet.content);
let dateInfos = idAndDate(pouet.created_at);
let entry = {
title: textInfos.title,
date: dateInfos.date,
dateInfo: pouet.created_at,
content: textInfos.content,
like: pouet.favourites_count,
isLiked: false,
wasRead: false,
isSelected: false
}
msgContent.push(entry);
}
return msgContent;
}