-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from hunters-org/results
Results
- Loading branch information
Showing
13 changed files
with
195 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* eslint-disable import/prefer-default-export */ | ||
import { PathLike } from 'fs'; | ||
import { JSONDB } from './core/node'; | ||
import { JobDetails } from '../types'; | ||
|
||
export interface ProjectDetails { | ||
name: string; | ||
domain: string; | ||
recon?: { | ||
subfinder?: JobDetails; | ||
screens?: JobDetails; | ||
params?: JobDetails; | ||
liveDomains?: JobDetails; | ||
}; | ||
} | ||
|
||
export function connectJson<_T = ProjectDetails>(path: PathLike) { | ||
const db = new JSONDB<_T>(path); | ||
return db; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* eslint-disable import/prefer-default-export */ | ||
export class BrowserDB { | ||
private filePath: string; | ||
|
||
constructor(filePath: string) { | ||
this.filePath = filePath; | ||
} | ||
|
||
async read(): Promise<any | null> { | ||
try { | ||
const response = await fetch(this.filePath); | ||
if (!response.ok) { | ||
throw new Error('Failed to fetch data'); | ||
} | ||
return await response.json(); | ||
} catch (error) { | ||
// eslint-disable-next-line no-console | ||
console.error('Error reading data:', error); | ||
return null; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* eslint-disable no-console */ | ||
/* eslint-disable import/prefer-default-export */ | ||
import { PathLike } from 'fs'; | ||
import fs from 'fs/promises'; | ||
|
||
export class JSONDB<T> { | ||
private filePath: PathLike; | ||
|
||
constructor(file: PathLike) { | ||
this.filePath = file; | ||
} | ||
|
||
async read(): Promise<T | null> { | ||
try { | ||
const data = await fs.readFile(this.filePath, 'utf-8'); | ||
return JSON.parse(data) as T; | ||
} catch (error) { | ||
console.error('Error reading file:', error); | ||
return null; | ||
} | ||
} | ||
|
||
async update(updates: Partial<T>): Promise<void> { | ||
try { | ||
const existingData = await this.read(); | ||
if (existingData === null) { | ||
console.error('No data found to update'); | ||
return; | ||
} | ||
const updatedData = { ...existingData, ...updates }; | ||
await fs.writeFile(this.filePath, JSON.stringify(updatedData, null, 2)); | ||
} catch (error) { | ||
console.error('Error updating file:', error); | ||
} | ||
} | ||
|
||
async delete(): Promise<void> { | ||
try { | ||
await fs.unlink(this.filePath); | ||
} catch (error) { | ||
console.error('Error deleting file:', error); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { PathLike } from 'fs'; | ||
|
||
export type JobDetails = { | ||
run: boolean; | ||
filePath: PathLike; | ||
result?: number | string; | ||
date: string; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters