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 { 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 categoryConverter = new CategoryConverterUseCase({ categoriesMapping })
|
||||||
|
|
||||||
const getCategoryUseCase = new GetCategoryUseCase({categoriesMapping})
|
|
||||||
|
|
||||||
|
|
||||||
getCategoryUseCase.execute('utorrent.com')
|
getCategoryUseCase.execute('utorrent.com')
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
|
|
||||||
class CategoryConverterUseCase {
|
class CategoryConverterUseCase {
|
||||||
constructor(categoriesMapping) {
|
constructor({categoriesMapping}) {
|
||||||
this.categoriesMapping = 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")
|
const { exec } = require("node:child_process")
|
||||||
|
|
||||||
class GetCategoryUseCase {
|
class GetCategoryUseCase {
|
||||||
constructor({categoriesMapping}) {
|
|
||||||
this.categoriesMapping = categoriesMapping
|
|
||||||
}
|
|
||||||
|
|
||||||
execute(domain) {
|
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) {
|
if (error) {
|
||||||
console.error(error)
|
console.error(error);
|
||||||
return
|
reject(error);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const outputParts = stdout.split(/\s+/); // Split by whitespace
|
const outputParts = stdout.split(/\s+/);
|
||||||
if (outputParts[3]) {
|
if (outputParts[3]) {
|
||||||
const categoryId = outputParts[2];
|
const categoryId = outputParts[2];
|
||||||
console.log({ categoryId });
|
console.log({ categoryId });
|
||||||
|
resolve(categoryId);
|
||||||
} else {
|
} else {
|
||||||
console.log({ error: 'Category ID not found' });
|
console.log({ error: 'Category ID not found' });
|
||||||
|
reject('Category ID not found');
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user