make statuses, images, videos work

This commit is contained in:
fenwick67 2019-07-31 14:48:51 -04:00
parent c48fdfd7ec
commit eae453813d
3 changed files with 45 additions and 16 deletions

View file

@ -95,7 +95,7 @@ app.get('/apiv2/feed',cors(),function(req,res){
res.send('You need to specify a user URL');
}
var feedUrl = req.query.feedUrl;
var feedUrl = req.query.feedurl;
var opts = {};
if (req.query.size){
@ -140,7 +140,7 @@ app.get('/apiv2/feed',cors(),function(req,res){
res.status(500);
res.send('Error fetching or parsing your feed.');
// TODO log the error
console.error(er);
console.error(er,er.stack);
})
})

View file

@ -41,13 +41,11 @@ module.exports = async function (opts) {
var feed = await apGet(feedUrl);
var items = itemsForFeed(feed);
var templateData = {
opts: opts,// from the request
meta: metaForUser(user),
items: itemsForFeed(feed),
nextPageLink: getNextPage(user,feed),
items: itemsForFeed(user,feed),
nextPageLink: getNextPage(opts,user,feed),
isIndex: isIndex
};
@ -65,29 +63,60 @@ function metaForUser(user) {
}
// TODO make function
function itemsForFeed(feed) {
return feed.orderedItems.map((item)=>{
function itemsForFeed(user,feed) {
return feed.orderedItems.filter((item)=>{
// this is temporary, don't handle boosts
return item.type == "Create" && item.object && item.object.type=="Note";
}).map((item)=>{
//needs to be { type, url }
var enclosures = (item.object.attachment||[]).filter((a)=>{
return a.type == "Document";
}).map((a)=>{
return {
type:a.mediaType,
url:a.url
}
});
return {
isBoost:false,
title:'',
title:'New Status by '+user.preferredUsername,
isReply:!!(item.object && item.object.inReplyTo),
hasCw:false,
cw:'',
content: item.object&&item.object.content?item.object.content:'',//TODO sanitize then render without entity escapes
atomHref:item.published?item.published.replace(/\W+/g,''):Math.random().toString().replace('.',''),
enclosures:[],//type, url
enclosures:enclosures,
stringDate:item.published?getTimeDisplay(Date.parse(item.published)):'',
author:{
uri:'',// link to author page
avatar:'',// url of av
fullName:'',// display name
uri:user.url,// link to author page
avatar:user.icon&&user.icon.url?user.icon.url:'',
displayName:user.name,
fullName:user.preferredUsername+'@'+(new URL(user.url).hostname),
}
}
})
}
// TODO
function getNextPage(user,feed){
return null;
function getNextPage(opts,user,feed){
//based on feed.next
// take feed.next, uriencode it, then take user url, then take options.mastofeedUrl
var base = opts.mastofeedUrl.slice(0,opts.mastofeedUrl.indexOf('?'));
var ret = '/apiv2/feed?userurl=' + encodeURIComponent(opts.userUrl) + '&feedurl=' +encodeURIComponent(feed.next);
// add other params to the end
(['theme','header','size','boosts','replies']).forEach((k)=>{
if (typeof opts[k] != 'undefined'){
ret+=`&${k}=${ opts[k].toString() }`;
}
})
return ret;
}

View file

@ -32,7 +32,7 @@
<%= meta.title %>
</a>
<br>
<%= meta.description %>
<%- meta.description %>
</div>
</div>
</div>