Skip to content

Commit

Permalink
defaultSkinsModel options for NameMC class
Browse files Browse the repository at this point in the history
  • Loading branch information
egorprnn committed Mar 28, 2021
1 parent af09deb commit 34cf26d
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 16 deletions.
11 changes: 6 additions & 5 deletions docs/EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,12 @@ 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 |
| 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. |

**Example**:

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

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

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

**Пример**:

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.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "namemcwrapper",
"version": "1.8.0",
"version": "1.8.1",
"description": "ES6 Promise based wrapper for NameMC.com",
"main": "./dist/NameMC.js",
"exports": {
Expand Down
10 changes: 8 additions & 2 deletions src/DataParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,18 @@ import { WrapperError } from "./WrapperError";

import { profileSkinsRegExp, escapeColorsClasses, escapeHtml, skinRegExp } from "./utils";

import { ISkin, IExtendedSkin, INamedSkin, ICape, ICapeResponse, IRender, IGetEndpointOptions, IGetRendersOptions, ISkinResponse, ICapeInfo, IServerPreview, IServer, Hash, BasePlayerInfo, Model } from "./interfaces";
import { IOptions, ISkin, IExtendedSkin, INamedSkin, ICape, ICapeResponse, IRender, IGetEndpointOptions, IGetRendersOptions, ISkinResponse, ICapeInfo, IServerPreview, IServer, Hash, BasePlayerInfo, Model } from "./interfaces";
import TagElement = cheerio.TagElement;
import Root = cheerio.Root;

export abstract class DataParser {

options: IOptions;

protected constructor(options: IOptions) {
this.options = options;
}

abstract getEndpoint(options: IGetEndpointOptions): string;
abstract getRenders(options: IGetRendersOptions): IRender;
abstract getCapeInfo(hash: Hash): ICapeInfo;
Expand Down Expand Up @@ -333,7 +339,7 @@ export abstract class DataParser {
switch(type) {
case "skin": {
const name = (response as ISkinResponse).name || null;
const model = (response as ISkinResponse).model || "unknown";
const model = (response as ISkinResponse).model || (this.options.defaultSkinsModel || "unknown");
const rating = (response as ISkinResponse).rating ?? 0;

return {
Expand Down
4 changes: 3 additions & 1 deletion src/NameMC.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export class NameMC extends DataParser {
readonly api: API;

constructor(options: IOptions = {}) {
super();
super(options);

this.options = {
endpoint: "namemc.com",
Expand Down Expand Up @@ -153,6 +153,8 @@ export class NameMC extends DataParser {
}: IGetRendersOptions): IRender {
const endpoint: string = this.getEndpoint({ subdomain: "render" });

model = this.options.defaultSkinsModel || model;

return {
body: {
front: `${endpoint}/skin/3d/body.png?skin=${skin}&model=${model}&width=${width}&height=${height}&theta=${theta}&phi=${phi}&time=${time}`,
Expand Down
3 changes: 3 additions & 0 deletions src/interfaces/NameMC/options.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { Model } from "./skin";

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

0 comments on commit 34cf26d

Please sign in to comment.