Skip to content

Commit

Permalink
rendersIgnoreProxy option
Browse files Browse the repository at this point in the history
  • Loading branch information
egorprnn committed Mar 29, 2021
1 parent 71bada2 commit 786f106
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 20 deletions.
13 changes: 7 additions & 6 deletions docs/EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,13 @@ Main class

**Kind**: class

| Param | Type | Default | Description |
| --------------------------- | -------- | -------------- | -------------------------------------------------------------------------- |
| options | `Object` | | Object with parameters for the class |
| options.proxy | `string` | | Proxy for requests |
| options.endpoint | `string` | `"namemc.com"` | NameMC Endpoint |
| options.defaultSkinsModel | `string` | `"unknown"` | Model for skins by default, if an error occurred while trying to parse it. |
| Param | Type | Default | Description |
| -------------------------- | --------- | -------------- | ------------------------------------------------------------------------- |
| options | `Object` | | Object with parameters for the class |
| options.proxy | `string` | | Proxy for requests |
| options.endpoint | `string` | `"namemc.com"` | NameMC Endpoint |
| options.defaultSkinsModel | `string` | `"unknown"` | Model for skins by default, if an error occurred while trying to parse it |
| options.rendersIgnoreProxy | `boolean` | `false` | Ignore proxy field for image renders |

**Example**:

Expand Down
13 changes: 7 additions & 6 deletions docs/RU.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,13 @@

**Вид**: класс

| Параметры | Тип | По умолчанию | Описание |
| --------------------------- | -------- | -------------- | -------------------------------------------------------------------------- |
| options | `Object` | | Объект с параметрами для класса |
| options.proxy | `string` | | Прокси для запросов |
| options.endpoint | `string` | `"namemc.com"` | Конечная точка NameMC для запросов |
| options.defaultSkinsModel | `string` | `"unknown"` | Модель для скинов по умолчанию, если при ее парсе произошла ошибка |
| Параметры | Тип | По умолчанию | Описание |
| -------------------------- | --------- | -------------- | ------------------------------------------------------------------ |
| options | `Object` | | Объект с параметрами для класса |
| options.proxy | `string` | | Прокси для запросов |
| options.endpoint | `string` | `"namemc.com"` | Конечная точка NameMC для запросов |
| options.defaultSkinsModel | `string` | `"unknown"` | Модель для скинов по умолчанию, если при ее парсе произошла ошибка |
| options.rendersIgnoreProxy | `boolean` | `false` | Игнорировать прокси для рендера изображений |

**Пример**:

Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "namemcwrapper",
"version": "1.8.4",
"version": "1.8.5",
"description": "ES6 Promise based wrapper for NameMC.com",
"main": "./dist/NameMC.js",
"exports": {
Expand All @@ -17,7 +17,8 @@
"scripts": {
"tsc": "tsc && node --experimental-modules --es-module-specifier-resolution=node ./scripts/removeEmptyFiles.mjs",
"build": "npm run-script tsc && babel build --out-dir dist --copy-files && node --experimental-modules --es-module-specifier-resolution=node ./scripts/fixImports.mjs",
"test": "npm run-script build && node --experimental-modules --experimental-json-modules node_modules/mocha/bin/_mocha --reporter spec --timeout 180000",
"pretest": "npm run-script build",
"test": "mocha --reporter spec --timeout 180000",
"eslint:check": "eslint ./src/**/*",
"eslint:fix": "eslint ./src/**/* --fix"
},
Expand Down
2 changes: 1 addition & 1 deletion src/DataParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export abstract class DataParser {
this.options = options;
}

abstract getEndpoint(options: IGetEndpointOptions): string;
protected abstract getEndpoint(options: IGetEndpointOptions): string;
abstract getRenders(options: IGetRendersOptions): IRender;
abstract getCapeInfo(hash: Hash): ICapeInfo;

Expand Down
20 changes: 17 additions & 3 deletions src/NameMC.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,22 @@ export class NameMC extends DataParser {
constructor(options: IOptions = {}) {
super(options);

const urlOptions: ("proxy" | "endpoint")[] = [
"proxy",
"endpoint"
];

urlOptions.forEach((option) => {
const optionValue = options[option];

if (optionValue?.endsWith("/")) {
options[option] = optionValue.slice(0, optionValue.length - 1);
}
});

this.options = {
endpoint: "namemc.com",
proxy: "",
...options
};

Expand Down Expand Up @@ -367,10 +381,10 @@ export class NameMC extends DataParser {
});
}

getEndpoint({ subdomain = "", domain = "" }: IGetEndpointOptions = {}): string {
const { proxy, endpoint }: IOptions = this.options;
protected getEndpoint({ subdomain = "", domain = "" }: IGetEndpointOptions = {}): string {
const { proxy, endpoint, rendersIgnoreProxy }: IOptions = this.options;

return `${proxy ? `${proxy}/` : ""}https://${subdomain ? `${subdomain}.` : ""}${domain || endpoint}`;
return `${rendersIgnoreProxy && subdomain === "renders" ? "" : proxy}https://${subdomain ? `${subdomain}.` : ""}${domain || endpoint}`;
}
}

Expand Down
1 change: 1 addition & 0 deletions src/interfaces/NameMC/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Model } from "./skin";

export interface IOptions {
proxy?: string;
rendersIgnoreProxy?: boolean;
endpoint?: string;
defaultSkinsModel?: Exclude<Model, "unknown">;
}

0 comments on commit 786f106

Please sign in to comment.