//native
type Confluence = {
email: string
apiToken: string
domain: string
}
/**
* Asynchronously convert content body
* Converts a content body from one format to another format asynchronously.
*/
export async function main(
auth: Confluence,
to: 'export_view',
expand: string | undefined,
spaceKeyContext: string | undefined,
contentIdContext: string | undefined,
allowCache: string | undefined,
embeddedContentRender: 'current' | 'version-at-save' | undefined,
body: {
value: string
representation:
| 'view'
| 'export_view'
| 'styled_view'
| 'storage'
| 'editor'
| 'editor2'
| 'anonymous_export_view'
| 'wiki'
| 'atlas_doc_format'
| 'plain'
| 'raw'
}
) {
const url = new URL(`https://${auth.domain}/wiki/rest/api/contentbody/convert/async/${to}`)
for (const [k, v] of [
['expand', expand],
['spaceKeyContext', spaceKeyContext],
['contentIdContext', contentIdContext],
['allowCache', allowCache],
['embeddedContentRender', embeddedContentRender]
]) {
if (v !== undefined && v !== '' && k !== undefined) {
url.searchParams.append(k, v)
}
}
const response = await fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: 'Basic ' + btoa(`${auth.email}:${auth.apiToken}`)
},
body: JSON.stringify(body)
})
if (!response.ok) {
const text = await response.text()
throw new Error(`${response.status} ${text}`)
}
return await response.json()
}
Submitted by hugo697 235 days ago