type Bitbucket = {
username: string;
password: string;
};
/**
* Get a snippet's raw file
* Retrieves the raw contents of a specific file in the snippet. The
`Content-Disposition` header will be "attachment" to avoid issues with
malevolent executable files.
The file's mime type is derived from its filename and returned in the
`Content-Type` header.
Note that for text files, no character encoding is included as part of
the content type.
*/
export async function main(
auth: Bitbucket,
encoded_id: string,
node_id: string,
path: string,
workspace: string
) {
const url = new URL(
`https://api.bitbucket.org/2.0/snippets/${workspace}/${encoded_id}/${node_id}/files/${path}`
);
const response = await fetch(url, {
method: "GET",
headers: {
Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
},
body: undefined,
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.text();
}
Submitted by hugo697 425 days ago