obj-drive-viewer / src /driveApi.js
hrkjt's picture
Upload folder using huggingface_hub
69bd9f7 verified
Raw
History Blame Contribute Delete
975 Bytes
async function apiFetch(path, { accessToken, idToken }, options = {}) {
const controller = new AbortController();
const timeoutId = window.setTimeout(() => controller.abort(), 60000);
const response = await fetch(path, {
...options,
signal: controller.signal,
headers: {
'X-Google-ID-Token': idToken,
Authorization: `Bearer ${accessToken}`,
...(options.headers || {}),
},
}).finally(() => window.clearTimeout(timeoutId));
if (!response.ok) {
const detail = await response.text();
throw new Error(`Google Drive API error ${response.status}: ${detail}`);
}
return response;
}
export async function listObjFiles(tokens) {
const response = await apiFetch('/api/files', tokens);
const data = await response.json();
return data.files || [];
}
export async function downloadObjText(fileId, tokens) {
const response = await apiFetch(`/api/files/${encodeURIComponent(fileId)}`, tokens);
return response.text();
}