diff options
author | kaotisk <kaotisk@arching-kaos.org> | 2024-10-14 04:44:28 +0300 |
---|---|---|
committer | kaotisk <kaotisk@arching-kaos.org> | 2024-10-14 04:44:28 +0300 |
commit | 39c632eda398b5294186b5a3b1d71e9e575f4485 (patch) | |
tree | 5428a315ad8d34f03be6b56c5e2734238fab27a7 /server/index.js | |
parent | 866eb9c6f8b145b065e47a8e47e9a79df386f5a4 (diff) | |
download | arching-kaos-radio-39c632eda398b5294186b5a3b1d71e9e575f4485.tar.gz arching-kaos-radio-39c632eda398b5294186b5a3b1d71e9e575f4485.tar.bz2 arching-kaos-radio-39c632eda398b5294186b5a3b1d71e9e575f4485.zip |
Clean up and refactoring
Diffstat (limited to 'server/index.js')
-rwxr-xr-x | server/index.js | 40 |
1 files changed, 23 insertions, 17 deletions
diff --git a/server/index.js b/server/index.js index 589d7db..64b4138 100755 --- a/server/index.js +++ b/server/index.js @@ -1,15 +1,6 @@ const http = require("node:http"); const fs = require("node:fs"); -// const welcomeMessage = require("./routes/default/index.js"); -// const getNodeInfo = require('./routes/getNodeInfo/index.js'); -// const getPeers = require('./routes/getPeers/index.js'); -// const getZblock = require('./routes/getZblock/index.js'); -// const getZlatest = require('./routes/getZLatest/index.js'); -// const getSblock = require('./routes/getSBlock/index.js'); -// const getSlatest = require('./routes/getSLatest/index.js'); - -// const akLogMessage = require('./lib/akLogMessage'); function akLogMessage(type, message) { console.log(type+": "+message); @@ -36,12 +27,17 @@ function respondError(res, errorMessage) function respondJSON(res, hash) { test = /[0-9a-f]{128}/ - if (test.test(hash)) + if(test.test(hash)) { - res.writeHead(200, { 'Content-Type': 'application/json'}); - res.end(JSON.stringify(JSON.parse(fs.readFileSync('../hashes/' + hash)))); - } else { - respondError(res, 'Not hash'); + var filename = '../hashes/' + hash; + var stat = fs.statSync(filename); + res.writeHead(200, { 'Content-Type': 'application/json', 'Content-Length': stat.size}); + var readStream = fs.createReadStream(filename); + readStream.pipe(res); + } + else + { + respondError(res, 'Not found'); } } @@ -72,10 +68,20 @@ function applicationRoutes(req, res, args) // Audio returns function respondOGG(res, hash) { - res.writeHead(200, { 'Content-Type': 'audio/ogg'}); test = /[0-9a-f]{128}/ - console.log(test.test(hash)) - res.end(fs.readFileSync('../hashes/' + hash)); + if(test.test(hash)) + { + var filename = '../hashes/' + hash; + var stat = fs.statSync(filename); + res.writeHead(200, { 'Content-Type': 'audio/ogg', 'Content-Length': stat.size}); + var readStream = fs.createReadStream(filename); + readStream.pipe(res); + } + else + { + respondError(res, 'Not found'); + } + } function audioRoutes(req, res, args) |