Small fix to Masto ID conversion code

This commit is contained in:
Luna 2023-03-13 00:44:38 -04:00
parent 75fd6d068d
commit f02b1429e9

View File

@ -30,7 +30,7 @@ export enum IdType {
export function convertId(idIn: string, idConvertTo: IdType ) {
let idArray = []
switch (idConvertTo) {
case IdType.CalckeyId:
case IdType.MastodonId:
idArray = [...idIn].map(item => item.charCodeAt(0));
idArray = idArray.map(item => {
if (item.toString().length < 3) {
@ -39,8 +39,11 @@ export function convertId(idIn: string, idConvertTo: IdType ) {
else return item.toString()
});
return idArray.join('');
case IdType.MastodonId:
case IdType.CalckeyId:
for (let i = 0; i < idIn.length; i += 3) {
if ((idIn.length % 3) !== 0) {
idIn = `0${idIn}`
}
idArray.push(idIn.slice(i, i+3));
}
idArray = idArray.map(item => String.fromCharCode(item));