Extract admin dashboard from ghabilee-frontend2 into a dedicated Next.js app for backoffice.ghabilee.ir (no SEO indexing / Clarity).
27 lines
730 B
TypeScript
27 lines
730 B
TypeScript
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
return typeof value === 'object' && value !== null && !Array.isArray(value)
|
|
}
|
|
|
|
export interface UploadedFilePayload {
|
|
id?: string
|
|
url: string
|
|
}
|
|
|
|
/**
|
|
* Parse `{ data: { id?, url } }` (or nested API envelope) from axios upload responses.
|
|
*/
|
|
export function parseUploadedFile(raw: unknown): UploadedFilePayload | null {
|
|
if (!isRecord(raw)) return null
|
|
|
|
const nested = isRecord(raw.data) ? raw.data : raw
|
|
const payload = isRecord(nested.data) ? nested.data : nested
|
|
const url = typeof payload.url === 'string' ? payload.url : null
|
|
|
|
if (!url) return null
|
|
|
|
return {
|
|
url,
|
|
id: typeof payload.id === 'string' ? payload.id : undefined,
|
|
}
|
|
}
|