implementing use cases
This commit is contained in:
14
src/app.js
14
src/app.js
@@ -1,10 +1,16 @@
|
||||
const { GetCategoryUseCase } = require('./use-cases/get-category-use-case.js')
|
||||
const categoriesMapping = require('../etc/categories-mapping.json')
|
||||
const categoriesMapping = require('./etc/categories-mapping.json')
|
||||
const { CategoryConverterUseCase } = require('./use-cases/category-converter-use-case.js')
|
||||
|
||||
const getCategoryUseCase = new GetCategoryUseCase();
|
||||
|
||||
(async () => {
|
||||
const categoryId = await getCategoryUseCase.execute()
|
||||
console.log(categoryId)
|
||||
})()
|
||||
|
||||
|
||||
|
||||
|
||||
const getCategoryUseCase = new GetCategoryUseCase({categoriesMapping})
|
||||
// const categoryConverter = new CategoryConverterUseCase({ categoriesMapping })
|
||||
|
||||
|
||||
getCategoryUseCase.execute('utorrent.com')
|
||||
@@ -1,6 +1,6 @@
|
||||
|
||||
class CategoryConverterUseCase {
|
||||
constructor(categoriesMapping) {
|
||||
constructor({categoriesMapping}) {
|
||||
this.categoriesMapping = categoriesMapping
|
||||
}
|
||||
|
||||
@@ -9,4 +9,4 @@ class CategoryConverterUseCase {
|
||||
}
|
||||
}
|
||||
|
||||
module.export = { CategoryConverterUseCase }
|
||||
module.exports = { CategoryConverterUseCase }
|
||||
@@ -1,25 +1,26 @@
|
||||
const { exec } = require("node:child_process")
|
||||
|
||||
class GetCategoryUseCase {
|
||||
constructor({categoriesMapping}) {
|
||||
this.categoriesMapping = categoriesMapping
|
||||
}
|
||||
|
||||
execute(domain) {
|
||||
exec(`echo ${domain} | bin/gcf1check.sh etc check_categorize_hybrid`, { cwd: '/usr/local/gcf1' }, (error, stdout, stderr)=>{
|
||||
return new Promise((resolve, reject) => {
|
||||
exec(`echo ${domain} | bin/gcf1check.sh etc check_categorize_hybrid`, { cwd: '/usr/local/gcf1' }, (error, stdout, stderr) => {
|
||||
if (error) {
|
||||
console.error(error)
|
||||
return
|
||||
console.error(error);
|
||||
reject(error);
|
||||
return;
|
||||
}
|
||||
|
||||
const outputParts = stdout.split(/\s+/); // Split by whitespace
|
||||
const outputParts = stdout.split(/\s+/);
|
||||
if (outputParts[3]) {
|
||||
const categoryId = outputParts[2];
|
||||
console.log({ categoryId });
|
||||
resolve(categoryId);
|
||||
} else {
|
||||
console.log({ error: 'Category ID not found' });
|
||||
reject('Category ID not found');
|
||||
}
|
||||
})
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user