mirror of
https://github.com/MadsLorentzen/ai-job-search.git
synced 2026-09-17 08:36:25 +00:00
fix(portal-clis): accept full posting URLs in jobbank, jobdanmark, and jobnet detail commands (#430)
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { defineCommand, option } from "@bunli/core"
|
||||
import { z } from "zod"
|
||||
import { apiFetch, writeError, stripHtml } from "../helpers.js"
|
||||
import { apiFetch, normalizeJobId, writeError, stripHtml } from "../helpers.js"
|
||||
|
||||
export interface DetailApiResponse {
|
||||
id: string
|
||||
@@ -87,12 +87,18 @@ export const detail = defineCommand({
|
||||
handler: async ({ positional, flags, signal }) => {
|
||||
if (signal.aborted) return
|
||||
|
||||
const id = positional[0] as string | undefined
|
||||
if (!id) {
|
||||
const rawId = positional[0] as string | undefined
|
||||
if (!rawId) {
|
||||
writeError("Job ad ID is required", "MISSING_REQUIRED")
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
const id = normalizeJobId(rawId)
|
||||
if (!id) {
|
||||
writeError(`Could not parse job ad ID from "${rawId}"`, "BAD_ID")
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
try {
|
||||
const data = prepareDetail(
|
||||
await apiFetch<DetailApiResponse>(`/FindJob/JobAdDetails/${id}`, {
|
||||
|
||||
@@ -55,3 +55,13 @@ export function stripHtml(html: string): string {
|
||||
.replace(/\s+/g, " ")
|
||||
.trim()
|
||||
}
|
||||
|
||||
export function normalizeJobId(input: string): string | null {
|
||||
const trimmed = input.trim()
|
||||
if (!trimmed) return null
|
||||
if (/^[a-zA-Z0-9_-]+$/.test(trimmed)) return trimmed
|
||||
const match = trimmed.match(/(?:\/find-job\/|\/JobAdDetails\/|\/Details\/)(?:detaljer\/)?([a-zA-Z0-9_-]+)(?:\/|$|\?|#)/i)
|
||||
if (match) return match[1]
|
||||
return null
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user