67 lines
1.9 KiB
JavaScript
67 lines
1.9 KiB
JavaScript
const express = require('express');
|
|
const axios = require('axios');
|
|
const router = express.Router();
|
|
|
|
const EMBY_URL = process.env.EMBY_URL;
|
|
const EMBY_API_KEY = process.env.EMBY_API_KEY;
|
|
|
|
// Get active sessions
|
|
router.get('/sessions', async (req, res) => {
|
|
try {
|
|
const response = await axios.get(`${EMBY_URL}/Sessions`, {
|
|
headers: { 'X-MediaBrowser-Token': EMBY_API_KEY }
|
|
});
|
|
res.json(response.data);
|
|
} catch (error) {
|
|
res.status(500).json({ error: 'Failed to fetch Emby sessions', details: error.message });
|
|
}
|
|
});
|
|
|
|
// Get user by ID
|
|
router.get('/users/:id', async (req, res) => {
|
|
try {
|
|
const response = await axios.get(`${EMBY_URL}/Users/${req.params.id}`, {
|
|
headers: { 'X-MediaBrowser-Token': EMBY_API_KEY }
|
|
});
|
|
res.json(response.data);
|
|
} catch (error) {
|
|
res.status(500).json({ error: 'Failed to fetch user details', details: error.message });
|
|
}
|
|
});
|
|
|
|
// Get all users
|
|
router.get('/users', async (req, res) => {
|
|
try {
|
|
const response = await axios.get(`${EMBY_URL}/Users`, {
|
|
headers: { 'X-MediaBrowser-Token': EMBY_API_KEY }
|
|
});
|
|
res.json(response.data);
|
|
} catch (error) {
|
|
res.status(500).json({ error: 'Failed to fetch users', details: error.message });
|
|
}
|
|
});
|
|
|
|
// Get current user by session ID
|
|
router.get('/session/:sessionId/user', async (req, res) => {
|
|
try {
|
|
const response = await axios.get(`${EMBY_URL}/Sessions`, {
|
|
headers: { 'X-MediaBrowser-Token': EMBY_API_KEY }
|
|
});
|
|
|
|
const session = response.data.find(s => s.Id === req.params.sessionId);
|
|
if (!session) {
|
|
return res.status(404).json({ error: 'Session not found' });
|
|
}
|
|
|
|
const userResponse = await axios.get(`${EMBY_URL}/Users/${session.UserId}`, {
|
|
headers: { 'X-MediaBrowser-Token': EMBY_API_KEY }
|
|
});
|
|
|
|
res.json(userResponse.data);
|
|
} catch (error) {
|
|
res.status(500).json({ error: 'Failed to fetch user from session', details: error.message });
|
|
}
|
|
});
|
|
|
|
module.exports = router;
|