fix(users/Profpatsch/lyric/ext): set user agent in all fetches

Change-Id: I8de1ef76c4d5789536e528f49226e58ee90b8749
Reviewed-on: https://cl.tvl.fyi/c/depot/+/12575
Reviewed-by: Profpatsch <mail@profpatsch.de>
Tested-by: BuildkiteCI
This commit is contained in:
Profpatsch 2024-10-05 14:19:22 +02:00
parent c925902015
commit 05c7230127

View file

@ -1,5 +1,8 @@
import * as crypto from 'crypto'; import * as crypto from 'crypto';
const USER_AGENT =
'lyric tool (source: https://code.tvl.fyi/tree/users/Profpatsch/lyric, contact: https://mastodon.xyz/@Profpatsch)';
// Helper function to convert a hex string to a Buffer // Helper function to convert a hex string to a Buffer
function hexToBytes(hex: string): Buffer { function hexToBytes(hex: string): Buffer {
return Buffer.from(hex, 'hex'); return Buffer.from(hex, 'hex');
@ -48,8 +51,8 @@ async function getUploadNonce() {
method: 'POST', method: 'POST',
headers: { headers: {
'Content-Type': 'application/json', 'Content-Type': 'application/json',
'User-Agent': 'lyric tool (https://code.tvl.fyi/tree/users/Profpatsch/lyric)', 'User-Agent': USER_AGENT,
'Lrclib-Client': 'lyric tool (https://code.tvl.fyi/tree/users/Profpatsch/lyric)', 'Lrclib-Client': USER_AGENT,
}, },
}); });
@ -96,8 +99,8 @@ export async function publishLyrics(
method: 'POST', method: 'POST',
headers: { headers: {
'Content-Type': 'application/json', 'Content-Type': 'application/json',
'User-Agent': 'lyric tool (https://code.tvl.fyi/tree/users/Profpatsch/lyric)', 'User-Agent': USER_AGENT,
'Lrclib-Client': 'lyric tool (https://code.tvl.fyi/tree/users/Profpatsch/lyric)', 'Lrclib-Client': USER_AGENT,
'X-Publish-Token': publishToken, 'X-Publish-Token': publishToken,
}, },
body: JSON.stringify(requestBody), body: JSON.stringify(requestBody),