expand "share" command
This commit is contained in:
parent
bdd320eab1
commit
dff4831a81
|
|
@ -1,14 +1,23 @@
|
||||||
import { apps } from "app/src/webapp"
|
import { apps } from "app/src/webapp"
|
||||||
import { connectSneaker } from "app/src/sneaker"
|
import { connectSneaker, sneakers, sneakerUrl } from "app/src/sneaker"
|
||||||
|
|
||||||
export default async function (app: string, subdomain = "") {
|
export default async function (app: string, subdomain = "") {
|
||||||
if (!app) {
|
if (!app) {
|
||||||
return `usage: share <app> [subdomain]`
|
let out = `usage: share <app> [subdomain]`
|
||||||
|
const apps = sneakers()
|
||||||
|
if (apps.length) {
|
||||||
|
out += "\n\nsharing\n" + apps.map(app => {
|
||||||
|
const url = sneakerUrl(app)
|
||||||
|
return `${app}: <a href="${url}">${url}</a>`
|
||||||
|
}).join("\n")
|
||||||
|
}
|
||||||
|
return { html: out }
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!apps().includes(app)) {
|
if (!apps().includes(app)) {
|
||||||
return { error: `${app} not found` }
|
return { error: `${app} not found` }
|
||||||
}
|
}
|
||||||
|
|
||||||
return await connectSneaker(app, subdomain)
|
const url = sneakerUrl(await connectSneaker(app, subdomain))
|
||||||
|
return { html: `<a href="${url}">${url}</a>` }
|
||||||
}
|
}
|
||||||
|
|
@ -11,6 +11,30 @@ type Connection = {
|
||||||
}
|
}
|
||||||
const conns: Record<string, Connection> = {}
|
const conns: Record<string, Connection> = {}
|
||||||
|
|
||||||
|
export function sneakerUrl(appOrSubdomain: string): string {
|
||||||
|
let conn = conns[appOrSubdomain]
|
||||||
|
if (!conn) {
|
||||||
|
for (const appName of Object.keys(conns)) {
|
||||||
|
if (conns[appName]?.subdomain === appOrSubdomain) {
|
||||||
|
conn = conns[appName]
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!conn)
|
||||||
|
return "none"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
let url = "http" + (SNEAKER_TLS ? "s" : "") + "://"
|
||||||
|
url += conn.subdomain + "." + SNEAKER_URL
|
||||||
|
|
||||||
|
return url
|
||||||
|
}
|
||||||
|
|
||||||
|
export function sneakers(): string[] {
|
||||||
|
return Object.keys(conns)
|
||||||
|
}
|
||||||
|
|
||||||
// returns the sneaker subdomain if successful
|
// returns the sneaker subdomain if successful
|
||||||
export async function connectSneaker(app: string, subdomain = ""): Promise<string> {
|
export async function connectSneaker(app: string, subdomain = ""): Promise<string> {
|
||||||
if (conns[app]) {
|
if (conns[app]) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user