Skip to content

Commit

Permalink
fix: update references to the google-drive modules that were not poin…
Browse files Browse the repository at this point in the history
…ting to the right functions
  • Loading branch information
totallynotdavid committed Oct 5, 2024
1 parent dca1242 commit 824d575
Show file tree
Hide file tree
Showing 8 changed files with 6 additions and 48 deletions.
5 changes: 2 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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);
Expand Down
7 changes: 4 additions & 3 deletions src/services/local-db.ts → src/services/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<sqlite3.Database, sqlite3.Statement>;
type SQLiteStmt = Statement;
Expand Down Expand Up @@ -254,7 +255,7 @@ export class FolderDatabase {
* @returns Boolean indicating existence.
*/
async fileExists(fileLink: string): Promise<boolean> {
const fileId = this.googleDriveService.extractFileIdFromLink(fileLink);
const fileId = extractFileIdFromLink(fileLink);
if (!fileId) return false;

try {
Expand All @@ -273,7 +274,7 @@ export class FolderDatabase {
* @returns The local file path if it exists, otherwise null.
*/
async getLocalFilePath(fileLink: string): Promise<string | null> {
const fileId = this.googleDriveService.extractFileIdFromLink(fileLink);
const fileId = extractFileIdFromLink(fileLink);
if (!fileId) return null;

try {
Expand All @@ -294,7 +295,7 @@ export class FolderDatabase {
* @param localPath The local path where the file is stored.
*/
async updateLocalFilePath(fileLink: string, localPath: string): Promise<void> {
const fileId = this.googleDriveService.extractFileIdFromLink(fileLink);
const fileId = extractFileIdFromLink(fileLink);
if (!fileId) {
throw new Error('Invalid file link provided.');
}
Expand Down
7 changes: 0 additions & 7 deletions src/services/google-drive/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.');
Expand Down
8 changes: 0 additions & 8 deletions src/services/google-drive/file-downloader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 0 additions & 7 deletions src/services/google-drive/file-fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
7 changes: 0 additions & 7 deletions src/services/google-drive/folder-validator.ts
Original file line number Diff line number Diff line change
@@ -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;
}
Expand Down
8 changes: 0 additions & 8 deletions src/services/google-drive/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 0 additions & 5 deletions src/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
export interface AuthClientConfig {
tokenPath: string;
credentialsPath: string;
}

export interface DriveFileManagerConfig {
folderId: string;
tokenPath?: string;
Expand Down

0 comments on commit 824d575

Please sign in to comment.