45 lines
1.1 KiB
TypeScript
45 lines
1.1 KiB
TypeScript
export interface BootstrapRemoteSkillRequestLike {
|
|
thread_id: string;
|
|
content_ids?: number[];
|
|
content_id?: number;
|
|
language_type?: number;
|
|
target_dir?: string;
|
|
clear_target?: boolean;
|
|
}
|
|
|
|
export interface NormalizedBootstrapRemoteSkillRequest
|
|
extends Omit<BootstrapRemoteSkillRequestLike, "content_id" | "content_ids"> {
|
|
content_ids: number[];
|
|
}
|
|
|
|
export function normalizeBootstrapRemoteSkillRequest(
|
|
request: BootstrapRemoteSkillRequestLike,
|
|
): NormalizedBootstrapRemoteSkillRequest {
|
|
const normalizedContentIds = Array.isArray(request.content_ids)
|
|
? request.content_ids
|
|
.map((id) => Number(id))
|
|
.filter((id) => Number.isFinite(id) && id > 0)
|
|
: [];
|
|
|
|
const legacyContentId =
|
|
request.content_id != null && Number.isFinite(Number(request.content_id))
|
|
? Number(request.content_id)
|
|
: undefined;
|
|
|
|
const contentIds =
|
|
normalizedContentIds.length > 0
|
|
? normalizedContentIds
|
|
: legacyContentId != null
|
|
? [legacyContentId]
|
|
: [];
|
|
|
|
if (contentIds.length === 0) {
|
|
throw new Error("content_ids is required.");
|
|
}
|
|
|
|
return {
|
|
...request,
|
|
content_ids: contentIds,
|
|
};
|
|
}
|