CrazySquirrel/UniqueTransport

View on GitHub
lib/ts/server.ts

Summary

Maintainability
F
1 wk
Test Coverage

File server.ts has 1109 lines of code (exceeds 250 allowed). Consider refactoring.
Open

"use strict";
/**
 * Import interfaces
 */
import IWindow from "../../interfaces/IWindow";
Severity: Major
Found in lib/ts/server.ts - About 2 days to fix

Function Proxy has 261 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  public Proxy(result, headers, request, response, depth = 5) {
    try {
      if (
          this.Settings.XAccelRedirect &&
          result.Data.link.indexOf(".css") === -1
Severity: Major
Found in lib/ts/server.ts - About 1 day to fix

Function Proxy has a Cognitive Complexity of 42 (exceeds 5 allowed). Consider refactoring.
Open

  public Proxy(result, headers, request, response, depth = 5) {
    try {
      if (
          this.Settings.XAccelRedirect &&
          result.Data.link.indexOf(".css") === -1
Severity: Minor
Found in lib/ts/server.ts - About 6 hrs to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Function doProxy has 148 lines of code (exceeds 25 allowed). Consider refactoring.
Open

          const doProxy = () => {
            if (this.proxyShit[result.Data.link]) {
              redirectProxy();
            } else {
              const url = URL.parse(result.Data.link);
Severity: Major
Found in lib/ts/server.ts - About 5 hrs to fix

Function Respond has 137 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  public Respond(result, headers, request, response) {
    try {
      headers["Cache-Control"] = "no-cache";
      let resp = "";
      switch (result.Params.Transport) {
Severity: Major
Found in lib/ts/server.ts - About 5 hrs to fix

Function processor has 126 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  public processor(data, params, request, headers) {
    return new Promise((resolve, reject) => {
      this.decode(data, this.Settings.Password).then(
          (_data: any) => {
            if (
Severity: Major
Found in lib/ts/server.ts - About 5 hrs to fix

Function listenr has 115 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  public listenr(request, response) {
    this.AcceptEncoding = request.headers["accept-encoding"] || "";

    const headers = Object.assign({}, baseHeaders);

Severity: Major
Found in lib/ts/server.ts - About 4 hrs to fix

Function req has 95 lines of code (exceeds 25 allowed). Consider refactoring.
Open

                      const req = (options.port === 443 ? HTTPS : HTTP).request(options, (res) => {
                        clearTimeout(proxyConnectionTimeout);

                        res.on("error", (_err) => {
                          redirectProxy();
Severity: Major
Found in lib/ts/server.ts - About 3 hrs to fix

Function Respond has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
Open

  public Respond(result, headers, request, response) {
    try {
      headers["Cache-Control"] = "no-cache";
      let resp = "";
      switch (result.Params.Transport) {
Severity: Minor
Found in lib/ts/server.ts - About 3 hrs to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Server has 23 functions (exceeds 20 allowed). Consider refactoring.
Open

export default class Server extends Transport {

  /**
   * Get choice ID
   * @param choiceType
Severity: Minor
Found in lib/ts/server.ts - About 2 hrs to fix

Function download has 56 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  public download(data, headers, request, depth = 3) {
    return new Promise((resolve, reject) => {
      const url = URL.parse(data.link);

      url.port = url.port || url.protocol === "https:" ? 443 : 80;
Severity: Major
Found in lib/ts/server.ts - About 2 hrs to fix

Function encodeSync has 50 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  public encodeSync(data: any, password: string) {
    if (
        this.cryptoModule === "" ||
        this.cryptoModule === "base64salt"
    ) {
Severity: Minor
Found in lib/ts/server.ts - About 2 hrs to fix

Function preprocessor has 49 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  public preprocessor(request) {
    return new Promise((resolve, reject) => {
      const data = [];
      /**
       * Get data from url
Severity: Minor
Found in lib/ts/server.ts - About 1 hr to fix

Function encodeSync has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
Open

  public encodeSync(data: any, password: string) {
    if (
        this.cryptoModule === "" ||
        this.cryptoModule === "base64salt"
    ) {
Severity: Minor
Found in lib/ts/server.ts - About 1 hr to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Function redirectProxy has 43 lines of code (exceeds 25 allowed). Consider refactoring.
Open

        const redirectProxy = () => {
          if (
              result.Data.link.indexOf(".css") === -1 &&
              result.Data.link.indexOf("yandex") === -1
          ) {
Severity: Minor
Found in lib/ts/server.ts - About 1 hr to fix

Function decodeSync has 36 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  public decodeSync(data: any, password: string) {
    try {
      let dec = decodeURIComponent(global.escape(Buffer.from(data, "base64").toString("utf8"))).split("@");
      dec.shift();
      dec = JSON.parse(dec.join("@"));
Severity: Minor
Found in lib/ts/server.ts - About 1 hr to fix

Function listenr has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
Open

  public listenr(request, response) {
    this.AcceptEncoding = request.headers["accept-encoding"] || "";

    const headers = Object.assign({}, baseHeaders);

Severity: Minor
Found in lib/ts/server.ts - About 1 hr to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Function responceError has 30 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  public responceError(id, request, response, headers, e?, ...data) {
    this.ErrorHandler(e, id, data);

    if (request.headers["x-real-404"]) {
      const url = URL.parse(request.headers["x-real-404"]);
Severity: Minor
Found in lib/ts/server.ts - About 1 hr to fix

Avoid deeply nested control flow statements.
Open

                        } else if (
                            (
                                res.statusCode === 301 ||
                                res.statusCode === 302
                            ) &&
Severity: Major
Found in lib/ts/server.ts - About 45 mins to fix

Avoid deeply nested control flow statements.
Open

                          if (e) {
                            doRedirect();
                          } else {
                            response.writeHead(this.Settings.SuccessResponseCode, JSON.parse(_headers));
                            FS.createReadStream(CachePathBody).pipe(response);
Severity: Major
Found in lib/ts/server.ts - About 45 mins to fix

Avoid deeply nested control flow statements.
Open

                      if (!response.answered) {
                        response.answered = true;
                        FS.readFile(CachePathHeaders, "utf-8", (e, _headers) => {
                          try {
                            if (e) {
Severity: Major
Found in lib/ts/server.ts - About 45 mins to fix

Avoid deeply nested control flow statements.
Open

                          if (
                              this.Settings.MaxProxySize &&
                              res.headers["content-length"] &&
                              parseInt(res.headers["content-length"], 10) > this.Settings.MaxProxySize &&
                              result.Data.link.indexOf(".css") === -1 &&
Severity: Major
Found in lib/ts/server.ts - About 45 mins to fix

Avoid deeply nested control flow statements.
Open

                if (
                    this.listners["proxy"]
                ) {
                  new Promise(
                      (_resolve) => {
Severity: Major
Found in lib/ts/server.ts - About 45 mins to fix

Function getHostFromHeaderXRealHost has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

  public getHostFromHeaderXRealHost(request, params) {
    if (request.headers["x-real-host"]) {
      let origin;

      if (request.headers["x-real-host"].indexOf("http") === -1) {
Severity: Minor
Found in lib/ts/server.ts - About 35 mins to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Avoid too many return statements within this function.
Open

        return data;
Severity: Major
Found in lib/ts/server.ts - About 30 mins to fix

Avoid too many return statements within this function.
Open

    return null;
Severity: Major
Found in lib/ts/server.ts - About 30 mins to fix

Avoid too many return statements within this function.
Open

      return dec;
Severity: Major
Found in lib/ts/server.ts - About 30 mins to fix

Avoid too many return statements within this function.
Open

    return false;
Severity: Major
Found in lib/ts/server.ts - About 30 mins to fix

Function getHostFromHeaderOrigin has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

  public getHostFromHeaderOrigin(request, params) {
    if (request.headers.origin) {
      let origin;

      if (request.headers.origin.indexOf("http") === -1) {
Severity: Minor
Found in lib/ts/server.ts - About 25 mins to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Function responceError has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

  public responceError(id, request, response, headers, e?, ...data) {
    this.ErrorHandler(e, id, data);

    if (request.headers["x-real-404"]) {
      const url = URL.parse(request.headers["x-real-404"]);
Severity: Minor
Found in lib/ts/server.ts - About 25 mins to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Function decodeSync has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

  public decodeSync(data: any, password: string) {
    try {
      let dec = decodeURIComponent(global.escape(Buffer.from(data, "base64").toString("utf8"))).split("@");
      dec.shift();
      dec = JSON.parse(dec.join("@"));
Severity: Minor
Found in lib/ts/server.ts - About 25 mins to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Function getHostFromHeaderHost has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

  public getHostFromHeaderHost(request, params) {
    if (request.headers.host) {
      let origin;

      if (request.headers.host.indexOf("http") === -1) {
Severity: Minor
Found in lib/ts/server.ts - About 25 mins to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Function getHostFromParamsReferer has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

  public getHostFromParamsReferer(request, params) {
    if (params.Refferer) {
      let origin;

      if (params.Refferer.indexOf("http") === -1) {
Severity: Minor
Found in lib/ts/server.ts - About 25 mins to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Function getHostFromHeaderReferer has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

  public getHostFromHeaderReferer(request, params) {
    if (request.headers.referer) {
      let origin;

      if (request.headers.referer.indexOf("http") === -1) {
Severity: Minor
Found in lib/ts/server.ts - About 25 mins to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

TODO found
Open

      // TODO: add logger
Severity: Minor
Found in lib/ts/server.ts by fixme

TODO found
Open

        // TODO: add logger
Severity: Minor
Found in lib/ts/server.ts by fixme

TODO found
Open

      // TODO: add logger
Severity: Minor
Found in lib/ts/server.ts by fixme

TODO found
Open

        // TODO: add logger
Severity: Minor
Found in lib/ts/server.ts by fixme

TODO found
Open

        // TODO: add logger
Severity: Minor
Found in lib/ts/server.ts by fixme

TODO found
Open

        // TODO: add logger
Severity: Minor
Found in lib/ts/server.ts by fixme

TODO found
Open

        // TODO: add logger
Severity: Minor
Found in lib/ts/server.ts by fixme

TODO found
Open

       * TODO: add logger
Severity: Minor
Found in lib/ts/server.ts by fixme

TODO found
Open

      // TODO: add logger
Severity: Minor
Found in lib/ts/server.ts by fixme

TODO found
Open

      // TODO: add logger
Severity: Minor
Found in lib/ts/server.ts by fixme

There are no issues that match your filters.

Category
Status