-- Leo's gemini proxy
-- Connecting to git.thebackupbox.net:1965...
-- Connected
-- Sending request
-- Meta line: 20 text/gemini
repo: fmrl action: commit revision: path_from: revision_from: 45fb254f74b9fd861222152aa744c57ca291a9d3: path_to: revision_to:
commit 45fb254f74b9fd861222152aa744c57ca291a9d3 Author: epoch <epoch@hack.thebackupbox.net> Date: Sun Jan 16 08:55:08 2022 +0000 made it use user get params for the list of users to query. supports local and remote. remote only if javascript is on though. diff --git a/index.cgi b/index.cgi
--- a/index.cgi +++ b/index.cgi @@ -305,18 +305,28 @@ else echo '<script>' cat << EOF -function load(user,callback) { +function load(acct,callback) { let xhr=new XMLHttpRequest(); - xhr.open("GET","/fmrl/user/"+user,true); - if(document.getElementById(user)) { - xhr.setRequestHeader("If-Modified-Since",document.getElementById(user).mtime); + arr=acct.split("@"); + let user=arr[0]; + let host=arr.length>1?arr[1]:"thebackupbox.net"; + if(arr.length > 1) { + xhr.open("GET","https://" + host + "/fmrl/user/"+user,true); + } else { + xhr.open("GET","/fmrl/user/"+user,true); + } + if(document.getElementById(acct)) { + xhr.setRequestHeader("If-Modified-Since",document.getElementById(acct).mtime); } xhr.onreadystatechange = function() { if(xhr.readyState == 4 && xhr.status == "200") { - callback(user,xhr.responseText,new Date(xhr.getResponseHeader("Last-Modified"))); + callback(acct,user,host,xhr.responseText,new Date(xhr.getResponseHeader("Last-Modified"))); } - if(xhr.readyState == 4 && xhr.status == "304") { + else if(xhr.readyState == 4 && xhr.status == "304") { console.log("not doing stuff because " + user + " is cached"); + } else { + /* console.log(xhr); */ + /* wasn't able to detect preflight error from this data :/ */ } } xhr.send(null); @@ -336,8 +346,13 @@ function enable_notif() { } function check_user(user,mtime) { - return load(user,function(user,text,mtime) { - let node=document.getElementById(user); + return load(user,function(acct,user,host,text,mtime) { + let node=document.getElementById(acct); + if(!node) { + node=document.createElement("div"); + node.id=acct; + document.getElementById("statuses").appendChild(node); + } let data = JSON.parse(text); node.innerText=""; node.mtime=mtime; @@ -349,7 +364,7 @@ function check_user(user,mtime) { avatar.alt=data.name + "'s avatar"; node.appendChild(avatar); p=document.createElement("p"); - let first_line=data.name+" (@" + user + "@thebackupbox.net)"; + let first_line=data.name+" (@" + user + "@" + host + ")"; let second_line=data.emoji + " " + data.status; let third_line=mediaverb[data.media_type] + " " + data.media; p.appendChild(document.createTextNode(first_line + "\n")); @@ -370,7 +385,21 @@ function refuse_to_submit(e) { var users=[ EOF -ls /var/www/fmrl/.users | sed 's/^/"/g;s/$/",/g' + +user_list="$(printf "%s\n" "$QUERY_STRING" \ + | tr '&' '\n' \ + | grep ^user= \ + | cut -d= -f2- \ + | tr -cd 'a-z@_.\n-' \ + | sed 's/^@//g' \ + | cut -d@ -f1,2 \ + | sort \ + | uniq)" +printf "%s\n" "$user_list" \ + | sed 's/^/"/g;s/$/",/g' + +### this is local list. I want to allow user-settable list of users. +#ls /var/www/fmrl/.users | sed 's/^/"/g;s/$/",/g' cat <<EOF ] @@ -405,27 +434,31 @@ echo '<a href="https://git.thebackupbox.net/fmrl-client/tree/refs/heads/trunk">s #echo ' <input type="submit" />' #echo '</form>' echo '<div id="statuses">' -for user in /var/www/fmrl/.users/*;do - user="$(basename "$user")" - user_file="/var/www/fmrl/.users/${user}" - avatar="$(jq -r .avatar.original < "${user_file}")" - name="$(jq -r .name < "${user_file}")" - emoji="$(jq -r .emoji < "${user_file}")" - status="$(jq -r .status < "${user_file}")" - media_type="$(jq -r .media_type < "${user_file}")" - if [ "$media_type" = 0 ];then - media_type=7 +for user in $user_list;do + printf '<div id="%s">' "$user" + if ! grep '@' <<< "$user" 2>&1 >/dev/null;then #local user! + user_file=/var/www/fmrl/.users/${user} + avatar="$(jq -r .avatar.original < "${user_file}")" + name="$(jq -r .name < "${user_file}")" + emoji="$(jq -r .emoji < "${user_file}")" + status="$(jq -r .status < "${user_file}")" + media_type="$(jq -r .media_type < "${user_file}")" + if [ "$media_type" = 0 ];then + media_type=7 + fi + mediaverb="reading,watching,watching,listening to,listening to,playing,erroring" + media_verb="$(printf "%s\n" "$mediaverb" | cut -d, -f$media_type)" + media="$(jq -r .media < "${user_file}")" + printf '<div id="%s">\n' "$user" + printf '<img alt="%s'\''s avatar" class="avatar" width="48" height="48" src="%s" />\n' "$user" "$avatar" + printf '<p>\n' + printf '%s (@%s@%s)\n<br/>' "$name" "$user" "thebackupbox.net" + printf '%s %s\n<br/>' "$emoji" "$status" + printf '%s %s\n' "$media_verb" "$media" + printf '</p>\n' + else + printf 'not going to load remote user %s for you right now. javascript could get it though.' "$user" fi - mediaverb="reading,watching,watching,listening to,listening to,playing,erroring" - media_verb="$(printf "%s\n" "$mediaverb" | cut -d, -f$media_type)" - media="$(jq -r .media < "${user_file}")" - printf '<div id="%s">\n' "$user" - printf '<img alt="%s'\''s avatar" class="avatar" width="48" height="48" src="%s" />\n' "$user" "$avatar" - printf '<p>\n' - printf '%s (@%s@%s)\n<br/>' "$name" "$user" "thebackupbox.net" - printf '%s %s\n<br/>' "$emoji" "$status" - printf '%s %s\n' "$media_verb" "$media" - printf '</p>\n' printf '</div>\n' done echo '</div>'
-----END OF PAGE-----
-- Response ended
-- Page fetched on Sun Jun 2 18:15:26 2024