20251125 save

This commit is contained in:
kosukesuenaga 2025-11-25 14:54:01 +09:00
parent 922fa0e77a
commit 092f2ec0f3
11 changed files with 299 additions and 1 deletions

View file

@ -0,0 +1,36 @@
import { authenticate } from "@google-cloud/local-auth";
import { JSONClient } from "google-auth-library/build/src/auth/googleauth";
import { google } from "googleapis";
import path from "path";
const SCOPES = ["https://www.googleapis.com/auth/drive", "https://www.googleapis.com/auth/drive.file"]
const CREDENTIALS_PATH = path.join(process.cwd(), 'credentials.json');
export const googleDriveController = {
getAuth: async():Promise<any> => {
const auth = await new google.auth.GoogleAuth({
keyFile: CREDENTIALS_PATH,
scopes: SCOPES,
});
return auth;
},
checkConnection: async() => {
const auth = await googleDriveController.getAuth();
// console.log("Google Drive client authenticated.");
const drive = google.drive({ version: "v3", auth: auth});
const folder = '1cCDJKusfrlDrJe2yHCR8pCHJXRqX-4Hw';
const res = await drive.files.list({
q: `'${folder}' in parents`,
pageSize: 10,
fields: "files(id, name)",
});
console.log("Files:");
console.log(res.data.files);
},
uploadFile: async() => {
},
createNewFile: async() => {
},
};