cleanup
This commit is contained in:
parent
3d7a8aafdf
commit
c1892230b7
13 changed files with 1111 additions and 993 deletions
56
src/server/routes/links.ts
Normal file
56
src/server/routes/links.ts
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
import { Router } from 'express';
|
||||
import type { Bot } from '../../bot/Bot.js';
|
||||
|
||||
export function linkRoutes(bot: Bot): Router {
|
||||
const router = Router();
|
||||
|
||||
router.post('/', (req, res) => {
|
||||
const { url, name, mode } = req.body as { url: string; name?: string; mode?: string };
|
||||
if (!url || !url.includes('pathofexile.com/trade')) {
|
||||
res.status(400).json({ error: 'Invalid trade URL' });
|
||||
return;
|
||||
}
|
||||
const linkMode = mode === 'scrap' ? 'scrap' : 'live';
|
||||
bot.addLink(url, name || '', linkMode);
|
||||
res.json({ ok: true });
|
||||
});
|
||||
|
||||
router.delete('/:id', (req, res) => {
|
||||
bot.removeLink(req.params.id);
|
||||
res.json({ ok: true });
|
||||
});
|
||||
|
||||
router.post('/:id/toggle', (req, res) => {
|
||||
const { active } = req.body as { active: boolean };
|
||||
bot.toggleLink(req.params.id, active);
|
||||
res.json({ ok: true });
|
||||
});
|
||||
|
||||
router.post('/:id/name', (req, res) => {
|
||||
const { name } = req.body as { name: string };
|
||||
bot.updateLinkName(req.params.id, name);
|
||||
res.json({ ok: true });
|
||||
});
|
||||
|
||||
router.post('/:id/mode', (req, res) => {
|
||||
const { mode } = req.body as { mode: string };
|
||||
if (mode !== 'live' && mode !== 'scrap') {
|
||||
res.status(400).json({ error: 'Invalid mode. Must be "live" or "scrap".' });
|
||||
return;
|
||||
}
|
||||
bot.updateLinkMode(req.params.id, mode);
|
||||
res.json({ ok: true });
|
||||
});
|
||||
|
||||
router.post('/:id/post-action', (req, res) => {
|
||||
const { postAction } = req.body as { postAction: string };
|
||||
if (postAction !== 'stash' && postAction !== 'salvage') {
|
||||
res.status(400).json({ error: 'Invalid postAction. Must be "stash" or "salvage".' });
|
||||
return;
|
||||
}
|
||||
bot.updateLinkPostAction(req.params.id, postAction);
|
||||
res.json({ ok: true });
|
||||
});
|
||||
|
||||
return router;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue