Small fix to Masto ID conversion code
This commit is contained in:
parent
7236aa4a3a
commit
e198a34cd0
1 changed files with 5 additions and 2 deletions
|
@ -30,7 +30,7 @@ export enum IdType {
|
||||||
export function convertId(idIn: string, idConvertTo: IdType ) {
|
export function convertId(idIn: string, idConvertTo: IdType ) {
|
||||||
let idArray = []
|
let idArray = []
|
||||||
switch (idConvertTo) {
|
switch (idConvertTo) {
|
||||||
case IdType.CalckeyId:
|
case IdType.MastodonId:
|
||||||
idArray = [...idIn].map(item => item.charCodeAt(0));
|
idArray = [...idIn].map(item => item.charCodeAt(0));
|
||||||
idArray = idArray.map(item => {
|
idArray = idArray.map(item => {
|
||||||
if (item.toString().length < 3) {
|
if (item.toString().length < 3) {
|
||||||
|
@ -39,8 +39,11 @@ export function convertId(idIn: string, idConvertTo: IdType ) {
|
||||||
else return item.toString()
|
else return item.toString()
|
||||||
});
|
});
|
||||||
return idArray.join('');
|
return idArray.join('');
|
||||||
case IdType.MastodonId:
|
case IdType.CalckeyId:
|
||||||
for (let i = 0; i < idIn.length; i += 3) {
|
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.push(idIn.slice(i, i+3));
|
||||||
}
|
}
|
||||||
idArray = idArray.map(item => String.fromCharCode(item));
|
idArray = idArray.map(item => String.fromCharCode(item));
|
||||||
|
|
Loading…
Reference in a new issue