56 lines
1.7 KiB
TypeScript
56 lines
1.7 KiB
TypeScript
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;
|
|
}
|