| 1 | import { eq } from "drizzle-orm"; |
| 2 | import { db } |
| 3 | import { userGoogleDrives } |
| 4 | import { safeDecrypt } |
| 5 | import { |
| 6 | getGDriveConnection, |
| 7 | getOperatorGDriveConfig, |
| 8 | revokeGoogleToken, |
| 9 | } from "../services/google-drive"; |
| 10 | import { recordActivity } |
| 11 | import { protectedProcedure } |
| 12 | |
| 13 | export const googleDriveRouter = |
| 14 | get: protectedProcedure.handler |
| 15 | const [config, |
| 16 | getOperatorGDriveConfig(), |
| 17 | getGDriveConnection(context.session |
| 18 | ]); |
| 19 | return { |
| 20 | operatorConfigured: !!config, |
| 21 | connected: !!connection, |
| 22 | email: connection?.email |
| 23 | }; |
| 24 | }), |
| 25 | |
| 26 | disconnect: protectedProcedure.handler |
| 27 | const row = |
| 28 | where: eq(userGoogleDrives |
| 29 | }); |
| 30 | if (row) { |
| 31 | await revokeGoogleToken(safeDecrypt |
| 32 | } |
| 33 | await db |
| 34 | .delete(userGoogleDrives) |
| 35 | .where(eq(userGoogleDrives |
| 36 | recordActivity({ |
| 37 | eventType: "account:google-drive.disconnect", |
| 38 | userId: context.session |
| 39 | ip: context.ip |
| 40 | }); |
| 41 | return { ok: |
| 42 | }), |
| 43 | }; |