From 7f397fe4977131794e8489d5abbc065b2ee1e4a4 Mon Sep 17 00:00:00 2001 From: MathMan05 Date: Thu, 29 Aug 2024 15:44:54 -0500 Subject: [PATCH] Fixes to the server list --- .dist/login.js | 15 +++++++++------ InstanceInfo.md | 11 ++++++++--- index.js | 28 +++++++++++++++++++++++++++- webpage/instances.json | 8 ++++---- webpage/login.ts | 17 ++++++++++------- webpage/register.html | 4 ++-- 6 files changed, 60 insertions(+), 23 deletions(-) diff --git a/.dist/login.js b/.dist/login.js index 5bd3f6e..b4f0817 100644 --- a/.dist/login.js +++ b/.dist/login.js @@ -422,16 +422,19 @@ if (datalist) { setTimeout(checkInstance, 10); } for (const instance of json) { + if (instance.display === false) { + continue; + } const option = document.createElement("option"); option.value = instance.name; - if (instance.URL) { - stringURLMap.set(option.value, instance.URL); - if (instance.URLs) { - stringURLsMap.set(instance.URL, instance.URLs); + if (instance.url) { + stringURLMap.set(option.value, instance.url); + if (instance.urls) { + stringURLsMap.set(instance.url, instance.urls); } } - else if (instance.URLs) { - stringURLsMap.set(option.value, instance.URLs); + else if (instance.urls) { + stringURLsMap.set(option.value, instance.urls); } else { option.disabled = true; diff --git a/InstanceInfo.md b/InstanceInfo.md index 8c61894..3e9b4b1 100644 --- a/InstanceInfo.md +++ b/InstanceInfo.md @@ -5,9 +5,12 @@ inside of webpage you'll see a file called `instances.json` in that file you'll "name":, "description"?:, "descriptionLong"?:, - "src"?:, - "URL"?:, - "URLs"?:{ + "image"?:, + "url"?:, + "language":, + "country":, + "display":, + "urls"?:{ "wellknown":, "api":, "cdn":, @@ -26,6 +29,8 @@ inside of webpage you'll see a file called `instances.json` in that file you'll ``` anything with a `?` in-front of its `:` are optional, though you must either include `"URL"` or `"URLs"`, but you may include both, though the client will most likely ignore `"URLs"` in favor of `"URL"`, though it may use `"URLs"` as a fallback if `"URL"` does not resolve, do not rely on this behavior. Some of these values may not be used right now, though they will likely be used in the future, so feel free to fill out what you like, though the more you fill out the more information we can give the users about your instance in the future. +language should be [ISO 639-1](https://en.wikipedia.org/wiki/ISO_639-1_codes). +Country should be [ISO 8166-2 alpha-2](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2). # Questions ## Do I have to do this to let Jank Client connect to my server? No, you may choose to not do this, this just makes it easier for people using Jank Client to find and use your instance as it's in the dropdown menu for instances, though the user may enter any instance they please. diff --git a/index.js b/index.js index a8af0a5..1ab22b7 100755 --- a/index.js +++ b/index.js @@ -4,8 +4,29 @@ const compression = require('compression') const express = require('express'); const fs = require('fs'); const app = express(); +const instances=require("./webpage/instances.json") +const instancenames=new Map(); +for(const instance of instances){ + instancenames.set(instance.name,instance); +} app.use(compression()) - +fetch("https://raw.githubusercontent.com/spacebarchat/spacebarchat/master/instances/instances.json").then(_=>_.json()).then(json=>{ + for(const instance of json){ + console.log(instance); + if(!instancenames.has(instance.name)){ + console.log("pushed"); + instances.push(instance); + console.log(instances) + }else{ + const ofinst=instancenames.get(instance.name) + for(const key of Object.keys(instance)){ + if(!ofinst[key]){ + ofinst[key]=instance[key]; + } + } + } + } +}) app.use("/getupdates",(req, res) => { const out=fs.statSync(`${__dirname}/webpage`); @@ -142,6 +163,11 @@ app.use('/', async (req, res) => { res.send("dud"); return; } + if(req.path.startsWith("/instances.json")){ + console.log("grabbed") + res.send(JSON.stringify(instances)); + return; + } if(req.path.startsWith("/invite/")){ res.sendFile(`./webpage/invite.html`, {root: __dirname}); return; diff --git a/webpage/instances.json b/webpage/instances.json index 578c366..b2da411 100644 --- a/webpage/instances.json +++ b/webpage/instances.json @@ -1,8 +1,8 @@ [ { - "name":"Spacebar Official", - "description":"The official instance of spacebar!", - "src":"https://cdn.old.server.spacebar.chat/icons/1006649183970562092/fb5218b5dfad5e1c7b452c17ddb1701e.png", - "URL":"https://spacebar.chat" + "name":"Spacebar", + "description":"The official Spacebar instance.", + "image":"https://raw.githubusercontent.com/spacebarchat/spacebarchat/master/branding/png/Spacebar__Icon-Discord.png", + "url":"https://spacebar.chat" } ] diff --git a/webpage/login.ts b/webpage/login.ts index 1f29885..d9e50ae 100644 --- a/webpage/login.ts +++ b/webpage/login.ts @@ -405,22 +405,25 @@ export {mobile, getBulkUsers,getBulkInfo,setTheme,Specialuser,getapiurls,adduser const datalist=document.getElementById("instances"); console.warn(datalist); if(datalist){ - fetch("/instances.json").then(_=>_.json()).then((json:{name:string,description?:string,src?:string,URL?:string,URLs:{wellknown:string,api:string,cdn:string,gateway:string,login?:string}}[])=>{ + fetch("/instances.json").then(_=>_.json()).then((json:{name:string,description?:string,src?:string,url?:string,display?:boolean,urls:{wellknown:string,api:string,cdn:string,gateway:string,login?:string}}[])=>{ console.warn(json); if(instancein&&instancein.value===""){ instancein.value=json[0].name; setTimeout(checkInstance,10); } for(const instance of json){ + if(instance.display===false){ + continue; + } const option=document.createElement("option"); option.value=instance.name; - if(instance.URL){ - stringURLMap.set(option.value,instance.URL); - if(instance.URLs){ - stringURLsMap.set(instance.URL,instance.URLs); + if(instance.url){ + stringURLMap.set(option.value,instance.url); + if(instance.urls){ + stringURLsMap.set(instance.url,instance.urls); } - }else if(instance.URLs){ - stringURLsMap.set(option.value,instance.URLs); + }else if(instance.urls){ + stringURLsMap.set(option.value,instance.urls); }else{ option.disabled=true; } diff --git a/webpage/register.html b/webpage/register.html index 601a431..f35ef56 100644 --- a/webpage/register.html +++ b/webpage/register.html @@ -20,12 +20,12 @@

- +

- +