less hacking way of pulling poe data
This commit is contained in:
@@ -63,14 +63,16 @@ const getSockets = (sockets: any[]): string => {
|
||||
return content.trim() + '\n';
|
||||
};
|
||||
|
||||
/** filter unwanted characters from item name */
|
||||
const filterName = (name: string): string => {
|
||||
const index = name.lastIndexOf('>');
|
||||
const newString = name.replace(/>/g, '>');
|
||||
const index = newString.lastIndexOf('>');
|
||||
if (index < 0) {
|
||||
return name;
|
||||
}
|
||||
|
||||
return name
|
||||
.slice(index + 4, name.length)
|
||||
.slice(index + 1, name.length)
|
||||
.replace('{', '')
|
||||
.replace('}', '');
|
||||
};
|
||||
@@ -103,5 +105,6 @@ const getProperties = (p?: any[], precedingText?: string): string => {
|
||||
};
|
||||
|
||||
export const ItemTextService = {
|
||||
filterName,
|
||||
parseItem,
|
||||
};
|
||||
|
||||
@@ -1,20 +1,44 @@
|
||||
import PQueue from 'p-queue';
|
||||
import { POE_HOME, POE_LEAGUE_LIST_URL, POE_STASH_ITEMS_URL } from '../constants';
|
||||
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',
|
||||
);
|
||||
return res.data;
|
||||
}
|
||||
const queue = new PQueue({ concurrency: 1 });
|
||||
|
||||
public static async priceCheck(item: any) {
|
||||
const res = await http.get(`https://poeprices.info/api?l=Incursion&i=${encodeURI(btoa(item))}`, {
|
||||
headers: {
|
||||
'Cache-Control': 'max-age=600',
|
||||
},
|
||||
const getStash = async (username: string, league: string, tabIndex: number | string): Promise<any> => {
|
||||
const res = await http.get(
|
||||
`${POE_STASH_ITEMS_URL}?league=${league}&tabs=1&tabIndex=${tabIndex}&accountName=${username}`,
|
||||
);
|
||||
return res.data;
|
||||
};
|
||||
|
||||
const priceCheck = async (item: any): Promise<any> => {
|
||||
return new Promise(resolve => {
|
||||
queue.add(() => {
|
||||
return http
|
||||
.get(`https://poeprices.info/api?l=Incursion&i=${encodeURI(btoa(item))}`, {
|
||||
headers: {
|
||||
'Cache-Control': 'max-age=600',
|
||||
},
|
||||
})
|
||||
.then(resolve);
|
||||
});
|
||||
return res.data;
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
const getUsername = async (): Promise<any> => {
|
||||
const res = await http.get(POE_HOME);
|
||||
const username = res.data.match(/\/account\/view-profile\/(.*?)\"/);
|
||||
return username[1];
|
||||
};
|
||||
|
||||
const getLeagues = async (): Promise<any> => {
|
||||
const res = await http.get(POE_LEAGUE_LIST_URL);
|
||||
return res.data;
|
||||
};
|
||||
|
||||
export const PoeService = {
|
||||
getLeagues,
|
||||
getStash,
|
||||
getUsername,
|
||||
priceCheck,
|
||||
};
|
||||
|
||||
25
app/services/storage.service.ts
Normal file
25
app/services/storage.service.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import Store from 'electron-store';
|
||||
const store = new Store();
|
||||
|
||||
const storeUsername = (username: string) => {
|
||||
store.set('user', username);
|
||||
};
|
||||
|
||||
const storeSessionID = (sessionID: string) => {
|
||||
store.set('sessionID', sessionID);
|
||||
};
|
||||
|
||||
const getSessionID = (): string | undefined => {
|
||||
return store.get('sessionID') || undefined;
|
||||
};
|
||||
|
||||
const getUsername = (): string | undefined => {
|
||||
return store.get('user') || undefined;
|
||||
};
|
||||
|
||||
export const StorageService = {
|
||||
getUsername,
|
||||
getSessionID,
|
||||
storeUsername,
|
||||
storeSessionID,
|
||||
};
|
||||
Reference in New Issue
Block a user