-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
107 additions
and
43 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
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,13 @@ | ||
import { Logger } from "../../logger"; | ||
import { ProxyStorage } from "../../proxy/proxy.storage"; | ||
|
||
export class DisableUserOpt { | ||
private readonly logger = new Logger("DisableUserOpt"); | ||
|
||
public constructor(private readonly proxyStorage: ProxyStorage) {} | ||
|
||
public async execute(userKey: string) { | ||
await this.proxyStorage.delete(userKey); | ||
this.logger.info(`Disabled user ${userKey}`); | ||
} | ||
} |
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,14 @@ | ||
import { Logger } from "../../logger"; | ||
import { IUserConfig } from "../../config/config.dto"; | ||
import { ProxyStorage } from "../../proxy/proxy.storage"; | ||
|
||
export class EnableUserOpt { | ||
private readonly logger = new Logger("EnableUserOpt"); | ||
|
||
public constructor(private readonly proxyStorage: ProxyStorage) {} | ||
|
||
public async execute(userConfig: IUserConfig) { | ||
await this.proxyStorage.add(userConfig.key, userConfig.proxy); | ||
this.logger.info(`Enabled user ${userConfig.key}`); | ||
} | ||
} |
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,23 @@ | ||
import { GetUserOpt } from "./get.user.opt"; | ||
import { ProxyStorage } from "../../proxy/proxy.storage"; | ||
import { EnableUserOpt } from "./enable.user.opt"; | ||
import { DisableUserOpt } from "./disable.user.opt"; | ||
|
||
export class RecheckUserOpt { | ||
public constructor( | ||
private readonly getUserOpt: GetUserOpt, | ||
private readonly proxyStorage: ProxyStorage, | ||
private readonly disableUserOpt: DisableUserOpt, | ||
private readonly enableUserOpt: EnableUserOpt | ||
) {} | ||
|
||
public async execute(userKey: string) { | ||
const user = await this.getUserOpt.execute(userKey); | ||
const proxyExists = this.proxyStorage.exists(userKey); | ||
|
||
if (proxyExists && !user.isEnabled()) | ||
await this.disableUserOpt.execute(userKey); | ||
else if (!proxyExists && user.isEnabled()) | ||
await this.enableUserOpt.execute(user.config); | ||
} | ||
} |
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