mirror of
https://github.com/eliasstepanik/strudel-docker.git
synced 2026-01-23 19:48:31 +00:00
Merge pull request #1288 from tidalcycles/sampler-improvements
@strudel/sampler improvements
This commit is contained in:
commit
fcf6450ff0
@ -1,7 +1,7 @@
|
|||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
|
|
||||||
import cowsay from 'cowsay';
|
import cowsay from 'cowsay';
|
||||||
import { createReadStream } from 'fs';
|
import { createReadStream, existsSync } from 'fs';
|
||||||
import { readdir } from 'fs/promises';
|
import { readdir } from 'fs/promises';
|
||||||
import http from 'http';
|
import http from 'http';
|
||||||
import { join, sep } from 'path';
|
import { join, sep } from 'path';
|
||||||
@ -70,12 +70,15 @@ const server = http.createServer(async (req, res) => {
|
|||||||
return res.end(JSON.stringify(banks));
|
return res.end(JSON.stringify(banks));
|
||||||
}
|
}
|
||||||
let subpath = decodeURIComponent(req.url);
|
let subpath = decodeURIComponent(req.url);
|
||||||
if (!files.includes(subpath)) {
|
const filePath = join(directory, subpath.split('/').join(sep));
|
||||||
|
|
||||||
|
//console.log('GET:', filePath);
|
||||||
|
const isFound = existsSync(filePath);
|
||||||
|
if (!isFound) {
|
||||||
res.statusCode = 404;
|
res.statusCode = 404;
|
||||||
res.end('File not found');
|
res.end('File not found');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const filePath = join(directory, subpath.split('/').join(sep));
|
|
||||||
const readStream = createReadStream(filePath);
|
const readStream = createReadStream(filePath);
|
||||||
readStream.on('error', (err) => {
|
readStream.on('error', (err) => {
|
||||||
res.statusCode = 500;
|
res.statusCode = 500;
|
||||||
@ -99,12 +102,6 @@ Object.keys(networkInterfaces).forEach((key) => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!IP) {
|
|
||||||
console.error("Unable to determine server's IP address.");
|
|
||||||
// eslint-disable-next-line
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
server.listen(PORT, IP_ADDRESS, () => {
|
server.listen(PORT, IP_ADDRESS, () => {
|
||||||
console.log(`@strudel/sampler is now serving audio files from:
|
console.log(`@strudel/sampler is now serving audio files from:
|
||||||
${directory}
|
${directory}
|
||||||
@ -113,6 +110,6 @@ To use them in the Strudel REPL, run:
|
|||||||
samples('http://localhost:${PORT}')
|
samples('http://localhost:${PORT}')
|
||||||
|
|
||||||
Or on a machine in the same network:
|
Or on a machine in the same network:
|
||||||
samples('http://${IP}:${PORT}')
|
${IP ? `samples('http://${IP}:${PORT}')` : `Unable to determine server's IP address.`}
|
||||||
`);
|
`);
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user