Initial commit: KeySelector implementation
This commit is contained in:
commit
48cdda01ca
30 files changed
+2272
No files matched your search
@@ -0,0 +1,27 @@
|
||||
const express = require('express');
|
||||
const fetch = require('node-fetch');
|
||||
const router = express.Router();
|
||||
|
||||
// Fetch cover from iTunes API to avoid frontend CORS issues
|
||||
router.get('/', async (req, res) => {
|
||||
const q = req.query.q;
|
||||
if (!q) return res.status(400).json({ error: 'Missing q parameter' });
|
||||
|
||||
try {
|
||||
const url = `https://itunes.apple.com/search?term=${encodeURIComponent(q)}&media=music&entity=song&limit=1`;
|
||||
const response = await fetch(url);
|
||||
const data = await response.json();
|
||||
|
||||
if (data.results && data.results[0] && data.results[0].artworkUrl100) {
|
||||
const src = data.results[0].artworkUrl100.replace('100x100bb', '300x300bb');
|
||||
return res.json({ url: src });
|
||||
}
|
||||
|
||||
res.json({ url: null });
|
||||
} catch (err) {
|
||||
console.error('iTunes cover fetch error', err);
|
||||
res.status(500).json({ error: 'Server error fetching cover' });
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
Reference in new issue
Block a user