36 lines
1.1 KiB
JavaScript
36 lines
1.1 KiB
JavaScript
|
|
import express from 'express';
|
||
|
|
|
||
|
|
const router = express.Router();
|
||
|
|
const REPLICATE_BASE = 'https://api.replicate.com/v1';
|
||
|
|
|
||
|
|
router.get('/', async (req, res) => {
|
||
|
|
const token = process.env.REPLICATE_API_TOKEN;
|
||
|
|
if (!token) return res.status(400).json({ error: 'REPLICATE_API_TOKEN not configured' });
|
||
|
|
|
||
|
|
try {
|
||
|
|
const response = await fetch(`${REPLICATE_BASE}/account`, {
|
||
|
|
headers: { 'Authorization': `Bearer ${token}` }
|
||
|
|
});
|
||
|
|
if (!response.ok) {
|
||
|
|
const err = await response.json().catch(() => ({}));
|
||
|
|
return res.status(response.status).json({ error: err.detail || 'Failed to fetch account' });
|
||
|
|
}
|
||
|
|
const account = await response.json();
|
||
|
|
|
||
|
|
// Try to get hardware/usage info
|
||
|
|
let hardware = null;
|
||
|
|
try {
|
||
|
|
const hwRes = await fetch(`${REPLICATE_BASE}/hardware`, {
|
||
|
|
headers: { 'Authorization': `Bearer ${token}` }
|
||
|
|
});
|
||
|
|
if (hwRes.ok) hardware = await hwRes.json();
|
||
|
|
} catch (_) {}
|
||
|
|
|
||
|
|
res.json({ account, hardware });
|
||
|
|
} catch (err) {
|
||
|
|
res.status(500).json({ error: err.message });
|
||
|
|
}
|
||
|
|
});
|
||
|
|
|
||
|
|
export { router as accountRouter };
|