fast72 commited on
Commit
dc17900
·
verified ·
1 Parent(s): 8fa2db9

Upload 2 files

Browse files
Files changed (2) hide show
  1. index.js +55 -0
  2. package.json +6 -0
index.js ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ const express = require('express')
2
+ const axios = require('axios')
3
+
4
+ const app = express()
5
+ const PORT = 7860
6
+
7
+ const seedOrder = [
8
+ 'Carrot', 'Strawberry', 'Blueberry', 'Orange Tulip', 'Tomato', 'Corn', 'Daffodil',
9
+ 'Watermelon', 'Pumpkin', 'Apple', 'Bamboo', 'Coconut', 'Cactus', 'Dragon Fruit',
10
+ 'Mango', 'Grape', 'Mushroom', 'Pepper', 'Cacao', 'Beanstalk', 'Ember Lily', 'Sugar Apple'
11
+ ]
12
+
13
+ const gearOrder = [
14
+ 'Watering Can', 'Trowel', 'Recall Wrench', 'Basic Sprinkler', 'Advanced Sprinkler',
15
+ 'Godly Sprinkler', 'Lightning Rod', 'Master Sprinkler', 'Cleaning Spray',
16
+ 'Favorite Tool', 'Harvest Tool', 'Friendship Pot'
17
+ ]
18
+
19
+ const baseUrl = 'https://www.growagardenvalues.com/stock/refresh_stock.php?type='
20
+
21
+ async function fetchStock(type) {
22
+ try {
23
+ const res = await axios.get(`${baseUrl}${type}`)
24
+ return res.data?.data?.records || []
25
+ } catch {
26
+ return []
27
+ }
28
+ }
29
+
30
+ function sortAndFormat(records, order) {
31
+ return order
32
+ .map(name => {
33
+ const found = records.find(r => r?.Data?.Name === name)
34
+ return found ? { name, value: found.Amount } : null
35
+ })
36
+ .filter(Boolean)
37
+ }
38
+
39
+ app.get('/', async (req, res) => {
40
+ const [seeds, gears, eggs] = await Promise.all([
41
+ fetchStock('seeds'),
42
+ fetchStock('gears'),
43
+ fetchStock('eggs')
44
+ ])
45
+
46
+ res.json({
47
+ seeds: sortAndFormat(seeds, seedOrder),
48
+ gears: sortAndFormat(gears, gearOrder),
49
+ eggs: eggs.map(e => ({ name: e.Data?.Name, value: e.Amount })).filter(e => e.name)
50
+ })
51
+ })
52
+
53
+ app.listen(PORT, () => {
54
+ console.log(`http://localhost:${PORT}`)
55
+ })
package.json ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ {
2
+ "dependencies": {
3
+ "axios": "^1.10.0",
4
+ "express": "^5.1.0"
5
+ }
6
+ }