Adjusted admin follow to accept [@]user@domain.tld format
This commit is contained in:
parent
2701786de8
commit
283220111f
1 changed files with 21 additions and 3 deletions
24
src/admin.ts
24
src/admin.ts
|
@ -2,7 +2,7 @@ import { idsFromValue } from "./activitypub"
|
|||
import * as db from "./db"
|
||||
import { ACTOR, ADMIN_PASSWORD, ADMIN_USERNAME, BASE_URL } from "./env"
|
||||
import outbox from "./outbox"
|
||||
import { fetchObject } from "./request"
|
||||
import { activityMimeTypes, fetchObject } from "./request"
|
||||
|
||||
export default (req: Request): Response | Promise<Response> | undefined => {
|
||||
const url = new URL(req.url)
|
||||
|
@ -78,13 +78,31 @@ const create = async (req:Request, inReplyTo:string|null = null):Promise<Respons
|
|||
}
|
||||
|
||||
const follow = async (req:Request, handle:string):Promise<Response> => {
|
||||
let url
|
||||
if(handle.startsWith('@')) handle = handle.substring(1)
|
||||
try {
|
||||
url = new URL(handle).href
|
||||
}
|
||||
catch {
|
||||
// this is not a valid url. Probably a someone@domain.tld format
|
||||
const [user, host] = handle.split('@')
|
||||
const res = await fetch(`https://${host}/.well-known/webfinger/?resource=acct:${handle}`)
|
||||
const webfinger = await res.json()
|
||||
if(!webfinger.links) return new Response("", { status: 404 })
|
||||
const links:any[] = webfinger.links
|
||||
const actorLink = links.find(l => l.rel === "self" && (activityMimeTypes.includes(l.type)))
|
||||
if(!actorLink) return new Response("", { status: 404 })
|
||||
url = actorLink.href
|
||||
}
|
||||
console.log(`Follow ${url}`)
|
||||
|
||||
// send the follow request to the supplied actor
|
||||
return await outbox({
|
||||
"@context": "https://www.w3.org/ns/activitystreams",
|
||||
type: "Follow",
|
||||
actor: ACTOR,
|
||||
object: handle,
|
||||
to: [handle, "https://www.w3.org/ns/activitystreams#Public"]
|
||||
object: url,
|
||||
to: [url, "https://www.w3.org/ns/activitystreams#Public"]
|
||||
})
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue