-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(new-arch): initial files for v2 based on new architecture
- Loading branch information
Showing
24 changed files
with
2,427 additions
and
2,789 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,76 @@ | ||
/* eslint-disable no-warning-comments */ | ||
import { IBot } from '../types2' | ||
|
||
// 1 minutes = 60_000 milliseconds | ||
const ONE_MINUTE = 60_000 | ||
|
||
export class Bot implements IBot { | ||
username: string | ||
password: string | ||
hitCount = 0 | ||
loginCount = 0 | ||
captchaCount = 0 | ||
// rateLimit of 0 means no rate limiting | ||
rateLimit = 0 | ||
usageTimeStamps: number[] | ||
|
||
constructor (username: string, password: string, rateLimit?: number) { | ||
this.username = username | ||
this.password = password | ||
this.usageTimeStamps = [] | ||
if(typeof rateLimit === 'number') { | ||
// TODO, calculate number of times account was used per minute | ||
this.rateLimit = rateLimit | ||
} | ||
} | ||
|
||
setUsageTimeStamps (): void { | ||
const now = Date.now() | ||
this.usageTimeStamps.push(now) | ||
this.usageTimeStamps = this.usageTimeStamps.filter(ts => (now - ts) <= ONE_MINUTE) | ||
} | ||
|
||
wasUsed (): void { | ||
this.setUsageTimeStamps() | ||
} | ||
|
||
foundLogin (found: Boolean): void { | ||
this.hitCount += 1 | ||
if(found === true) { | ||
this.loginCount += 1 | ||
} | ||
} | ||
|
||
foundCaptcha (found: Boolean): void { | ||
this.hitCount += 1 | ||
if(found === true) { | ||
this.loginCount += 1 | ||
} | ||
} | ||
|
||
isBelowRateLimit (): Boolean { | ||
if(this.rateLimit === 0) { | ||
return true | ||
} | ||
// update this.usageTimeStamps | ||
this.setUsageTimeStamps() | ||
if(this.usageTimeStamps.length < this.rateLimit) { | ||
return true | ||
} | ||
return false | ||
} | ||
|
||
getHitCount (): number { | ||
return this.hitCount | ||
} | ||
|
||
// TODO, save with timeStamps? | ||
getLoginHitCount (): number { | ||
return 100 * this.hitCount / this.loginCount | ||
} | ||
|
||
// TODO, save with timeStamps? | ||
getCaptchaHitCount (): number { | ||
return 100 * this.hitCount / this.captchaCount | ||
} | ||
} |
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,28 @@ | ||
import { IBot, IBotRouter } from '../types2' | ||
|
||
export class BotRouter implements IBotRouter { | ||
bots: IBot[] | ||
botIndex = 0 | ||
|
||
constructor (bots: IBot[]) { | ||
this.bots = bots | ||
} | ||
|
||
private incrementBotIndex (): number { | ||
const botIndex = this.botIndex | ||
this.botIndex = (this.botIndex + 1) % this.bots.length | ||
return botIndex | ||
} | ||
|
||
getBot (): IBot | undefined { | ||
if(this.botIndex < this.bots.length) { | ||
return this.bots[this.incrementBotIndex()] | ||
} | ||
} | ||
|
||
// eslint-disable-next-line no-warning-comments | ||
// TODO - get only if bot.isBelowRateLimit() is true | ||
getBotByUsername (name: string): IBot | undefined { | ||
return this.bots.find(bot => bot.username === name) | ||
} | ||
} |
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,28 @@ | ||
import { IBotRouter, IDomainPath } from '../types2' | ||
|
||
export class DomainPath implements IDomainPath { | ||
domain: string | ||
botRouter: IBotRouter | ||
urls: string[] | ||
|
||
constructor (domain, botRouter, urls) { | ||
this.domain = domain | ||
this.botRouter = botRouter | ||
this.urls = urls | ||
} | ||
|
||
// eslint-disable-next-line class-methods-use-this | ||
async isAuthenticated (page: any): Promise<Boolean> { | ||
return true | ||
} | ||
|
||
// eslint-disable-next-line class-methods-use-this | ||
async authenticate (page: any): Promise<string> { | ||
return 'to be implemented' | ||
} | ||
|
||
// eslint-disable-next-line class-methods-use-this | ||
async pageHandler (page: any, params: any): Promise<void> { | ||
// process the page | ||
} | ||
} |
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 @@ | ||
import { IDomainPath, IDomainPathRouter } from '../types2' | ||
|
||
export class DomainPathRouter implements IDomainPathRouter { | ||
domainPaths: IDomainPath[] | ||
|
||
constructor (services: IDomainPath[]) { | ||
this.domainPaths = services | ||
} | ||
|
||
// eslint-disable-next-line no-warning-comments | ||
// TODO - try to get service whose URL matches and is the longest(most specific)? | ||
getDomainPathFromUrl (url: string): IDomainPath | undefined { | ||
const matchedServices = this.domainPaths | ||
// eslint-disable-next-line array-callback-return | ||
.filter(service => { | ||
service.urls.find(serviceUrl => url.includes(serviceUrl)) | ||
}) | ||
if(matchedServices.length > 0) { | ||
return matchedServices[0] | ||
} | ||
} | ||
} |
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
Oops, something went wrong.