File size: 838 Bytes
81587dd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
export type AcceptedImageTaskDetails = {
    taskId?: string;
    pollUrl?: string;
};

export function readAcceptedImageTaskDetails(result: unknown): AcceptedImageTaskDetails | undefined {
    if (!result || typeof result !== 'object' || Array.isArray(result)) return undefined;
    const record = result as Record<string, unknown>;
    if (readTrimmedString(record.object) !== 'image.task' || readTrimmedString(record.status) !== 'pending') {
        return undefined;
    }

    const taskId = readTrimmedString(record.task_id);
    const pollUrl = readTrimmedString(record.poll_url);
    return {
        ...(taskId ? { taskId } : {}),
        ...(pollUrl ? { pollUrl } : {})
    };
}

function readTrimmedString(value: unknown): string | undefined {
    return typeof value === 'string' && value.trim() ? value.trim() : undefined;
}