Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop #5

Merged
merged 2 commits into from
Jul 19, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 36 additions & 29 deletions src/whatsapp/repository/repository.manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ import { MessageUpRepository } from './messageUp.repository';
import { MongoClient } from 'mongodb';
import { WebhookRepository } from './webhook.repository';
import { ChatwootRepository } from './chatwoot.repository';

import { AuthRepository } from './auth.repository';
import { Auth, ConfigService, Database } from '../../config/env.config';
import { execSync } from 'child_process';
import { join } from 'path';
import fs from 'fs';
import { Logger } from '../../config/logger.config';

export class RepositoryBroker {
constructor(
public readonly message: MessageRepository,
Expand All @@ -23,7 +24,6 @@ export class RepositoryBroker {
private configService: ConfigService,
dbServer?: MongoClient,
) {
this.logger.verbose('initializing repository broker');
this.dbClient = dbServer;
this.__init_repo_without_db__();
}
Expand All @@ -38,39 +38,46 @@ export class RepositoryBroker {
private __init_repo_without_db__() {
this.logger.verbose('initializing repository without db');
if (!this.configService.get<Database>('DATABASE').ENABLED) {
this.logger.verbose('database is disabled');

const storePath = join(process.cwd(), 'store');

this.logger.verbose('creating store path: ' + storePath);
execSync(
`mkdir -p ${join(
try {
const authDir = join(
storePath,
'auth',
this.configService.get<Auth>('AUTHENTICATION').TYPE,
)}`,
);

this.logger.verbose('creating chats path: ' + join(storePath, 'chats'));
execSync(`mkdir -p ${join(storePath, 'chats')}`);

this.logger.verbose('creating contacts path: ' + join(storePath, 'contacts'));
execSync(`mkdir -p ${join(storePath, 'contacts')}`);

this.logger.verbose('creating messages path: ' + join(storePath, 'messages'));
execSync(`mkdir -p ${join(storePath, 'messages')}`);

this.logger.verbose('creating message-up path: ' + join(storePath, 'message-up'));
execSync(`mkdir -p ${join(storePath, 'message-up')}`);

this.logger.verbose('creating webhook path: ' + join(storePath, 'webhook'));
execSync(`mkdir -p ${join(storePath, 'webhook')}`);

this.logger.verbose('creating chatwoot path: ' + join(storePath, 'chatwoot'));
execSync(`mkdir -p ${join(storePath, 'chatwoot')}`);
);
const chatsDir = join(storePath, 'chats');
const contactsDir = join(storePath, 'contacts');
const messagesDir = join(storePath, 'messages');
const messageUpDir = join(storePath, 'message-up');
const webhookDir = join(storePath, 'webhook');
const chatwootDir = join(storePath, 'chatwoot');

this.logger.verbose('creating temp path: ' + join(storePath, 'temp'));
execSync(`mkdir -p ${join(storePath, 'temp')}`);
// Check if directories exist, create them if not
if (!fs.existsSync(authDir)) {
fs.mkdirSync(authDir, { recursive: true });
}
if (!fs.existsSync(chatsDir)) {
fs.mkdirSync(chatsDir, { recursive: true });
}
if (!fs.existsSync(contactsDir)) {
fs.mkdirSync(contactsDir, { recursive: true });
}
if (!fs.existsSync(messagesDir)) {
fs.mkdirSync(messagesDir, { recursive: true });
}
if (!fs.existsSync(messageUpDir)) {
fs.mkdirSync(messageUpDir, { recursive: true });
}
if (!fs.existsSync(webhookDir)) {
fs.mkdirSync(webhookDir, { recursive: true });
}
if (!fs.existsSync(chatwootDir)) {
fs.mkdirSync(chatwootDir, { recursive: true });
}
} catch (error) {
console.error(error);
}
}
}
}