feat(misskey-js): acct.parseがURLを受け付けるように, acct.tsのテストを追加

This commit is contained in:
tamaina 2025-08-26 14:28:43 +09:00
parent 14f5456ef0
commit a8eff662e3
1 changed files with 12 additions and 12 deletions

View File

@ -3,6 +3,16 @@ export type Acct = {
host: string | null;
};
export function correctAcct(acct: Acct, localHostname?: string): Acct {
const result = { ...acct };
if (!acct.host) {
result.host = null;
} else if (localHostname && acct.host === localHostname) {
result.host = null;
}
return result;
}
/**
* Parses a string and returns an Acct object.
* @param acct String to parse
@ -22,12 +32,7 @@ export function parse(acct: string, localHostname?: string): Acct {
const split = path.split('@', 3); // ['', 'username', 'other.example.com']
let host: string | null = split[2] || url.hostname;
if (localHostname && host === localHostname) {
host = null;
}
return { username: split[1], host: host };
return correctAcct({ username: split[1], host: split[2] || url.hostname }, localHostname);
}
//#endregion
@ -40,12 +45,7 @@ export function parse(acct: string, localHostname?: string): Acct {
}
const split = acctWithNoPrefix.split('@', 2);
let host: string | null = split[1] || null;
if (localHostname && host === localHostname) {
host = null;
}
return { username: split[0], host };
return correctAcct({ username: split[0], host: split[1] || null }, localHostname);
//#endregion
}