more specific price seach should be working

This commit is contained in:
2018-08-14 23:36:09 -05:00
parent 4757abfff3
commit 5423b81c95
9 changed files with 157 additions and 17 deletions

2
app/services/index.ts Normal file
View File

@@ -0,0 +1,2 @@
export * from './item-text.service';
export * from './poe.service';

View File

@@ -0,0 +1,107 @@
import * as _ from 'lodash';
import { FrameType } from '../model/frame-type';
const lineBreak = '--------\n';
const parseItem = (item: any): string => {
let name = '';
name += `Rarity: ${FrameType[item.frameType]}\n`;
name += item.name ? filterName(item.name) + '\n' : '';
name += filterName(item.typeLine) + '\n';
name += getProperties(item.properties);
name += getProperties(item.requirements, 'Requirements:\n');
// sockets
name += getSockets(item.sockets);
name += item.ilvl ? `${lineBreak}Item Level: ${item.ilvl}\n` : '';
name += getMods(item.implicitMods);
name += getMods(item.explicitMods);
if (!item.identified) {
name += lineBreak;
name += 'Unidentified\n';
}
if (item.corrupted) {
name += lineBreak;
name += 'Corrupted\n';
}
if (item.elder) {
name += lineBreak;
name += 'Elder Item\n';
}
if (item.shaper) {
name += lineBreak;
name += 'Shaper Item\n';
}
if (item.descrText) {
name += lineBreak;
name += `${item.descrText}\n`;
}
return name;
};
const getSockets = (sockets: any[]): string => {
if (!sockets) {
return '';
}
let content = lineBreak;
content += 'Sockets: ';
const grp = _.groupBy(sockets, 'group');
_.each(_.keys(grp), key => {
content += grp[key].map(g => g.sColour).join('-');
content += ' ';
});
return content.trim() + '\n';
};
const filterName = (name: string): string => {
const index = name.lastIndexOf('>');
if (index < 0) {
return name;
}
return name
.slice(index + 4, name.length)
.replace('{', '')
.replace('}', '');
};
const getMods = (mods: string[]): string => {
if (!mods || mods.length === 0) {
return '';
}
let content = lineBreak;
content += _.map(mods, filterName).join('\n') + '\n';
return content;
};
const getProperties = (p?: any[], precedingText?: string): string => {
if (!p) {
return '';
}
let content = lineBreak;
content += precedingText || '';
p.forEach(item => {
content += item.name;
if (item.values && item.values.length > 0) {
content += `: ${item.values[0][0]}`;
}
content += '\n';
});
return content;
};
export const ItemTextService = {
parseItem,
};

View File

@@ -3,7 +3,8 @@ import { http } from '../http';
export class PoeService {
public static async getStash(): Promise<any> {
const res = await http.get(
'https://pathofexile.com/character-window/get-stash-items?league=Incursion&tabs=1&tabIndex=6&accountName=DoctorCoctor',
'https://pathofexile.com/character-window/get-stash-items?' +
'league=Incursion&tabs=1&tabIndex=6&accountName=DoctorCoctor',
);
return res.data;
}
@@ -11,11 +12,7 @@ export class PoeService {
public static async priceCheck(item: any) {
const res = await http.get(`https://poeprices.info/api?l=Incursion&i=${encodeURI(btoa(item))}`, {
headers: {
// Host: 'poeprices.info',
// Connection: 'keep-alive',
'Cache-Control': 'max-age=600',
// Origin: 'https://poeprices.info',
// Accept: 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
},
});
return res.data;