fix: polish bark battle creation flow
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
export function normalizePublicCodeText(value: string) {
|
||||
export function normalizePublicCodeText(value: string) {
|
||||
return value
|
||||
.trim()
|
||||
.replace(/[^a-zA-Z0-9]/gu, '')
|
||||
@@ -53,6 +53,20 @@ export function buildBabyObjectMatchPublicWorkCode(profileId: string) {
|
||||
return `BO-${suffix}`;
|
||||
}
|
||||
|
||||
function normalizeBarkBattlePublicWorkCodeSuffix(workId: string) {
|
||||
const normalized = normalizePublicCodeText(workId);
|
||||
const withoutPrefix = normalized.startsWith('BB')
|
||||
? normalized.slice(2)
|
||||
: normalized;
|
||||
const fallback = withoutPrefix || normalized || '00000000';
|
||||
|
||||
return fallback.slice(-8).padStart(8, '0');
|
||||
}
|
||||
|
||||
export function buildBarkBattlePublicWorkCode(workId: string) {
|
||||
return `BB-${normalizeBarkBattlePublicWorkCodeSuffix(workId)}`;
|
||||
}
|
||||
|
||||
export function isSamePuzzlePublicWorkCode(keyword: string, profileId: string) {
|
||||
const normalizedKeyword = normalizePublicCodeText(keyword);
|
||||
|
||||
@@ -124,3 +138,14 @@ export function isSameBabyObjectMatchPublicWorkCode(
|
||||
normalizedKeyword === normalizePublicCodeText(profileId)
|
||||
);
|
||||
}
|
||||
|
||||
export function isSameBarkBattlePublicWorkCode(keyword: string, workId: string) {
|
||||
const normalizedKeyword = normalizePublicCodeText(keyword);
|
||||
|
||||
return (
|
||||
normalizedKeyword ===
|
||||
normalizePublicCodeText(buildBarkBattlePublicWorkCode(workId)) ||
|
||||
normalizedKeyword === normalizePublicCodeText(workId) ||
|
||||
normalizedKeyword === normalizeBarkBattlePublicWorkCodeSuffix(workId)
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user