Compare commits
42 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0ab6194b43 | ||
|
|
46f359bb1e | ||
|
|
9b852dc40c | ||
|
|
a6d837f953 | ||
|
|
921882054d | ||
|
|
cdd2fcb59e | ||
|
|
8daeed6b5f | ||
|
|
6d05233a6e | ||
|
|
3dd61ab4e8 | ||
|
|
b7ea7bc552 | ||
|
|
d23c89c3c9 | ||
|
|
fd766a822c | ||
|
|
bf580c8a84 | ||
|
|
12fc98c925 | ||
|
|
3b7ef0f3ee | ||
|
|
ada7268062 | ||
|
|
b55e1dd0a6 | ||
|
|
49f04ef82f | ||
|
|
862401fa9b | ||
|
|
20e94a7e0e | ||
|
|
7f2b8ce5aa | ||
|
|
14df9ae2cd | ||
|
|
36f2535cf8 | ||
|
|
3dfa3007bf | ||
|
|
e80ff5fece | ||
|
|
694d88bb72 | ||
|
|
9569477a26 | ||
|
|
6574f8f672 | ||
|
|
ea6605f9dc | ||
|
|
953afcbc84 | ||
|
|
1d4ade717a | ||
|
|
25ff0b9903 | ||
|
|
2f8f3ea017 | ||
|
|
c3f0fd84ac | ||
|
|
64eb6fbf4e | ||
|
|
50c951e0d3 | ||
|
|
6086c6dbcc | ||
|
|
30b5c74c06 | ||
|
|
a835f220e2 | ||
|
|
a35a3e7ecb | ||
|
|
9b61909eab | ||
|
|
a3689f4cd2 |
12
dist/fastify.d.ts
vendored
12
dist/fastify.d.ts
vendored
@@ -1,15 +1,21 @@
|
||||
import { AxiosInstance } from "axios";
|
||||
import type { AxiosInstance } from "axios";
|
||||
export type ServiceResult<T = unknown> = {
|
||||
result: T;
|
||||
successful: boolean;
|
||||
};
|
||||
export declare abstract class Client {
|
||||
export declare class API_Error {
|
||||
error: string;
|
||||
constructor(error: string);
|
||||
}
|
||||
export declare abstract class BaseClient {
|
||||
private axiosInstance;
|
||||
constructor(axiosInstance: AxiosInstance);
|
||||
getAxios(): AxiosInstance;
|
||||
}
|
||||
export declare abstract class Service<T> {
|
||||
export declare abstract class BaseService<T> {
|
||||
private client;
|
||||
constructor(client: T);
|
||||
getClient(): T;
|
||||
getSuccessfulResult<R = unknown>(result: R): ServiceResult<R>;
|
||||
getErrorResult(error: string): ServiceResult<string>;
|
||||
}
|
||||
|
||||
2
dist/fastify.d.ts.map
vendored
2
dist/fastify.d.ts.map
vendored
@@ -1 +1 @@
|
||||
{"version":3,"file":"fastify.d.ts","sourceRoot":"","sources":["../src/fastify.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAEtC,MAAM,MAAM,aAAa,CAAC,CAAC,GAAG,OAAO,IAAI;IACvC,MAAM,EAAE,CAAC,CAAC;IACV,UAAU,EAAE,OAAO,CAAC;CACrB,CAAC;AAEF,8BAAsB,MAAM;IAC1B,OAAO,CAAC,aAAa,CAAgB;gBAEzB,aAAa,EAAE,aAAa;CAGzC;AAED,8BAAsB,OAAO,CAAC,CAAC;IAC7B,OAAO,CAAC,MAAM,CAAI;gBAEN,MAAM,EAAE,CAAC;IAIrB,mBAAmB,CAAC,CAAC,GAAG,OAAO,EAAE,MAAM,EAAE,CAAC,GAAG,aAAa,CAAC,CAAC,CAAC;IAO7D,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,aAAa,CAAC,MAAM,CAAC;CAMrD"}
|
||||
{"version":3,"file":"fastify.d.ts","sourceRoot":"","sources":["../src/fastify.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAE3C,MAAM,MAAM,aAAa,CAAC,CAAC,GAAG,OAAO,IAAI;IACvC,MAAM,EAAE,CAAC,CAAC;IACV,UAAU,EAAE,OAAO,CAAC;CACrB,CAAC;AAEF,qBAAa,SAAS;IACD,KAAK,EAAE,MAAM;gBAAb,KAAK,EAAE,MAAM;CACjC;AAED,8BAAsB,UAAU;IAC9B,OAAO,CAAC,aAAa,CAAgB;gBAEzB,aAAa,EAAE,aAAa;IAIxC,QAAQ,IAAI,aAAa;CAG1B;AAED,8BAAsB,WAAW,CAAC,CAAC;IACjC,OAAO,CAAC,MAAM,CAAI;gBAEN,MAAM,EAAE,CAAC;IAIrB,SAAS,IAAI,CAAC;IAId,mBAAmB,CAAC,CAAC,GAAG,OAAO,EAAE,MAAM,EAAE,CAAC,GAAG,aAAa,CAAC,CAAC,CAAC;IAO7D,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,aAAa,CAAC,MAAM,CAAC;CAMrD"}
|
||||
16
dist/fastify.js
vendored
16
dist/fastify.js
vendored
@@ -1,14 +1,26 @@
|
||||
export class Client {
|
||||
export class API_Error {
|
||||
error;
|
||||
constructor(error) {
|
||||
this.error = error;
|
||||
}
|
||||
}
|
||||
export class BaseClient {
|
||||
axiosInstance;
|
||||
constructor(axiosInstance) {
|
||||
this.axiosInstance = axiosInstance;
|
||||
}
|
||||
getAxios() {
|
||||
return this.axiosInstance;
|
||||
}
|
||||
}
|
||||
export class Service {
|
||||
export class BaseService {
|
||||
client;
|
||||
constructor(client) {
|
||||
this.client = client;
|
||||
}
|
||||
getClient() {
|
||||
return this.client;
|
||||
}
|
||||
getSuccessfulResult(result) {
|
||||
return {
|
||||
result,
|
||||
|
||||
12
dist/homepage.d.ts
vendored
Normal file
12
dist/homepage.d.ts
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
import { type API_HA_DeskPosition } from "./homeassistant";
|
||||
import { type TidalGetCurrent } from "./tidal";
|
||||
export type FullInformation = {
|
||||
ha_desk_position: API_HA_DeskPosition | null;
|
||||
ha_temp: string | null;
|
||||
tidal_current: TidalGetCurrent | null;
|
||||
};
|
||||
export type LastPoll = {
|
||||
time: number | null;
|
||||
result: FullInformation | null;
|
||||
};
|
||||
//# sourceMappingURL=homepage.d.ts.map
|
||||
1
dist/homepage.d.ts.map
vendored
Normal file
1
dist/homepage.d.ts.map
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"homepage.d.ts","sourceRoot":"","sources":["../src/homepage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAC3D,OAAO,EAAE,KAAK,eAAe,EAAE,MAAM,SAAS,CAAC;AAE/C,MAAM,MAAM,eAAe,GAAG;IAC7B,gBAAgB,EAAE,mBAAmB,GAAG,IAAI,CAAC;IAC7C,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,aAAa,EAAE,eAAe,GAAG,IAAI,CAAC;CACtC,CAAC;AAEF,MAAM,MAAM,QAAQ,GAAG;IACtB,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,MAAM,EAAE,eAAe,GAAG,IAAI,CAAC;CAC/B,CAAC"}
|
||||
1
dist/homepage.js
vendored
Normal file
1
dist/homepage.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
export {};
|
||||
11
dist/index.d.ts
vendored
11
dist/index.d.ts
vendored
@@ -1,5 +1,8 @@
|
||||
export * from "./homeassistant";
|
||||
export * as Logger from "./logger";
|
||||
export * from "./tidal";
|
||||
export * as TimeHelper from "./timehelper";
|
||||
export * from "./fastify.js";
|
||||
export * from "./homeassistant.js";
|
||||
export * from "./homepage.js";
|
||||
export * from "./logger.js";
|
||||
export * from "./sse.js";
|
||||
export * from "./tidal.js";
|
||||
export * from "./timehelper.js";
|
||||
//# sourceMappingURL=index.d.ts.map
|
||||
2
dist/index.d.ts.map
vendored
2
dist/index.d.ts.map
vendored
@@ -1 +1 @@
|
||||
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,OAAO,KAAK,MAAM,MAAM,UAAU,CAAC;AACnC,cAAc,SAAS,CAAC;AACxB,OAAO,KAAK,UAAU,MAAM,cAAc,CAAC"}
|
||||
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,oBAAoB,CAAC;AACnC,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC;AAC3B,cAAc,iBAAiB,CAAC"}
|
||||
11
dist/index.js
vendored
11
dist/index.js
vendored
@@ -1,4 +1,7 @@
|
||||
export * from "./homeassistant";
|
||||
export * as Logger from "./logger";
|
||||
export * from "./tidal";
|
||||
export * as TimeHelper from "./timehelper";
|
||||
export * from "./fastify.js";
|
||||
export * from "./homeassistant.js";
|
||||
export * from "./homepage.js";
|
||||
export * from "./logger.js";
|
||||
export * from "./sse.js";
|
||||
export * from "./tidal.js";
|
||||
export * from "./timehelper.js";
|
||||
|
||||
27
dist/sse.d.ts
vendored
Normal file
27
dist/sse.d.ts
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
import { UUID } from "crypto";
|
||||
export type SseClient = {
|
||||
id: UUID;
|
||||
send: (data: SseEvent) => void;
|
||||
};
|
||||
export type SseEvent = {
|
||||
type: string;
|
||||
data?: unknown;
|
||||
message?: string;
|
||||
};
|
||||
export type SseClientChangeEvent = {
|
||||
type: "add" | "remove";
|
||||
clientId: string;
|
||||
clientCount: number;
|
||||
};
|
||||
export type SseClientChangeCallback = (event: SseClientChangeEvent) => void;
|
||||
export declare class SseService {
|
||||
private clients;
|
||||
private clientChangeCallbacks;
|
||||
onClientChange(callback: SseClientChangeCallback): () => void;
|
||||
private emitClientChange;
|
||||
addClient(client: SseClient): void;
|
||||
removeClient(clientId: string): void;
|
||||
notifyClients(event: SseEvent): void;
|
||||
getClientCount(): number;
|
||||
}
|
||||
//# sourceMappingURL=sse.d.ts.map
|
||||
1
dist/sse.d.ts.map
vendored
Normal file
1
dist/sse.d.ts.map
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"sse.d.ts","sourceRoot":"","sources":["../src/sse.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAG9B,MAAM,MAAM,SAAS,GAAG;IACvB,EAAE,EAAE,IAAI,CAAC;IACT,IAAI,EAAE,CAAC,IAAI,EAAE,QAAQ,KAAK,IAAI,CAAC;CAC/B,CAAC;AAEF,MAAM,MAAM,QAAQ,GAAG;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG;IAClC,IAAI,EAAE,KAAK,GAAG,QAAQ,CAAC;IACvB,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,uBAAuB,GAAG,CAAC,KAAK,EAAE,oBAAoB,KAAK,IAAI,CAAC;AAE5E,qBAAa,UAAU;IACtB,OAAO,CAAC,OAAO,CAAqC;IACpD,OAAO,CAAC,qBAAqB,CAAiC;IAE9D,cAAc,CAAC,QAAQ,EAAE,uBAAuB,GAAG,MAAM,IAAI;IAS7D,OAAO,CAAC,gBAAgB;IAMxB,SAAS,CAAC,MAAM,EAAE,SAAS,GAAG,IAAI;IAYlC,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI;IAYpC,aAAa,CAAC,KAAK,EAAE,QAAQ,GAAG,IAAI;IAMpC,cAAc,IAAI,MAAM;CAGxB"}
|
||||
42
dist/sse.js
vendored
Normal file
42
dist/sse.js
vendored
Normal file
@@ -0,0 +1,42 @@
|
||||
import { logInfo } from "./logger.js";
|
||||
export class SseService {
|
||||
clients = new Map();
|
||||
clientChangeCallbacks = [];
|
||||
onClientChange(callback) {
|
||||
this.clientChangeCallbacks.push(callback);
|
||||
return () => {
|
||||
this.clientChangeCallbacks = this.clientChangeCallbacks.filter((cb) => cb !== callback);
|
||||
};
|
||||
}
|
||||
emitClientChange(event) {
|
||||
for (const callback of this.clientChangeCallbacks) {
|
||||
callback(event);
|
||||
}
|
||||
}
|
||||
addClient(client) {
|
||||
this.clients.set(client.id, client);
|
||||
logInfo(`SSE client connected: ${client.id}. Total clients: ${this.clients.size}`);
|
||||
this.emitClientChange({
|
||||
type: "add",
|
||||
clientId: client.id,
|
||||
clientCount: this.clients.size,
|
||||
});
|
||||
}
|
||||
removeClient(clientId) {
|
||||
this.clients.delete(clientId);
|
||||
logInfo(`SSE client disconnected: ${clientId}. Total clients: ${this.clients.size}`);
|
||||
this.emitClientChange({
|
||||
type: "remove",
|
||||
clientId,
|
||||
clientCount: this.clients.size,
|
||||
});
|
||||
}
|
||||
notifyClients(event) {
|
||||
for (const client of this.clients.values()) {
|
||||
client.send(event);
|
||||
}
|
||||
}
|
||||
getClientCount() {
|
||||
return this.clients.size;
|
||||
}
|
||||
}
|
||||
18
dist/tidal.d.ts
vendored
18
dist/tidal.d.ts
vendored
@@ -1,14 +1,26 @@
|
||||
export type TidalSong = {
|
||||
export type TidalGetCurrent = {
|
||||
title: string;
|
||||
artists: string;
|
||||
artistsArray: string[];
|
||||
album: string;
|
||||
playingFrom: string;
|
||||
status: "playing" | "paused";
|
||||
url: string;
|
||||
current: string;
|
||||
currentInSeconds: number;
|
||||
duration: string;
|
||||
};
|
||||
export type TidalVolume = {
|
||||
durationInSeconds: number;
|
||||
image: string;
|
||||
icon: string;
|
||||
localAlbumArt: string;
|
||||
favorite: boolean;
|
||||
trackId: string;
|
||||
volume: number;
|
||||
player: {
|
||||
status: "playing" | "paused";
|
||||
shuffle: boolean;
|
||||
repeat: "all" | "single" | "none";
|
||||
};
|
||||
artist: string;
|
||||
};
|
||||
//# sourceMappingURL=tidal.d.ts.map
|
||||
2
dist/tidal.d.ts.map
vendored
2
dist/tidal.d.ts.map
vendored
@@ -1 +1 @@
|
||||
{"version":3,"file":"tidal.d.ts","sourceRoot":"","sources":["../src/tidal.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,SAAS,GAAG;IACtB,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,SAAS,GAAG,QAAQ,CAAC;IAC7B,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG;IACxB,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC"}
|
||||
{"version":3,"file":"tidal.d.ts","sourceRoot":"","sources":["../src/tidal.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,eAAe,GAAG;IAC7B,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,SAAS,GAAG,QAAQ,CAAC;IAC7B,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE,MAAM,CAAC;IAChB,gBAAgB,EAAE,MAAM,CAAC;IACzB,QAAQ,EAAE,MAAM,CAAC;IACjB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,aAAa,EAAE,MAAM,CAAC;IACtB,QAAQ,EAAE,OAAO,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE;QACP,MAAM,EAAE,SAAS,GAAG,QAAQ,CAAC;QAC7B,OAAO,EAAE,OAAO,CAAC;QACjB,MAAM,EAAE,KAAK,GAAG,QAAQ,GAAG,MAAM,CAAC;KAClC,CAAC;IACF,MAAM,EAAE,MAAM,CAAC;CACf,CAAC"}
|
||||
3
dist/timehelper.d.ts
vendored
3
dist/timehelper.d.ts
vendored
@@ -1,7 +1,8 @@
|
||||
export declare class TimeSpan {
|
||||
private start;
|
||||
private end;
|
||||
constructor(timeSpanStr: string);
|
||||
private timeZone;
|
||||
constructor(timeSpanStr: string, timeZone: string);
|
||||
private parseTime;
|
||||
contains(timestamp?: number): boolean;
|
||||
}
|
||||
|
||||
2
dist/timehelper.d.ts.map
vendored
2
dist/timehelper.d.ts.map
vendored
@@ -1 +1 @@
|
||||
{"version":3,"file":"timehelper.d.ts","sourceRoot":"","sources":["../src/timehelper.ts"],"names":[],"mappings":"AAAA,qBAAa,QAAQ;IACnB,OAAO,CAAC,KAAK,CAAqC;IAClD,OAAO,CAAC,GAAG,CAAqC;gBAEpC,WAAW,EAAE,MAAM;IAM/B,OAAO,CAAC,SAAS;IAKjB,QAAQ,CAAC,SAAS,GAAE,MAAmB,GAAG,OAAO;CAgBlD;AAED,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,CAAC,cAAc,CAAC,EAAE,OAAO,KAAK,MAAM,CAAC;CAClD;AAED,wBAAgB,uBAAuB,CACrC,KAAK,EAAE,MAAM,EACb,GAAG,EAAE,MAAM,GACV,WAAW,CAOb;AAED,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,MAAM,EACZ,cAAc,GAAE,OAAe,GAC9B,MAAM,CAmBR"}
|
||||
{"version":3,"file":"timehelper.d.ts","sourceRoot":"","sources":["../src/timehelper.ts"],"names":[],"mappings":"AAAA,qBAAa,QAAQ;IACnB,OAAO,CAAC,KAAK,CAAqC;IAClD,OAAO,CAAC,GAAG,CAAqC;IAChD,OAAO,CAAC,QAAQ,CAAC;gBAEL,WAAW,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM;IAOjD,OAAO,CAAC,SAAS;IAKjB,QAAQ,CAAC,SAAS,GAAE,MAAmB,GAAG,OAAO;CAqBlD;AAED,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,CAAC,cAAc,CAAC,EAAE,OAAO,KAAK,MAAM,CAAC;CAClD;AAED,wBAAgB,uBAAuB,CACrC,KAAK,EAAE,MAAM,EACb,GAAG,EAAE,MAAM,GACV,WAAW,CAOb;AAED,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,MAAM,EACZ,cAAc,GAAE,OAAe,GAC9B,MAAM,CAmBR"}
|
||||
13
dist/timehelper.js
vendored
13
dist/timehelper.js
vendored
@@ -1,10 +1,12 @@
|
||||
export class TimeSpan {
|
||||
start;
|
||||
end;
|
||||
constructor(timeSpanStr) {
|
||||
timeZone;
|
||||
constructor(timeSpanStr, timeZone) {
|
||||
const [startStr, endStr] = timeSpanStr.split("-");
|
||||
this.start = this.parseTime(startStr);
|
||||
this.end = this.parseTime(endStr);
|
||||
this.timeZone = timeZone;
|
||||
}
|
||||
parseTime(timeStr) {
|
||||
const [hours, minutes] = timeStr.split(":").map(Number);
|
||||
@@ -12,8 +14,13 @@ export class TimeSpan {
|
||||
}
|
||||
contains(timestamp = Date.now()) {
|
||||
const date = new Date(timestamp);
|
||||
const hours = date.getHours();
|
||||
const minutes = date.getMinutes();
|
||||
const berlinTimeStr = date.toLocaleString("de-DE", {
|
||||
timeZone: this.timeZone, // "Europe/Berlin"
|
||||
hour12: false,
|
||||
hour: "2-digit",
|
||||
minute: "2-digit",
|
||||
});
|
||||
const [hours, minutes] = berlinTimeStr.split(":").map(Number);
|
||||
const currentMinutes = hours * 60 + minutes;
|
||||
const startMinutes = this.start.hours * 60 + this.start.minutes;
|
||||
const endMinutes = this.end.hours * 60 + this.end.minutes;
|
||||
|
||||
4
package-lock.json
generated
4
package-lock.json
generated
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "@dpu/shared",
|
||||
"version": "1.1.3",
|
||||
"version": "1.6.1",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "@dpu/shared",
|
||||
"version": "1.1.3",
|
||||
"version": "1.6.1",
|
||||
"dependencies": {
|
||||
"axios": "^1.7.9",
|
||||
"chalk": "^5.6.2",
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
{
|
||||
"name": "@dpu/shared",
|
||||
"version": "1.1.3",
|
||||
"version": "1.6.1",
|
||||
"description": "",
|
||||
"main": "dist/index.js",
|
||||
"types": "dist/index.d.ts",
|
||||
"type": "module",
|
||||
"files": [
|
||||
"dist"
|
||||
],
|
||||
|
||||
@@ -1,25 +1,37 @@
|
||||
import { AxiosInstance } from "axios";
|
||||
import type { AxiosInstance } from "axios";
|
||||
|
||||
export type ServiceResult<T = unknown> = {
|
||||
result: T;
|
||||
successful: boolean;
|
||||
};
|
||||
|
||||
export abstract class Client {
|
||||
export class API_Error {
|
||||
constructor(public error: string) {}
|
||||
}
|
||||
|
||||
export abstract class BaseClient {
|
||||
private axiosInstance: AxiosInstance;
|
||||
|
||||
constructor(axiosInstance: AxiosInstance) {
|
||||
this.axiosInstance = axiosInstance;
|
||||
}
|
||||
|
||||
getAxios(): AxiosInstance {
|
||||
return this.axiosInstance;
|
||||
}
|
||||
}
|
||||
|
||||
export abstract class Service<T> {
|
||||
export abstract class BaseService<T> {
|
||||
private client: T;
|
||||
|
||||
constructor(client: T) {
|
||||
this.client = client;
|
||||
}
|
||||
|
||||
getClient(): T {
|
||||
return this.client;
|
||||
}
|
||||
|
||||
getSuccessfulResult<R = unknown>(result: R): ServiceResult<R> {
|
||||
return {
|
||||
result,
|
||||
|
||||
13
src/homepage.ts
Normal file
13
src/homepage.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import { type API_HA_DeskPosition } from "./homeassistant";
|
||||
import { type TidalGetCurrent } from "./tidal";
|
||||
|
||||
export type FullInformation = {
|
||||
ha_desk_position: API_HA_DeskPosition | null;
|
||||
ha_temp: string | null;
|
||||
tidal_current: TidalGetCurrent | null;
|
||||
};
|
||||
|
||||
export type LastPoll = {
|
||||
time: number | null;
|
||||
result: FullInformation | null;
|
||||
};
|
||||
12
src/index.ts
12
src/index.ts
@@ -1,4 +1,8 @@
|
||||
export * from "./homeassistant";
|
||||
export * as Logger from "./logger";
|
||||
export * from "./tidal";
|
||||
export * as TimeHelper from "./timehelper";
|
||||
export * from "./fastify.js";
|
||||
export * from "./homeassistant.js";
|
||||
export * from "./homepage.js";
|
||||
export * from "./logger.js";
|
||||
export * from "./sse.js";
|
||||
export * from "./tidal.js";
|
||||
export * from "./timehelper.js";
|
||||
|
||||
|
||||
75
src/sse.ts
Normal file
75
src/sse.ts
Normal file
@@ -0,0 +1,75 @@
|
||||
import { UUID } from "crypto";
|
||||
import { logInfo } from "./logger.js";
|
||||
|
||||
export type SseClient = {
|
||||
id: UUID;
|
||||
send: (data: SseEvent) => void;
|
||||
};
|
||||
|
||||
export type SseEvent = {
|
||||
type: string;
|
||||
data?: unknown;
|
||||
message?: string;
|
||||
};
|
||||
|
||||
export type SseClientChangeEvent = {
|
||||
type: "add" | "remove";
|
||||
clientId: string;
|
||||
clientCount: number;
|
||||
};
|
||||
|
||||
export type SseClientChangeCallback = (event: SseClientChangeEvent) => void;
|
||||
|
||||
export class SseService {
|
||||
private clients: Map<string, SseClient> = new Map();
|
||||
private clientChangeCallbacks: SseClientChangeCallback[] = [];
|
||||
|
||||
onClientChange(callback: SseClientChangeCallback): () => void {
|
||||
this.clientChangeCallbacks.push(callback);
|
||||
return () => {
|
||||
this.clientChangeCallbacks = this.clientChangeCallbacks.filter(
|
||||
(cb) => cb !== callback,
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
private emitClientChange(event: SseClientChangeEvent): void {
|
||||
for (const callback of this.clientChangeCallbacks) {
|
||||
callback(event);
|
||||
}
|
||||
}
|
||||
|
||||
addClient(client: SseClient): void {
|
||||
this.clients.set(client.id, client);
|
||||
logInfo(
|
||||
`SSE client connected: ${client.id}. Total clients: ${this.clients.size}`,
|
||||
);
|
||||
this.emitClientChange({
|
||||
type: "add",
|
||||
clientId: client.id,
|
||||
clientCount: this.clients.size,
|
||||
});
|
||||
}
|
||||
|
||||
removeClient(clientId: string): void {
|
||||
this.clients.delete(clientId);
|
||||
logInfo(
|
||||
`SSE client disconnected: ${clientId}. Total clients: ${this.clients.size}`,
|
||||
);
|
||||
this.emitClientChange({
|
||||
type: "remove",
|
||||
clientId,
|
||||
clientCount: this.clients.size,
|
||||
});
|
||||
}
|
||||
|
||||
notifyClients(event: SseEvent): void {
|
||||
for (const client of this.clients.values()) {
|
||||
client.send(event);
|
||||
}
|
||||
}
|
||||
|
||||
getClientCount(): number {
|
||||
return this.clients.size;
|
||||
}
|
||||
}
|
||||
19
src/tidal.ts
19
src/tidal.ts
@@ -1,14 +1,25 @@
|
||||
export type TidalSong = {
|
||||
export type TidalGetCurrent = {
|
||||
title: string;
|
||||
artists: string;
|
||||
artistsArray: string[];
|
||||
album: string;
|
||||
playingFrom: string;
|
||||
status: "playing" | "paused";
|
||||
url: string;
|
||||
current: string;
|
||||
currentInSeconds: number;
|
||||
duration: string;
|
||||
};
|
||||
|
||||
export type TidalVolume = {
|
||||
durationInSeconds: number;
|
||||
image: string;
|
||||
icon: string;
|
||||
localAlbumArt: string;
|
||||
favorite: boolean;
|
||||
trackId: string;
|
||||
volume: number;
|
||||
player: {
|
||||
status: "playing" | "paused";
|
||||
shuffle: boolean;
|
||||
repeat: "all" | "single" | "none";
|
||||
};
|
||||
artist: string;
|
||||
};
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
export class TimeSpan {
|
||||
private start: { hours: number; minutes: number };
|
||||
private end: { hours: number; minutes: number };
|
||||
private timeZone;
|
||||
|
||||
constructor(timeSpanStr: string) {
|
||||
constructor(timeSpanStr: string, timeZone: string) {
|
||||
const [startStr, endStr] = timeSpanStr.split("-");
|
||||
this.start = this.parseTime(startStr);
|
||||
this.end = this.parseTime(endStr);
|
||||
this.timeZone = timeZone;
|
||||
}
|
||||
|
||||
private parseTime(timeStr: string) {
|
||||
@@ -16,10 +18,15 @@ export class TimeSpan {
|
||||
contains(timestamp: number = Date.now()): boolean {
|
||||
const date = new Date(timestamp);
|
||||
|
||||
const hours = date.getHours();
|
||||
const minutes = date.getMinutes();
|
||||
const currentMinutes = hours * 60 + minutes;
|
||||
const berlinTimeStr = date.toLocaleString("de-DE", {
|
||||
timeZone: this.timeZone, // "Europe/Berlin"
|
||||
hour12: false,
|
||||
hour: "2-digit",
|
||||
minute: "2-digit",
|
||||
});
|
||||
|
||||
const [hours, minutes] = berlinTimeStr.split(":").map(Number);
|
||||
const currentMinutes = hours * 60 + minutes;
|
||||
const startMinutes = this.start.hours * 60 + this.start.minutes;
|
||||
const endMinutes = this.end.hours * 60 + this.end.minutes;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user