Skip to content

Commit bc44dea

Browse files
committed
prepare local mode #62
1 parent 140bc55 commit bc44dea

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

runtime.js

+13-1
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,19 @@ const AssistServer = context => {
335335
.then(body => body.data[0].url ? body.data[0].url : Promise.reject(new Error('empty')))
336336
.then(link => runtime.preferenceReader.get('CDN.redirect') ? link.replace(/(m\d+?)(?!c)\.music\.126\.net/, '$1c.music.126.net') : link)
337337
.then(link => (res.writeHead(302, {location: url.pathname + '?' + queryify({url: link})}), res.end()))
338-
.catch(error => ['empty'].includes(error.message) ? (res.writeHead(404, {'content-type': 'audio/mpeg'}), res.end()) : error)
338+
.catch(error => ['empty'].includes(error.message) ? (res.writeHead(404, {'content-type': 'audio/*'}), res.end()) : error)
339+
}
340+
else if (url.pathname === '/song/file' && query.path) {
341+
let file = decodeURIComponent(urlParse(query.path).pathname), meta = {}
342+
file = process.platform === 'win32' ? file.replace(/^\//, '') : file
343+
try {meta = fs.statSync(file)}
344+
catch(error) {return (res.writeHead(404, {'content-type': 'audio/*'}), res.end())}
345+
let [start, end] = (headers['range'] || '').split('-')
346+
start = parseInt(start) || 0
347+
end = parseInt(end) || Infinity
348+
const bytes = `bytes ${start}-${end === Infinity ? meta.size - 1 : end}/${meta.size}`
349+
res.writeHead(headers['range'] ? 206 : 200, {'content-type': 'audio/*', 'content-range': headers['range'] ? bytes : null})
350+
fs.createReadStream(file, {start, end}).pipe(res)
339351
}
340352
else {
341353
res.socket.destroy()

0 commit comments

Comments
 (0)