From 8a6a0055027986381bb58f5ab58d8ca0cbee42d6 Mon Sep 17 00:00:00 2001 From: Sam Therapy Date: Sun, 6 Feb 2022 18:46:21 -0600 Subject: [PATCH] change var to let Signed-off-by: Sam Therapy --- lib/convert.js | 46 ++++++++++++++++++++--------------------- lib/errorPage.js | 6 +++--- lib/template.ejs | 16 +++++++------- src/build-styles.js | 12 +++++------ src/index.js | 8 ++++--- src/public/js/script.js | 12 +++++------ test/test.js | 2 +- 7 files changed, 52 insertions(+), 50 deletions(-) diff --git a/lib/convert.js b/lib/convert.js index fcf97b4..a3ebd84 100644 --- a/lib/convert.js +++ b/lib/convert.js @@ -1,6 +1,6 @@ import { compile } from "ejs"; import { readFileSync } from "fs"; -var template = compile(readFileSync("./lib/template.ejs", "utf8")); +let template = compile(readFileSync("./lib/template.ejs", "utf8")); import { format } from "timeago.js"; import got from "got"; @@ -56,17 +56,17 @@ async function promiseSome(proms){ } export default async function (opts) { - // var opts = opts; + // let opts = opts; - var feedUrl = opts.feedUrl; - var userUrl = opts.userUrl; - var isIndex = false; + let feedUrl = opts.feedUrl; + let userUrl = opts.userUrl; + let isIndex = false; if (!userUrl) { throw new Error("need user URL"); } - var user, feed; + let user, feed; // get user and feed in parallel if I have both URLs. // can cache feed aggressively since it is a specific start and end. @@ -77,7 +77,7 @@ export default async function (opts) { user = await apGet(userUrl,24 * hour); isIndex = true; - var outbox = await apGet(user.outbox, 1 * hour); + let outbox = await apGet(user.outbox, 1 * hour); // outbox.first can be a string for a URL, or an object with stuffs in it if (typeof outbox.first == "object"){ @@ -88,7 +88,7 @@ export default async function (opts) { } - var templateData = { + let templateData = { opts: opts,// from the request meta: metaForUser(user), items: await itemsForFeed(opts,user,feed), @@ -112,12 +112,12 @@ function metaForUser(user) { async function itemsForFeed(opts,user,feed) { - var items = feed.orderedItems; + let items = feed.orderedItems; if (opts.boosts){ // yes, I have to fetch all the fucking boosts for this whole feed apparently >:/ - var boostData = []; - var boostUrls = feed.orderedItems.filter(i=>i.type=="Announce").map(i=>i.object); + let boostData = []; + let boostUrls = feed.orderedItems.filter(i=>i.type=="Announce").map(i=>i.object); // console.log(boostUrls); boostData = await promiseSome(boostUrls.map(apGet)); @@ -125,7 +125,7 @@ async function itemsForFeed(opts,user,feed) { let userData = await promiseSome(boostData.map(d=>d?d.attributedTo||"":null).map(apGet)); // put a ._userdata key on the item object if this is a boost - for (var i = 0; i < boostData.length; i ++){ + for (let i = 0; i < boostData.length; i ++){ if (userData[i] && boostData[i]){ boostData[i]._userdata = userData[i]; } @@ -143,8 +143,8 @@ async function itemsForFeed(opts,user,feed) { // inject in-place into items - var index = -1; - for (var i = 0; i < items.length; i ++){ + let index = -1; + for (let i = 0; i < items.length; i ++){ if (items[i].object == boostToot.id){ index = i; break; @@ -166,7 +166,7 @@ async function itemsForFeed(opts,user,feed) { return typeof item.object == "object";// handle weird cases }).map((item)=>{ - var enclosures = (item.object.attachment||[]).filter((a)=>{ + let enclosures = (item.object.attachment||[]).filter((a)=>{ return a.type == "Document"; }).map((a)=>{ return { @@ -176,7 +176,7 @@ async function itemsForFeed(opts,user,feed) { }; }); - var op = item._userdata?item._userdata:user; + let op = item._userdata?item._userdata:user; return { isBoost:!!item._userdata, @@ -203,9 +203,9 @@ function getNextPage(opts,user,feed){ //based on feed.next if (!feed.next){return null;} // take feed.next, uriencode it, then take user url, then take options.mastofeedUrl - //var base = opts.mastofeedUrl.slice(0,opts.mastofeedUrl.indexOf("?")); + //let base = opts.mastofeedUrl.slice(0,opts.mastofeedUrl.indexOf("?")); - var ret = "/api/v1/feed?userurl=" + encodeURIComponent(opts.userUrl) + "&feedurl=" +encodeURIComponent(feed.next) + "&instance_type=" + opts.instance_type; + let ret = "/api/v1/feed?userurl=" + encodeURIComponent(opts.userUrl) + "&feedurl=" +encodeURIComponent(feed.next) + "&instance_type=" + opts.instance_type; // add other params to the end (["theme","header","size","boosts","replies"]).forEach((k)=>{ @@ -220,15 +220,15 @@ function getNextPage(opts,user,feed){ // utilities below function getTimeDisplay(d) { - // var d = d; + // let d = d; if (typeof d !== "object") { d = new Date(d); } // convert to number let dt = d.getTime(); - var now = Date.now(); + let now = Date.now(); - var delta = now - dt; + let delta = now - dt; // over 6 days ago if (delta > 1000 * 60 * 60 * 24 * 6) { @@ -241,8 +241,8 @@ function getTimeDisplay(d) { function isoDateToEnglish(d) { - var dt = d.split(/[t-]/ig); - var months = ["January", "February", "March", "April", "May", "June", + let dt = d.split(/[t-]/ig); + let months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]; return months[Number(dt[1]) - 1] + " " + dt[2] + ", " + dt[0]; diff --git a/lib/errorPage.js b/lib/errorPage.js index cf80008..297d8bb 100644 --- a/lib/errorPage.js +++ b/lib/errorPage.js @@ -1,10 +1,10 @@ import { compile } from "ejs"; import { readFileSync } from "fs"; -var template = compile(readFileSync("./lib/template.ejs", "utf8")); +let template = compile(readFileSync("./lib/template.ejs", "utf8")); export default function(code,message,displayOptions){ - var msg; + let msg; // const displayOptions = displayOptions || {}; if (code == 500 && !message){ @@ -14,7 +14,7 @@ export default function(code,message,displayOptions){ } - var options = { + let options = { opts:{ header:true, theme:displayOptions.theme||null, diff --git a/lib/template.ejs b/lib/template.ejs index d2c1f18..cc31ec9 100644 --- a/lib/template.ejs +++ b/lib/template.ejs @@ -51,7 +51,7 @@
- <% var filtered = items.filter(function(item){return !((item.isBoost && !opts.boosts) || (item.isReply && !opts.replies)) })%> + <% let filtered = items.filter(function(item){return !((item.isBoost && !opts.boosts) || (item.isReply && !opts.replies)) })%> <% filtered.forEach(function(item){ %>
<% if (item.isBoost) { %> @@ -67,7 +67,7 @@
<% if (item.hasCw){ %> - <% var cwId = (item.cw+item.atomHref).replace(/\W+/g,'') %> + <% let cwId = (item.cw+item.atomHref).replace(/\W+/g,'') %> <%- item.cw %> @@ -79,8 +79,8 @@ <% if (item.enclosures.length > 0){ %>
- <% for (var i = 0; i < item.enclosures.length; i ++){ %> - <% var e = item.enclosures[i] %> + <% for (let i = 0; i < item.enclosures.length; i ++){ %> + <% let e = item.enclosures[i] %> <% if (e.type.indexOf('audio') > -1) {%>