Skip to content

Commit

Permalink
Update galnet feed, remove legacy commodity feed
Browse files Browse the repository at this point in the history
  • Loading branch information
iaincollins committed Oct 28, 2024
1 parent 842eb77 commit 883bbca
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 47 deletions.
3 changes: 2 additions & 1 deletion lib/cron-tasks/galnet-news.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const fs = require('fs')
const { ARDENT_GALNET_NEWS_CACHE } = require('../consts')

const GALNET_NEWS_FEED = 'https://cms.zaonce.net/en-GB/jsonapi/node/galnet_article'
const GALNET_NEWS_FEED = 'https://cms.zaonce.net/en-GB/jsonapi/node/galnet_article?&sort=-published_at&page[offset]=0&page[limit]=12 '

module.exports = async () => {
try {
Expand All @@ -14,6 +14,7 @@ module.exports = async () => {
title: item.attributes.title,
text: item.attributes.body.value.replace(/\r/g, ''),
slug: item.attributes.field_slug,
image: `https://hosting.zaonce.net/elite-dangerous/galnet/${item.attributes.field_galnet_image}.png`,
url: `https://community.elitedangerous.com/galnet/uid/${item.attributes.field_galnet_guid}`
}))

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ardent-api",
"version": "4.1.0",
"version": "4.2.0",
"description": "Ardent API provides access to data submitted to EDDN",
"main": "index.js",
"scripts": {
Expand Down
45 changes: 0 additions & 45 deletions router/api/commodities.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,51 +17,6 @@ module.exports = (router) => {
ctx.body = JSON.parse(fs.readFileSync(COMMODITIES_REPORT)).commodities
})

// deprecated - will be removed in a future update
router.get('/api/v1-beta/commodities/ticker', async (ctx, next) => {
const stations = await dbAsync.all(`
SELECT * FROM stations.stations AS s WHERE
s.stationType != 'Fleet Carrier'
AND s.stationType IS NOT NULL
GROUP BY s.stationName
ORDER BY s.updatedAt DESC
LIMIT 50`)

const imports = []
for (const station of stations) {
const stationImport = await dbAsync.get(`
SELECT * FROM trade.commodities as c
WHERE c.marketId = @marketId
AND (c.demand > 1000 OR c.demand = 0)
AND c.demandBracket = 3
AND c.updatedAt > '${getISOTimestamp('-1')}'
ORDER BY c.sellPrice DESC
LIMIT 5`, { marketId: station.marketId })
if (stationImport) imports.push(stationImport)
}

const exports = []
for (const station of stations) {
const stationExport = await dbAsync.get(`
SELECT * FROM trade.commodities as c
WHERE c.marketId = @marketId
AND c.stock > 1000
AND c.stockBracket = 3
AND c.updatedAt > '${getISOTimestamp('-1')}'
ORDER BY c.buyPrice DESC
LIMIT 5`, { marketId: station.marketId })
if (stationExport) exports.push(stationExport)
}

const result = [
...imports,
...exports
].sort((a, b) => a.updatedAt.localeCompare(b.updatedAt)) // Sort results by recency
.filter((obj1, i, arr) => arr.findIndex(obj2 => (obj2.marketId === obj1.marketId)) === i) // Filter so only one entry for each station

ctx.body = result
})

router.get('/api/v1/commodities/core-systems-1000', async (ctx, next) => {
ctx.body = JSON.parse(fs.readFileSync(CORE_SYSTEMS_1000_REPORT))
})
Expand Down

0 comments on commit 883bbca

Please sign in to comment.