mirror of
https://github.com/Nezumi-2711/next-gdrive-index.git
synced 2026-09-22 20:01:36 +00:00
31 lines
757 B
TypeScript
31 lines
757 B
TypeScript
import apiConfig from "config/api.config";
|
|
import { drive_v3, google } from "googleapis";
|
|
import { decrypt } from "utils/encryptionHelper";
|
|
|
|
const decryptedSecret: string = decrypt(
|
|
apiConfig.client_secret,
|
|
process.env.NEXT_PUBLIC_ENCRYPTION_KEY as string,
|
|
);
|
|
const decryptedRefreshToken: string = decrypt(
|
|
apiConfig.refresh_token,
|
|
process.env.NEXT_PUBLIC_ENCRYPTION_KEY as string,
|
|
);
|
|
|
|
const oauth2Client = new google.auth.OAuth2(
|
|
apiConfig.client_id,
|
|
decryptedSecret,
|
|
);
|
|
oauth2Client.setCredentials({
|
|
refresh_token: decodeURIComponent(decryptedRefreshToken),
|
|
});
|
|
|
|
let gdriveInstance;
|
|
if (!gdriveInstance) {
|
|
gdriveInstance = google.drive({
|
|
version: "v3",
|
|
auth: oauth2Client,
|
|
});
|
|
}
|
|
|
|
export default gdriveInstance as drive_v3.Drive;
|