Vana SDK - v0.1.0
    Preparing search index...

    Google Drive Storage Provider with folder management capabilities

    Implements storage interface for Google Drive using OAuth2 authentication. Provides file upload/download operations and advanced folder management including search, creation, and nested folder structures. Requires the https://www.googleapis.com/auth/drive.file OAuth scope for full functionality.

    const googleDriveStorage = new GoogleDriveStorage({
    accessToken: "your-oauth-access-token",
    refreshToken: "your-oauth-refresh-token",
    clientId: "your-oauth-client-id",
    clientSecret: "your-oauth-client-secret",
    });

    // Create folder structure and upload file
    const folderId = await googleDriveStorage.findOrCreateFolder("screenshots");
    const result = await googleDriveStorage.upload(fileBlob, "image.png");

    Implements

    Index

    Methods

    • Searches for an existing folder by name within a specified parent folder

      Parameters

      • name: string

        The exact name of the folder to search for

      • parentId: string = "root"

        The ID of the parent folder to search within (defaults to 'root')

      Returns Promise<null | string>

      Promise that resolves to the folder ID if found, or null if not found

      This method queries the Google Drive API to find a folder with the exact name within the specified parent directory. Only searches for folders (not files) and excludes trashed items.

      When the Google Drive API request fails

      // Search for a folder in the root directory
      const folderId = await googleDriveStorage.findFolder("screenshots");
      if (folderId) {
      console.log("Found folder:", folderId);
      } else {
      console.log("Folder not found");
      }

      // Search for a subfolder within another folder
      const subFolderId = await googleDriveStorage.findFolder("roasts", parentFolderId);
    • Creates a new folder within a specified parent folder

      Parameters

      • name: string

        The name for the new folder

      • parentId: string = "root"

        The ID of the parent folder where the new folder will be created (defaults to 'root')

      Returns Promise<string>

      Promise that resolves to the ID of the newly created folder

      This method creates a new folder using the Google Drive API. The folder will be created with the specified name as a child of the parent folder. Requires the https://www.googleapis.com/auth/drive.file OAuth scope.

      When the Google Drive API request fails or folder creation is denied

      // Create a folder in the root directory
      const folderId = await googleDriveStorage.createFolder("my-documents");
      console.log("Created folder:", folderId);

      // Create a subfolder within another folder
      const subFolderId = await googleDriveStorage.createFolder("reports", parentFolderId);
    • Finds an existing folder by name, or creates it if it doesn't exist

      Parameters

      • name: string

        The name of the folder to find or create

      • parentId: string = "root"

        The ID of the parent folder to search within or create the folder in (defaults to 'root')

      Returns Promise<string>

      Promise that resolves to the folder ID (either existing or newly created)

      This is a convenience method that combines findFolder and createFolder. It first searches for an existing folder with the specified name. If found, it returns the existing folder's ID. If not found, it creates a new folder and returns the new folder's ID.

      When the Google Drive API request fails

      // Ensure a folder exists, creating it if necessary
      const folderId = await googleDriveStorage.findOrCreateFolder("screenshots");
      console.log("Folder ID:", folderId); // Will be same ID if folder already existed

      // Create nested folder structure
      const parentId = await googleDriveStorage.findOrCreateFolder("projects");
      const childId = await googleDriveStorage.findOrCreateFolder("vana-app", parentId);