change var to let

Signed-off-by: Sam Therapy <sam@samtherapy.net>
This commit is contained in:
Sam Therapy 2022-02-06 18:46:21 -06:00
parent dce7ececa7
commit 8a6a005502
Signed by untrusted user: sam
GPG key ID: 4D8B07C18F31ACBD
7 changed files with 52 additions and 50 deletions

View file

@ -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];

View file

@ -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,

View file

@ -51,7 +51,7 @@
<div class="container">
<% 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){ %>
<div class="item">
<% if (item.isBoost) { %>
@ -67,7 +67,7 @@
</div>
</div>
<% if (item.hasCw){ %>
<% var cwId = (item.cw+item.atomHref).replace(/\W+/g,'') %>
<% let cwId = (item.cw+item.atomHref).replace(/\W+/g,'') %>
<span class="cw"><%- item.cw %></span>
<input type="checkbox" class="showmore" id="<%- cwId %>">
<label class="button" for="<%- cwId %>">Show</label>
@ -79,8 +79,8 @@
<% if (item.enclosures.length > 0){ %>
<div class="enclosures">
<% 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) {%>
<audio class="enclosure" controls loop src="<%= e.url %>"/>
<% }else if (e.type.indexOf('video') > -1){ %>
@ -116,8 +116,8 @@
<script src="/infinite-scroll.js"></script>
<script type="text/javascript">
var lastPageLoaded = null;
var infScroll = new InfiniteScroll( '.container', {
let lastPageLoaded = null;
let infScroll = new InfiniteScroll( '.container', {
// options
hideNav:'.pagination',
append: '.item',
@ -125,12 +125,12 @@
prefill:true,
path: function(){
// need to query this DOM my damn self
var pageLinks = document.querySelectorAll('.hacky_link');
let pageLinks = document.querySelectorAll('.hacky_link');
if (!pageLinks || pageLinks.length == 0){
console.log ('next page link could not be found');
return false;
}else{
var finalLink = pageLinks[pageLinks.length-1].href;
let finalLink = pageLinks[pageLinks.length-1].href;
// make sure we don't load the same page twice
if (!finalLink || finalLink == window.location.href || finalLink == lastPageLoaded){
console.log('this was the last page');

View file

@ -2,15 +2,15 @@
import { readFileSync, writeFileSync } from "fs";
import { renderSync } from "node-sass";
var staticDir = "./src/public/";
var srcDir = "./src/stylesrc/";
var themes = ["masto-light","masto-dark","masto-auto"];
let staticDir = "./src/public/";
let srcDir = "./src/stylesrc/";
let themes = ["masto-light","masto-dark","masto-auto"];
themes.forEach(function(s){
var sassFile = srcDir+s+".scss";
var cssFile = staticDir+s+".css";
var result = renderSync({
let sassFile = srcDir+s+".scss";
let cssFile = staticDir+s+".css";
let result = renderSync({
data: readFileSync(sassFile,"utf8"),
includePaths:[srcDir]
});

View file

@ -59,7 +59,9 @@ app.get("/api/v1/feed", cors(), logger, async function(req, res) {
if (type === "") {
const user = req.query.user;
const instance = req.query.instance;
let instanceType = await detector(instance);
let instanceType = await detector(instance).catch(() =>
""
);
if (instanceType === "mastodon" || instanceType === "pleroma") {
userUrl = instance + "/users/" + user;
type = instanceType;
@ -67,8 +69,8 @@ app.get("/api/v1/feed", cors(), logger, async function(req, res) {
userUrl = instance + "/@" + user;
type = instanceType;
} else {
res.status(400);
res.send(errorPage(400, "You need to specify a user URL"));
res.status(500);
res.send(errorPage(500, "You need to specify a user URL"));
return;
}
} else {

View file

@ -6,18 +6,18 @@ window.genUrl = function genUrl() {
let user = val("usernamein");
let instance = "https://" + val("urlin");
var showBoosts = (!document.getElementById("hideboosts").checked).toString();
var showReplies = (!document.getElementById("hidereplies").checked).toString();
var showHeader = document.getElementById("header").checked.toString();
var portStr = (window.location.port && window.location.port != 80) ? (":" + window.location.port) : "";
let showBoosts = (!document.getElementById("hideboosts").checked).toString();
let showReplies = (!document.getElementById("hidereplies").checked).toString();
let showHeader = document.getElementById("header").checked.toString();
let portStr = (window.location.port && window.location.port != 80) ? (":" + window.location.port) : "";
var iframeUrl = window.location.protocol + "//" + window.location.hostname + portStr
let iframeUrl = window.location.protocol + "//" + window.location.hostname + portStr
+ "/api/v1/feed?user=" + encodeURIComponent(user) + "&instance=" + encodeURIComponent(instance) + "&instance_type=" + "&theme=" + val("theme") + "&size=" + val("size")
+ "&header=" + showHeader + "&replies=" + showReplies + "&boosts=" + showBoosts;
document.getElementById("result").value = "<iframe allowfullscreen sandbox=\"allow-top-navigation allow-scripts\" width=\"" + val("width") + "\" height=\"" + val("height") + "\" src=\"" + iframeUrl + "\"></iframe>";
var iframe = document.getElementById("frame");
let iframe = document.getElementById("frame");
iframe.src = iframeUrl;
iframe.width = val("width");
iframe.height = val("height");

View file

@ -5,7 +5,7 @@ import { createReadStream, writeFileSync } from "fs";
import convert from "../lib/convert.js";
var r = createReadStream("./test/sample.atom");
let r = createReadStream("./test/sample.atom");
convert(r,function(er,data){
if (er){return console.log("error: ",er);}