Migrate to yarn

This commit is contained in:
2022-07-07 00:51:28 +03:00
parent 1af1048670
commit 78fd1b5adf
32 changed files with 10289 additions and 20356 deletions

View File

@@ -1,3 +0,0 @@
{
"extends": "standard"
}

15
gather/.eslintrc.js Normal file
View File

@@ -0,0 +1,15 @@
export default {
parser: '@typescript-eslint/parser',
extends: 'standard-with-typescript',
parserOptions: {
project: './tsconfig.json'
},
rules: {
'@typescript-eslint/no-floating-promises': [
'error',
{
ignoreIIFE: true
}
]
}
}

6816
gather/package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,21 +1,22 @@
{
"name": "warframe-market-bot",
"name": "gather",
"private": true,
"version": "1.0.0",
"description": "The background job that collects data and stores it in a DB",
"main": "index.js",
"scripts": {
"start": "node src/index.js"
"start": "node ./dist/index.js",
"build": "./node_modules/typescript/bin/tsc"
},
"author": "Anatoly Kopyl",
"license": "ISC",
"dependencies": {
"axios": "^0.26.0",
"dotenv": "^16.0.0",
"limiter": "^2.1.0",
"shared-stuff": "file:../shared-stuff"
"mongoose": "^6.4.3",
"shared-stuff": "1.0.0",
"typescript": "^4.7.4"
},
"devDependencies": {
"eslint-config-standard": "^16.0.3",
"eslint-config-standard-with-typescript": "^22.0.0",
"pm2": "^5.2.0"
}
}

View File

@@ -1,44 +0,0 @@
const axios = require('axios')
const { RateLimiter } = require('limiter')
class Api {
constructor () {
this.baseUrl = 'https://api.warframe.market/v1/'
this.delay = process.env.API_DELAY ?? 3000
this.limiter = new RateLimiter({ tokensPerInterval: 1, interval: Number(this.delay) })
}
async _get (url) {
await this.limiter.removeTokens(1)
return axios.get(url).catch((error) => {
console.error(error)
return {
data: {
payload: {
orders: []
}
}
}
})
}
async getOrders (url) {
const response = await this._get(this.baseUrl + 'items/' + url + '/orders')
return response.data.payload.orders.filter(function (order) {
return order.order_type === 'sell' && order.user.status !== 'offline'
})
}
async getSortedOrders (url) {
const orders = await this.getOrders(url)
if (orders.length === 0) {
return []
}
return orders.sort(function (a, b) {
return a.platinum - b.platinum
})
}
}
module.exports = new Api()

59
gather/src/api.ts Normal file
View File

@@ -0,0 +1,59 @@
import axios from 'axios'
import type { AxiosError } from 'axios'
import { RateLimiter } from 'limiter'
type user = {
status: 'online' | 'offline'
}
type order = {
order_type: 'buy' | 'sell',
platinum: number,
user: user
}
class Api {
baseUrl: string
delay: number
limiter: RateLimiter
constructor () {
this.baseUrl = 'https://api.warframe.market/v1/'
this.delay = Number(process.env.API_DELAY) ?? 3000
this.limiter = new RateLimiter({ tokensPerInterval: 1, interval: Number(this.delay) })
}
async _get (url: string) {
await this.limiter.removeTokens(1)
return axios.get(url).catch((error: AxiosError) => {
console.error(error)
return {
data: {
payload: {
orders: []
}
}
}
})
}
async getOrders (url: string): Promise<order[]> {
const response = await this._get(this.baseUrl + 'items/' + url + '/orders')
return response.data.payload.orders.filter(function (order: order) {
return order.order_type === 'sell' && order.user.status !== 'offline'
})
}
async getSortedOrders (url: string): Promise<order[]> {
const orders = await this.getOrders(url)
if (orders.length === 0) {
return []
}
return orders.sort(function (a: order, b: order) {
return a.platinum - b.platinum
})
}
}
export default new Api()

View File

