rework to work with non forked version

This commit is contained in:
Darius
2026-02-03 21:55:10 +01:00
parent fd27cac031
commit 6859ba27b9
3 changed files with 301 additions and 696 deletions

793
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -13,9 +13,9 @@ export class TidalClient extends BaseClient {
}
}
async post<T>(endpoint: string, data: unknown): Promise<T> {
async put<T>(endpoint: string, data: unknown): Promise<T> {
try {
const response = await this.getAxios().post<T>(`/${endpoint}`, data);
const response = await this.getAxios().put<T>(`/${endpoint}`, data);
return response.data;
} catch (error) {
printNetworkError(error);

View File

@@ -1,8 +1,8 @@
import {
BaseService,
type ServiceResult,
type TidalSong,
type TidalVolume,
type TidalGetCurrent,
type TidalPutVolume,
} from "@dpu/shared";
import { logWarning } from "@dpu/shared/dist/logger.js";
import type { TidalClient } from "./client.js";
@@ -11,7 +11,7 @@ export class TidalService extends BaseService<TidalClient> {
async getSongFormatted(): Promise<ServiceResult<string>> {
const req = await this.getSong();
if (req.successful) {
const song = req.result as TidalSong;
const song = req.result as TidalGetCurrent;
const status = song.status === "playing" ? "▶️" : "⏸️";
return this.getSuccessfulResult(
`listening to ${song.title} by ${song.artists}. ${status} ${song.current}/${song.duration}. link: ${song.url}`,
@@ -21,9 +21,9 @@ export class TidalService extends BaseService<TidalClient> {
}
}
async getSong(): Promise<ServiceResult<TidalSong | string>> {
async getSong(): Promise<ServiceResult<TidalGetCurrent | string>> {
try {
const response = await this.getClient().get<TidalSong>("current");
const response = await this.getClient().get<TidalGetCurrent>("current");
return this.getSuccessfulResult(response);
} catch {
@@ -33,11 +33,13 @@ export class TidalService extends BaseService<TidalClient> {
}
}
async getVolume(): Promise<ServiceResult<TidalVolume | string>> {
async getVolume(): Promise<ServiceResult<TidalPutVolume | string>> {
try {
const response = await this.getClient().get<TidalVolume>("volume");
const response = await this.getClient().get<TidalGetCurrent>("current");
return this.getSuccessfulResult(response);
return this.getSuccessfulResult({
volume: response.volume,
});
} catch {
const error_message = "error getting volume from tidal";
logWarning(error_message);
@@ -51,14 +53,14 @@ export class TidalService extends BaseService<TidalClient> {
async setVolume(
argument: string,
): Promise<ServiceResult<TidalVolume | string>> {
const value = parseInt(argument, 10);
): Promise<ServiceResult<TidalPutVolume | string>> {
const value = this.percentageToDecimal(argument);
// relative
const adjustMatch = argument.match(/^([+-])(\d+)$/);
const adjustMatch = argument.match(/^([+-])/);
if (adjustMatch) {
const req = await this.getVolume();
if (req.successful) {
const volume = req.result as TidalVolume;
const volume = req.result as TidalPutVolume;
const wantedVolume = volume.volume + value;
const clampWantedVolume = this.clamp(wantedVolume);
return await this.setVolumeToTidal(clampWantedVolume);
@@ -66,7 +68,7 @@ export class TidalService extends BaseService<TidalClient> {
}
// absolute
const setMatch = argument.match(/^(\d+)$/);
const setMatch = argument.match(/^(\d+)/);
if (setMatch) {
const clampValue = this.clamp(value);
return await this.setVolumeToTidal(clampValue);
@@ -79,11 +81,12 @@ export class TidalService extends BaseService<TidalClient> {
async setVolumeToTidal(
volume: number,
): Promise<ServiceResult<TidalVolume | string>> {
): Promise<ServiceResult<TidalPutVolume | string>> {
try {
const response = await this.getClient().post<TidalVolume>("volume", {
volume,
});
const response = await this.getClient().put<TidalPutVolume>(
`player/volume?volume=${volume}`,
{},
);
return this.getSuccessfulResult(response);
} catch {
@@ -92,4 +95,13 @@ export class TidalService extends BaseService<TidalClient> {
return this.getErrorResult(error_message);
}
}
decimalToPercentage(decimal: number): number {
return decimal * 100;
}
percentageToDecimal(percentage: string): number {
const num = parseFloat(percentage);
return num / 100;
}
}