Skip to content

Commit 4ae0e6e

Browse files
committed
feat(FR-2862): add preset mode for deployment revision creation
1 parent d5362fa commit 4ae0e6e

36 files changed

Lines changed: 2552 additions & 3486 deletions

packages/backend.ai-ui/src/helper/index.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,23 @@ export const isValidUUID = (uuid: string) => {
430430
return regex.test(uuid);
431431
};
432432

433+
/**
434+
* Resolve a UUID from either a raw UUID or a Strawberry global id like
435+
* `ImageV2:<uuid>`. Useful for mutation inputs that are declared as `ID!`
436+
* but parsed as `UUID!` server-side — callers can pass either form and get
437+
* a clean UUID back. `toLocalId` calls `atob`, which throws on non-base64
438+
* input, so we guard with try/catch and verify the decoded value is a UUID.
439+
*/
440+
export const safeDecodeUuid = (idOrGlobalId: string): string | undefined => {
441+
if (isValidUUID(idOrGlobalId)) return idOrGlobalId;
442+
try {
443+
const decoded = toLocalId(idOrGlobalId);
444+
return decoded && isValidUUID(decoded) ? decoded : undefined;
445+
} catch {
446+
return undefined;
447+
}
448+
};
449+
433450
export const convertToUUID = (id: string): string => {
434451
if (isValidUUID(id) && /^[0-9a-fA-F]{36}$/.test(id)) {
435452
return id;

0 commit comments

Comments
 (0)