//native
type Box = {
token: string;
};
/**
* Get file information
* Retrieves the details about a file.
*/
export async function main(
auth: Box,
file_id: string,
fields: string | undefined,
if_none_match: string,
boxapi: string,
x_rep_hints: string,
) {
const url = new URL(`https://api.box.com/2.0/files/${file_id}`);
for (const [k, v] of [["fields", fields]]) {
if (v !== undefined && v !== "" && k !== undefined) {
url.searchParams.append(k, v);
}
}
const response = await fetch(url, {
method: "GET",
headers: {
"if-none-match": if_none_match,
boxapi: boxapi,
"x-rep-hints": x_rep_hints,
Authorization: "Bearer " + auth.token,
},
body: undefined,
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
Submitted by hugo697 235 days ago