From 824d575ad57995b71ede5e3f043f3447f71cef8d Mon Sep 17 00:00:00 2001 From: David Duran Date: Sat, 5 Oct 2024 02:43:29 -0500 Subject: [PATCH] fix: update references to the google-drive modules that were not pointing to the right functions --- src/index.ts | 5 ++--- src/services/{local-db.ts => database.ts} | 7 ++++--- src/services/google-drive/client.ts | 7 ------- src/services/google-drive/file-downloader.ts | 8 -------- src/services/google-drive/file-fetcher.ts | 7 ------- src/services/google-drive/folder-validator.ts | 7 ------- src/services/google-drive/index.ts | 8 -------- src/types/index.ts | 5 ----- 8 files changed, 6 insertions(+), 48 deletions(-) rename src/services/{local-db.ts => database.ts} (97%) diff --git a/src/index.ts b/src/index.ts index 02680ed..8008abc 100644 --- a/src/index.ts +++ b/src/index.ts @@ -2,7 +2,7 @@ import path from 'path'; import fs from 'fs/promises'; import {authorize} from '@/services/authorizer'; import {GoogleDriveService} from '@/services/google-drive'; -import {FolderDatabase} from '@/services/local-db'; +import {FolderDatabase} from '@/services/database'; import {logger} from '@/utils/logger'; import {DriveFileManagerConfig, DatabaseFile} from '@/types'; import {defaultConfig, baseDirectories} from '@/config'; @@ -170,8 +170,7 @@ export class DriveFileManager { throw new Error('File not found in the database.'); } - const localPath = - await this.googleDriveService.downloadFileFromGoogleDrive(fileLink); + const localPath = await this.googleDriveService.downloadFile(fileLink); logger.info(`File downloaded successfully to ${localPath}`); await this.folderDatabase.updateLocalFilePath(fileLink, localPath); diff --git a/src/services/local-db.ts b/src/services/database.ts similarity index 97% rename from src/services/local-db.ts rename to src/services/database.ts index 9a2ae8a..c58ebcd 100644 --- a/src/services/local-db.ts +++ b/src/services/database.ts @@ -4,6 +4,7 @@ import {Logger} from '@/utils/logger'; import {GoogleDriveService} from '@/services/google-drive'; import {escapeSingleQuotes} from '@/utils'; import {GoogleFile, RefreshResult, DatabaseFile} from '@/types'; +import {extractFileIdFromLink} from '@/utils'; type SQLiteDB = Database; type SQLiteStmt = Statement; @@ -254,7 +255,7 @@ export class FolderDatabase { * @returns Boolean indicating existence. */ async fileExists(fileLink: string): Promise { - const fileId = this.googleDriveService.extractFileIdFromLink(fileLink); + const fileId = extractFileIdFromLink(fileLink); if (!fileId) return false; try { @@ -273,7 +274,7 @@ export class FolderDatabase { * @returns The local file path if it exists, otherwise null. */ async getLocalFilePath(fileLink: string): Promise { - const fileId = this.googleDriveService.extractFileIdFromLink(fileLink); + const fileId = extractFileIdFromLink(fileLink); if (!fileId) return null; try { @@ -294,7 +295,7 @@ export class FolderDatabase { * @param localPath The local path where the file is stored. */ async updateLocalFilePath(fileLink: string, localPath: string): Promise { - const fileId = this.googleDriveService.extractFileIdFromLink(fileLink); + const fileId = extractFileIdFromLink(fileLink); if (!fileId) { throw new Error('Invalid file link provided.'); } diff --git a/src/services/google-drive/client.ts b/src/services/google-drive/client.ts index 6638d91..69e93a9 100644 --- a/src/services/google-drive/client.ts +++ b/src/services/google-drive/client.ts @@ -2,16 +2,9 @@ import {google, drive_v3} from 'googleapis'; import {OAuth2Client} from 'google-auth-library'; import {logger} from '@/utils/logger'; -/** - * Handles the initialization of the Google Drive client. - */ export class GoogleDriveClient { public drive: drive_v3.Drive; - /** - * Constructs a new GoogleDriveClient. - * @param authClient - An authenticated OAuth2Client instance. - */ constructor(authClient: OAuth2Client) { this.drive = google.drive({version: 'v3', auth: authClient}); logger.info('Initialized Google Drive client.'); diff --git a/src/services/google-drive/file-downloader.ts b/src/services/google-drive/file-downloader.ts index f1afd0f..a273db1 100644 --- a/src/services/google-drive/file-downloader.ts +++ b/src/services/google-drive/file-downloader.ts @@ -4,18 +4,10 @@ import {drive_v3} from 'googleapis'; import {logger} from '@/utils/logger'; import {extractFileIdFromLink} from '@/utils'; -/** - * Manages the downloading of files from Google Drive. - */ export class FileDownloader { private drive: drive_v3.Drive; private downloadsPath: string; - /** - * Constructs a new FileDownloader. - * @param drive - An instance of Google Drive client. - * @param downloadsPath - The local path where files will be downloaded. - */ constructor(drive: drive_v3.Drive, downloadsPath: string) { this.drive = drive; this.downloadsPath = downloadsPath; diff --git a/src/services/google-drive/file-fetcher.ts b/src/services/google-drive/file-fetcher.ts index de9057b..c066b29 100644 --- a/src/services/google-drive/file-fetcher.ts +++ b/src/services/google-drive/file-fetcher.ts @@ -3,16 +3,9 @@ import {GoogleFile} from '@/types'; import {logger} from '@/utils/logger'; import {chunkArray} from '@/utils'; -/** - * Manages file and folder retrieval operations from Google Drive. - */ export class FileFetcher { private drive: drive_v3.Drive; - /** - * Constructs a new FileFetcher. - * @param drive - An instance of Google Drive client. - */ constructor(drive: drive_v3.Drive) { this.drive = drive; } diff --git a/src/services/google-drive/folder-validator.ts b/src/services/google-drive/folder-validator.ts index 5244a21..a850774 100644 --- a/src/services/google-drive/folder-validator.ts +++ b/src/services/google-drive/folder-validator.ts @@ -1,16 +1,9 @@ import {drive_v3} from 'googleapis'; import {logger} from '@/utils/logger'; -/** - * Responsible for validating Google Drive folder IDs. - */ export class FolderValidator { private drive: drive_v3.Drive; - /** - * Constructs a new FolderValidator. - * @param drive - An instance of Google Drive client. - */ constructor(drive: drive_v3.Drive) { this.drive = drive; } diff --git a/src/services/google-drive/index.ts b/src/services/google-drive/index.ts index 656c930..c11e4cb 100644 --- a/src/services/google-drive/index.ts +++ b/src/services/google-drive/index.ts @@ -6,20 +6,12 @@ import {OAuth2Client} from 'google-auth-library'; import {GoogleFile} from '@/types'; import {drive_v3} from 'googleapis'; -/** - * Provides a unified interface for interacting with Google Drive functionalities. - */ export class GoogleDriveService { private client: GoogleDriveClient; private validator: FolderValidator; private fetcher: FileFetcher; private downloader: FileDownloader; - /** - * Constructs a new GoogleDriveService. - * @param authClient - An authenticated OAuth2Client instance. - * @param downloadsPath - The local path where files will be downloaded. - */ constructor(authClient: OAuth2Client, downloadsPath: string) { this.client = new GoogleDriveClient(authClient); this.validator = new FolderValidator(this.client.drive); diff --git a/src/types/index.ts b/src/types/index.ts index bd86faf..54a8694 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -1,8 +1,3 @@ -export interface AuthClientConfig { - tokenPath: string; - credentialsPath: string; -} - export interface DriveFileManagerConfig { folderId: string; tokenPath?: string;