Skip to content

Commit 4a01c75

Browse files
committed
Fix all build errors; and tested - working!
1 parent 3ddecd9 commit 4a01c75

File tree

5 files changed

+26
-16
lines changed

5 files changed

+26
-16
lines changed

src/controllers/index.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,14 @@ const API_ROOT = 'https://api.relisten.net/api/v2';
4343
registerFont(__dirname + '/../../fonts/Roboto-Black.ttf', { family: 'RobotoBlack' });
4444

4545
router.get('/', (req, res) => {
46-
return res.json({ hi: 'hi world' });
46+
res.json({ hi: 'hi world' });
4747
});
4848

4949
router.get('/album-art/:artist/years/:year/:show_date/{:source}/:size.png', (req, res) => {
5050
const size = parseInt(req.params['size'] || '500', 10); // Provide default or handle NaN
5151

5252
if (isNaN(size) || !(size > 0 && size <= 1500)) {
53-
return res.status(400).send('Invalid size parameter');
53+
res.status(400).send('Invalid size parameter');
5454
}
5555

5656
const canvas: Canvas = createCanvas(size, size);
@@ -73,7 +73,7 @@ router.get('/album-art/:artist/years/:year/:show_date/{:source}/:size.png', (req
7373
.then((json: ShowApiResponse) => {
7474
if (!json || !json.sources || json.sources.length === 0) {
7575
winston.error('no json sources found (v2 api)', { slug, year, date, sourceId });
76-
return res.status(404).send('Show or sources not found');
76+
res.status(404).send('Show or sources not found');
7777
}
7878

7979
// Find source by ID if provided, otherwise use the first source
@@ -88,7 +88,7 @@ router.get('/album-art/:artist/years/:year/:show_date/{:source}/:size.png', (req
8888
date,
8989
sourceId,
9090
});
91-
return res.status(404).send('Source not found or invalid');
91+
res.status(404).send('Source not found or invalid');
9292
}
9393

9494
let venue: Venue = {
@@ -130,7 +130,7 @@ router.get('/album-art/:artist/years/:year/:show_date/{:source}/:size.png', (req
130130
date,
131131
sourceId,
132132
});
133-
return res.status(500).send('Error generating image buffer');
133+
res.status(500).send('Error generating image buffer');
134134
}
135135
res.send(buf);
136136
},
@@ -156,7 +156,7 @@ router.get('/ios-album-art/:artist/:source_uuid/:size.png', (req, res) => {
156156
const size = parseInt(req.params['size'] || '500', 10); // Provide default or handle NaN
157157

158158
if (isNaN(size) || !(size > 0 && size <= 1500)) {
159-
return res.status(400).send('Invalid size parameter');
159+
res.status(400).send('Invalid size parameter');
160160
}
161161

162162
const canvas: Canvas = createCanvas(size, size);
@@ -177,7 +177,7 @@ router.get('/ios-album-art/:artist/:source_uuid/:size.png', (req, res) => {
177177
// V3 show endpoint returns a single show, sources are within it.
178178
if (!json || !json.sources || json.sources.length === 0) {
179179
winston.error('no json sources found (v3 api)', { sourceUuid });
180-
return res.status(404).send('Show or sources not found');
180+
res.status(404).send('Show or sources not found');
181181
}
182182

183183
// In v3 /shows/{uuid}, the response is the show containing the source.
@@ -191,7 +191,7 @@ router.get('/ios-album-art/:artist/:source_uuid/:size.png', (req, res) => {
191191
artistParam,
192192
sourceUuid,
193193
});
194-
return res.status(404).send('Source not found or invalid');
194+
res.status(404).send('Source not found or invalid');
195195
}
196196

197197
let venue: Venue = {
@@ -228,7 +228,7 @@ router.get('/ios-album-art/:artist/:source_uuid/:size.png', (req, res) => {
228228
(err, buf) => {
229229
if (err) {
230230
winston.error('Failed to create PNG buffer', { error: err, artistParam, sourceUuid });
231-
return res.status(500).send('Error generating image buffer');
231+
res.status(500).send('Error generating image buffer');
232232
}
233233
res.send(buf);
234234
},

src/lib/artistsCache.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
2-
const artistsCache: { [key: string]: { slug: string } } = {};
1+
const artistsCache: { [key: string]: { slug: string; name: string } } = {};
32

43
fetch('https://api.relisten.net/api/v2/artists')
54
.then((res) => res.json())
6-
.then((json) => json.map((artist: { slug: string}) => (artistsCache[artist.slug] = artist)));
5+
.then((json) =>
6+
json.map((artist: { slug: string; name: string }) => (artistsCache[artist.slug] = artist))
7+
);
78

89
export default artistsCache;

src/server.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,17 @@ const wsdl = fs.readFileSync(__dirname + '/../Sonos.wsdl', 'utf8');
1515
app.use(controllers);
1616
app.use('/static', express.static(path.join(__dirname, 'public')));
1717

18-
app.listen(PORT, '0.0.0.0', (err: any) => {
19-
if (err) winston.info('Error', err);
18+
process.on('unhandledRejection', (err) => {
19+
console.error('unhandledRejection', err);
20+
winston.error('unhandledRejection');
21+
});
22+
23+
process.on('uncaughtException', (err) => {
24+
console.error('uncaughtException', err);
25+
winston.error('uncaughtException');
26+
});
2027

28+
app.listen(PORT, '0.0.0.0', () => {
2129
const listener = soap.listen(app, '/wsdl', services('mp3'), wsdl); // only here for posterity
2230
const mp3Listener = soap.listen(app, '/mp3', services('mp3'), wsdl);
2331
const flacListener = soap.listen(app, '/flac', services('flac'), wsdl);

src/services/getMediaURI.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ const getMediaURI = (type, id, callback) => {
3030

3131
let trackUrl = track[`${type}_url`] || track.mp3_url;
3232

33-
let headers = [];
33+
const headers = [];
3434

3535
if (/\/archive\.org/.test(trackUrl)) {
3636
trackUrl = trackUrl.replace('://archive.org/', '://audio.relisten.net/archive.org/');

src/services/search.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export default (type) => (args, callback) => {
2727
.then((json) => {
2828
const results = [];
2929

30-
searchForArtists &&
30+
if (searchForArtists) {
3131
json.artists.map((artist) => {
3232
results.push({
3333
id: `Artist:${artist.slug}`,
@@ -41,6 +41,7 @@ export default (type) => (args, callback) => {
4141
// albumArtURI: ''
4242
});
4343
});
44+
}
4445

4546
// searchForSongs && json.songs.map(artist => {
4647
// results.push({

0 commit comments

Comments
 (0)