mirror of
https://github.com/wkulhanek/bonob.git
synced 2025-12-21 17:33:29 +01:00
Add explicit HEAD handler for track stream that doesnt scrobble
This commit is contained in:
@@ -26,7 +26,7 @@ function server(
|
||||
musicService: MusicService,
|
||||
linkCodes: LinkCodes = new InMemoryLinkCodes(),
|
||||
accessTokens: AccessTokens = new AccessTokenPerAuthToken(),
|
||||
clock: Clock = SystemClock
|
||||
clock: Clock = SystemClock
|
||||
): Express {
|
||||
const app = express();
|
||||
|
||||
@@ -139,6 +139,29 @@ function server(
|
||||
</Presentation>`);
|
||||
});
|
||||
|
||||
app.head("/stream/track/:id", async (req, res) => {
|
||||
const id = req.params["id"]!;
|
||||
const accessToken = req.headers[BONOB_ACCESS_TOKEN_HEADER] as string;
|
||||
const authToken = accessTokens.authTokenFor(accessToken);
|
||||
if (!authToken) {
|
||||
return res.status(401).send();
|
||||
} else {
|
||||
return musicService
|
||||
.login(authToken)
|
||||
.then((it) =>
|
||||
it.stream({ trackId: id, range: req.headers["range"] || undefined })
|
||||
)
|
||||
.then((trackStream) => {
|
||||
res.status(trackStream.status);
|
||||
Object.entries(trackStream.headers)
|
||||
.filter(([_, v]) => v !== undefined)
|
||||
.forEach(([header, value]) => res.setHeader(header, value));
|
||||
|
||||
res.send();
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
app.get("/stream/track/:id", async (req, res) => {
|
||||
const id = req.params["id"]!;
|
||||
const accessToken = req.headers[BONOB_ACCESS_TOKEN_HEADER] as string;
|
||||
|
||||
Reference in New Issue
Block a user