mirror of
https://github.com/versia-pub/server.git
synced 2026-04-27 20:59:15 +02:00
feat(federation): ✨ Port to Versia 0.6
This commit is contained in:
parent
de69f27877
commit
fca30b4dad
62 changed files with 1614 additions and 2008 deletions
|
|
@ -15,3 +15,31 @@ export class Entity {
|
|||
return this.data;
|
||||
}
|
||||
}
|
||||
|
||||
export class Reference {
|
||||
public constructor(
|
||||
public id: string,
|
||||
public domain?: string,
|
||||
) {}
|
||||
|
||||
public static fromString(str: string): Reference {
|
||||
// Expect format: domain:id or id (if domain is the local instance)
|
||||
// Handle IPv6 addresses in brackets
|
||||
const chunks = str.split(":");
|
||||
if (chunks.length === 2) {
|
||||
return new Reference(chunks[1], chunks[0]);
|
||||
}
|
||||
|
||||
if (chunks.length > 2) {
|
||||
const domain = chunks.slice(0, -1).join(":");
|
||||
const id = chunks.at(-1) as string;
|
||||
return new Reference(id, domain);
|
||||
}
|
||||
|
||||
return new Reference(str);
|
||||
}
|
||||
|
||||
public toString(): string {
|
||||
return this.domain ? `${this.domain}:${this.id}` : this.id;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue