type Trello = {
key: string;
token: string;
};
/**
* Create Attachment On Card
* Create an Attachment to a Card
*/
export async function main(
auth: Trello,
id: string,
name: string | undefined,
file: string | undefined,
mimeType: string | undefined,
url: string | undefined,
setCover: string | undefined
) {
const url_ = new URL(`https://api.trello.com/1/cards/${id}/attachments`);
for (const [k, v] of [
["name", name],
["file", file],
["mimeType", mimeType],
["url", url],
["setCover", setCover],
["key", auth.key],
["token", auth.token],
]) {
if (v !== undefined && v !== "") {
url_.searchParams.append(k, v);
}
}
const response = await fetch(url_, {
method: "POST",
headers: {
Authorization: undefined,
},
body: undefined,
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
Submitted by hugo697 398 days ago
type Trello = {
key: string;
token: string;
};
/**
* Create Attachment On Card
* Create an Attachment to a Card
*/
export async function main(
auth: Trello,
id: string,
name: string | undefined,
file: string | undefined,
mimeType: string | undefined,
url: string | undefined,
setCover: string | undefined
) {
const url_ = new URL(`https://api.trello.com/1/cards/${id}/attachments`);
for (const [k, v] of [
["name", name],
["file", file],
["mimeType", mimeType],
["url", url],
["setCover", setCover],
["key", auth.key],
["token", auth.token],
]) {
if (v !== undefined && v !== "") {
url_.searchParams.append(k, v);
}
}
const response = await fetch(url_, {
method: "POST",
headers: {
Authorization: undefined,
},
body: undefined,
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
Submitted by hugo697 953 days ago