Add explicit HEAD handler for track stream that doesnt scrobble

This commit is contained in:
simojenki
2021-06-19 12:26:49 +10:00
parent 79c8c99c1b
commit e6378de25d
2 changed files with 430 additions and 287 deletions

View File

@@ -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;