(configText: string)
| 35 | } |
| 36 | |
| 37 | export function parseShareXConfig(configText: string): ShareXUploaderConfig { |
| 38 | let parsed: unknown; |
| 39 | const normalizedConfigText = configText.replace(/^\uFEFF/, "").trim(); |
| 40 | |
| 41 | try { |
| 42 | parsed = JSON.parse(normalizedConfigText); |
| 43 | } catch { |
| 44 | throw new Error("Invalid ShareX JSON"); |
| 45 | } |
| 46 | |
| 47 | if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) { |
| 48 | throw new Error("ShareX config must be a JSON object"); |
| 49 | } |
| 50 | |
| 51 | const config = parsed as ShareXUploaderConfig; |
| 52 | |
| 53 | if (!config.RequestURL || typeof config.RequestURL !== "string") { |
| 54 | throw new Error("ShareX RequestURL is required"); |
| 55 | } |
| 56 | |
| 57 | if (!isSupportedShareXDestination(config)) { |
| 58 | throw new Error("ShareX DestinationType must include FileUploader or ImageUploader"); |
| 59 | } |
| 60 | |
| 61 | return config; |
| 62 | } |
| 63 | |
| 64 | export function isSupportedShareXDestination(config: ShareXUploaderConfig): boolean { |
| 65 | const destinationTypes = parseDestinationTypes(config.DestinationType); |
no test coverage detected