diff --git a/app/components/home.tsx b/app/components/home.tsx index eb3ffa3..e3e43ef 100644 --- a/app/components/home.tsx +++ b/app/components/home.tsx @@ -1,5 +1,7 @@ import { WebviewTag } from 'electron'; +import * as _ from 'lodash'; import React from 'react'; +import { ItemTextService } from '../services'; import { PoeService } from '../services/poe.service'; import { LoginWebview } from './login-webview'; import { PriceListItem } from './price-list-item/price-list-item'; @@ -44,9 +46,13 @@ export class Home extends React.Component { if (json === null || json['error']) { this.setState({ showLogin: true }); } else if (json.items) { - this.setState({ showLogin: false, data: json.items }); - this.getItemPrice(json.items, 0); - console.log(json.items); + const items = _.map(json.items, item => { + item.fullText = ItemTextService.parseItem(item); + return item; + }); + + this.setState({ showLogin: false, data: items }); + this.getItemPrice(items, 0); } } @@ -60,8 +66,10 @@ export class Home extends React.Component { return; } - const res = await PoeService.priceCheck(data[index].typeLine); - if (res.currency_rec && res.min_price) { + console.log(data[index]); + console.log(data[index].fullText + '\n\n\n'); + const res = await PoeService.priceCheck(data[index].fullText); + if ((res.min && res.currency) || (res.currency_rec && res.min_price)) { const dataCopy: any = [...data]; dataCopy[index].priceInfo = res; await new Promise(resolve => this.setState({ data: dataCopy }, resolve)); @@ -79,6 +87,10 @@ export class Home extends React.Component { public render() { const { data, showLogin } = this.state; + const url = + 'https://www.pathofexile.com/character-window/get-stash-items' + + '?league=Incursion&tabs=1&tabIndex=0&accountName=DoctorCoctor'; + return (
{showLogin && } @@ -88,7 +100,7 @@ export class Home extends React.Component { ref="webview" partition="persist:poe" preload="ipc-renderer.js" - src="https://www.pathofexile.com/character-window/get-stash-items?league=Incursion&tabs=1&tabIndex=13&accountName=DoctorCoctor" + src={url} style={{ opacity: 0, width: '0', height: '0' }} />
diff --git a/app/components/login-webview.tsx b/app/components/login-webview.tsx index 990eaa5..01634ed 100644 --- a/app/components/login-webview.tsx +++ b/app/components/login-webview.tsx @@ -30,7 +30,7 @@ export class LoginWebview extends React.Component { ref="webview" partition="persist:poe" src="https://www.pathofexile.com/login" - style={{ height: '100%', width: '100%' }} + style={{ height: '500px', width: '100%' }} /> ); } diff --git a/app/components/price-list-item/price-list-item.tsx b/app/components/price-list-item/price-list-item.tsx index 84bc2c1..bf23fe6 100644 --- a/app/components/price-list-item/price-list-item.tsx +++ b/app/components/price-list-item/price-list-item.tsx @@ -18,17 +18,20 @@ export class PriceListItem extends React.Component { componentDidMount() {} render() { - const { data } = this.props; + const { fullText, icon, priceInfo, typeLine } = this.props.data; + return ( -
+
- +
- {data.typeLine} + {typeLine} +
+
+ {priceInfo ? `${priceInfo.min || priceInfo.min_price} ${priceInfo.currency || priceInfo.currency_rec}` : ''}
-
{data.priceInfo ? `${data.priceInfo.min_price} ${data.priceInfo.currency_rec}` : ''}
); diff --git a/app/model/frame-type.ts b/app/model/frame-type.ts new file mode 100644 index 0000000..a46eccc --- /dev/null +++ b/app/model/frame-type.ts @@ -0,0 +1,12 @@ +export const FrameType: { [key: number]: string } = { + 0: 'Normal', + 1: 'Magic', + 2: 'Rare', + 3: 'Unique', + 4: 'Gem', + 5: 'Currency', + 6: 'Divination Card', + 7: 'Quest Item', + 8: 'Prophecy', + 9: 'Relic', +}; diff --git a/app/services/index.ts b/app/services/index.ts new file mode 100644 index 0000000..a8a3364 --- /dev/null +++ b/app/services/index.ts @@ -0,0 +1,2 @@ +export * from './item-text.service'; +export * from './poe.service'; diff --git a/app/services/item-text.service.ts b/app/services/item-text.service.ts new file mode 100644 index 0000000..b47fca3 --- /dev/null +++ b/app/services/item-text.service.ts @@ -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, +}; diff --git a/app/services/poe.service.ts b/app/services/poe.service.ts index 7bc6cda..b2e4ea3 100644 --- a/app/services/poe.service.ts +++ b/app/services/poe.service.ts @@ -3,7 +3,8 @@ import { http } from '../http'; export class PoeService { public static async getStash(): Promise { 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; diff --git a/package-lock.json b/package-lock.json index 2dcc440..4d1bc7b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -84,6 +84,11 @@ "vue-template-es2015-compiler": "1.6.0" } }, + "@types/lodash": { + "version": "4.14.116", + "resolved": "https://registry.npmjs.org/@types/lodash/-/lodash-4.14.116.tgz", + "integrity": "sha512-lRnAtKnxMXcYYXqOiotTmJd74uawNWuPnsnPrrO7HiFuE3npE2iQhfABatbYDyxTNqZNuXzcKGhw37R7RjBFLg==" + }, "@types/node": { "version": "7.0.69", "resolved": "https://registry.npmjs.org/@types/node/-/node-7.0.69.tgz", diff --git a/package.json b/package.json index 2cabc7c..234770f 100644 --- a/package.json +++ b/package.json @@ -47,6 +47,7 @@ } }, "dependencies": { + "@types/lodash": "^4.14.116", "@types/react": "^16.4.9", "@types/react-dom": "^16.0.7", "autoprefixer": "^9.1.1", @@ -63,6 +64,7 @@ "file-loader": "^1.1.11", "font-awesome": "^4.7.0", "html-webpack-plugin": "^3.2.0", + "lodash": "^4.17.10", "node-sass": "^4.9.3", "normalize.css": "^8.0.0", "open-color": "^1.6.3",