feat: use a standard custom ID format in role buttons
This commit is contained in:
parent
784c54b22a
commit
b64611dd01
4 changed files with 30 additions and 3 deletions
3
backend/src/utils/buildCustomId.ts
Normal file
3
backend/src/utils/buildCustomId.ts
Normal file
|
@ -0,0 +1,3 @@
|
|||
export function buildCustomId(namespace: string, data: any = {}) {
|
||||
return `${namespace}:${Date.now()}:${JSON.stringify(data)}`;
|
||||
}
|
17
backend/src/utils/parseCustomId.ts
Normal file
17
backend/src/utils/parseCustomId.ts
Normal file
|
@ -0,0 +1,17 @@
|
|||
const customIdFormat = /^([^:]+):\d+:(.*)$/;
|
||||
|
||||
export function parseCustomId(customId: string): { namespace: string; data: any } {
|
||||
const parts = customId.match(customIdFormat);
|
||||
if (!parts) {
|
||||
return {
|
||||
namespace: "",
|
||||
data: null,
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
namespace: parts[1],
|
||||
// Skipping timestamp
|
||||
data: JSON.parse(parts[2]),
|
||||
};
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue