import * as wmill from "windmill-client"
import { S3Object } from "windmill-client"
/**
* Download Attachment
* Download an attachment by its ID (from an issue's `fields.attachment[].id`) and write it to Windmill object storage, returning the S3 file reference.
*/
export async function main(
auth: RT.Jira,
attachment_id: string,
output_s3_path: string
) {
const url = new URL(
`https://${auth.domain}.atlassian.net/rest/api/3/attachment/content/${attachment_id}`
)
const response = await fetch(url, {
method: "GET",
headers: {
Authorization: `Basic ${btoa(`${auth.username}:${auth.password}`)}`,
},
})
if (!response.ok) {
throw new Error(`${response.status} ${await response.text()}`)
}
const output: S3Object = { s3: output_s3_path }
await wmill.writeS3File(output, await response.blob())
return output
}
Submitted by hugo989 5 hours ago