@@ -1,10 +1,10 @@
require('dotenv').config()
const mongoose = require('mongoose')
const items = require('./items')
const { models } = require('shared-stuff')
import mongoose from 'mongoose'
import items from './items'
import { models } from 'shared-stuff'
import 'dotenv/config'
async function initDB () {
await mongoose.connect(process.env.MONGODB_URI)
async function initDB (): Promise<void> {
await mongoose.connect(String(process.env.MONGODB_URI))
}
(async () => {

View File

@@ -1,7 +1,7 @@
const Item = require('./Item')
import Item from './Item'
module.exports = class Archwings extends Item {
constructor (name) {
export default class Archwings extends Item {
constructor (name: string) {
super(name)
this.addPart('harness')

View File

@@ -1,7 +1,7 @@
const Item = require('./Item')
import Item from './Item'
module.exports = class Companion extends Item {
constructor (name) {
export default class Companion extends Item {
constructor (name: string) {
super(name)
this.addPart('carapace')

View File

@@ -1,11 +1,16 @@
const Part = require('./Part')
import Part from './Part'
function capitalize (string) {
function capitalize (string: string) {
return string.charAt(0).toUpperCase() + string.slice(1)
}
module.exports = class Item {
constructor (name) {
export default class Item {
name: string
fullName: string
set: Part
parts: Part[]
constructor (name: string) {
this.name = name
this.fullName = capitalize(name) + ' Prime'
this.set = new Part(name, 'set')
@@ -14,7 +19,7 @@ module.exports = class Item {
this.addPart('blueprint')
}
addPart (part, amount) {
addPart (part: string, amount: number = 1) {
this.parts.push(new Part(this.name, part, amount))
}
}

View File

@@ -1,14 +1,19 @@
const Api = require('../api')
import Api from '../api'
module.exports = class Part {
constructor (set, part, amount) {
export default class Part {
part: string
urlPath: string
url: string
amount: number
constructor (set: string, part: string, amount: number = 1) {
this.part = part
this.urlPath = `${set}_prime_${part}`
this.url = `https://warframe.market/items/${set}_prime_${part}`
this.amount = amount ?? 1
}
async getPrice () {
async getPrice (): Promise<number> {
const orders = await Api.getSortedOrders(this.urlPath)
if (orders.length === 0) {
return 0

View File

@@ -1,7 +1,7 @@
const Item = require('./Item')
import Item from './Item'
module.exports = class Primary extends Item {
constructor (name) {
export default class Primary extends Item {
constructor (name: string) {
super(name)
this.addPart('barrel')

View File

@@ -1,7 +1,7 @@
const Item = require('./Item')
import Item from './Item'
module.exports = class Secondary extends Item {
constructor (name) {
export default class Secondary extends Item {
constructor (name: string) {
super(name)
this.addPart('barrel', 2)

View File

@@ -1,7 +1,7 @@
const Item = require('./Item')
import Item from './Item'
module.exports = class Warframe extends Item {
constructor (name) {
export default class Warframe extends Item {
constructor (name: string) {
super(name)
this.addPart('systems')

View File

@@ -1,11 +1,12 @@
const items = require('./items.json')
const Warframe = require('./Warframe')
import items from './items.json'
import Warframe from './Warframe'
// const Primary = require('./Primary')
// const Secondary = require('./Secondary')
const Companion = require('./Companion')
const Archwings = require('./Archwings')
import Companion from './Companion'
import Archwings from './Archwings'
import type Item from './Item'
const result = []
const result: Item[] = []
items.warframes.forEach((name) => {
result.push(new Warframe(name))
@@ -23,4 +24,4 @@ items.archwings.forEach((name) => {
result.push(new Archwings(name))
})
module.exports = result
export default result

20
gather/tsconfig.json Normal file
View File

@@ -0,0 +1,20 @@
{
"compilerOptions": {
"target": "esnext",
"module": "commonjs",
"allowJs": true,
"checkJs": false,
"outDir": "dist",
"rootDir": ".",
"strict": true,
"forceConsistentCasingInFileNames": true,
"strictNullChecks": true,
"resolveJsonModule": true,
"esModuleInterop": true,
},
"exclude": ["node_modules", "dist"],
"include": [
"./src",
"./*",
]
}

1651
gather/yarn-error.log Normal file

File diff suppressed because it is too large Load Diff

1594
gather/yarn.lock Normal file

File diff suppressed because it is too large Load Diff