Files
mpcfill-pdf/drive.js
orion kindel ae5193700a init
2025-11-06 15:16:08 -06:00

27 lines
883 B
JavaScript

import {google as Google} from 'googleapis'
import Bun from 'bun'
const init = async () => {
const auth = await new Google.auth.GoogleAuth({ keyFile: '.client-secrets.json', scopes: ['https://www.googleapis.com/auth/drive'] }).getClient()
await auth.authorize()
return auth
}
/** @type {(auth: import('googleapis').Auth.AnyAuthClient, fileId: string) => Promise<import('googleapis').drive_v3.Schema$File>} */
const info = async (auth, fileId) =>
Google
.drive({ version: 'v3', auth })
.files
.get({ fileId })
.then(a => a.data)
/** @type {(auth: import('googleapis').Auth.AnyAuthClient, fileId: string) => Promise<ArrayBuffer>} */
const download = async (auth, fileId) =>
Google
.drive({ version: 'v3', auth })
.files
.get({ fileId, alt: 'media' }, { responseType: 'stream' })
.then(a => a.arrayBuffer())
export { init, download, info }