You've already forked tf2wikipricing
lint: define interface for remote schema response
This commit is contained in:
@@ -44,6 +44,44 @@ export class ItemSchema {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface SchemaResponseItem {
|
||||||
|
name: string;
|
||||||
|
defindex: number;
|
||||||
|
item_class: string;
|
||||||
|
item_type_name: string;
|
||||||
|
item_name: string;
|
||||||
|
item_description: string;
|
||||||
|
proper_name: boolean;
|
||||||
|
item_slot: ItemSlot;
|
||||||
|
model_player: string;
|
||||||
|
item_quality: number;
|
||||||
|
image_inventory: string;
|
||||||
|
min_ilevel: number;
|
||||||
|
max_ilevel: number;
|
||||||
|
image_url: string;
|
||||||
|
image_url_large: string;
|
||||||
|
drop_type: string;
|
||||||
|
craft_class: string;
|
||||||
|
craft_material_type: string;
|
||||||
|
capabilities: {
|
||||||
|
decodable?: boolean,
|
||||||
|
can_be_restored?: boolean;
|
||||||
|
can_card_upgrade?: boolean;
|
||||||
|
can_consume?: boolean;
|
||||||
|
can_craft_mark?: boolean;
|
||||||
|
can_gift_wrap?: boolean;
|
||||||
|
can_killstreakify?: boolean;
|
||||||
|
can_strangify?: boolean;
|
||||||
|
paintable?: boolean;
|
||||||
|
strange_parts?: boolean;
|
||||||
|
};
|
||||||
|
attributes: Array<{
|
||||||
|
name: string;
|
||||||
|
class: string;
|
||||||
|
value: number | string; // The value can sometimes be a string, but example uses numbers
|
||||||
|
}>;
|
||||||
|
}
|
||||||
|
|
||||||
export function getItemIndexByName(schema: ItemSchema, name: string, excludeStock: boolean = true, excludeDecorated: boolean = true) {
|
export function getItemIndexByName(schema: ItemSchema, name: string, excludeStock: boolean = true, excludeDecorated: boolean = true) {
|
||||||
for (const [defindex, value] of Object.entries(schema)) {
|
for (const [defindex, value] of Object.entries(schema)) {
|
||||||
if (value['name'] == name) {
|
if (value['name'] == name) {
|
||||||
@@ -152,21 +190,20 @@ export async function prepareSchema(): Promise<ItemSchema> {
|
|||||||
|
|
||||||
const cacheItems = {}
|
const cacheItems = {}
|
||||||
|
|
||||||
const responseItems: any[] = await response.json()
|
const responseItems: SchemaResponseItem[] = await response.json()
|
||||||
// We want to keep the keys `defindex`, `item_name`, and `attributes`
|
// We want to keep the keys `defindex`, `item_name`, and `attributes`
|
||||||
responseItems.forEach((item: any) => {
|
responseItems.forEach((item: SchemaResponseItem) => {
|
||||||
const defindex: number = item['defindex']
|
const defindex: number = item['defindex']
|
||||||
|
|
||||||
let tradable: boolean = true
|
let tradable: boolean = true
|
||||||
try {
|
try {
|
||||||
if(item['attributes'] != null) {
|
if(item['attributes'] != null) {
|
||||||
if(item['attributes'].find((attribute: {}) => (attribute as any)['class'] == "cannot_trade")) {
|
if(item['attributes'].find((attribute) => attribute['class'] == "cannot_trade")) {
|
||||||
tradable = false
|
tradable = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch(error) {
|
} catch(error) {
|
||||||
logError(error)
|
logError(error)
|
||||||
log(item)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let canKillstreakify: boolean = false
|
let canKillstreakify: boolean = false
|
||||||
@@ -178,7 +215,6 @@ export async function prepareSchema(): Promise<ItemSchema> {
|
|||||||
}
|
}
|
||||||
} catch(error) {
|
} catch(error) {
|
||||||
logError(error)
|
logError(error)
|
||||||
log(item)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
(cacheItems as any)[defindex.toString()] = {
|
(cacheItems as any)[defindex.toString()] = {
|
||||||
|
|||||||
Reference in New Issue
Block a user