hoffmation-base 0.1.1 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.js +27 -27
- package/.github/workflows/npm-publish.yml +50 -0
- package/.prettierrc.js +9 -9
- package/LICENSE +21 -21
- package/index.js +1 -1
- package/models/connectionCallbacks.ts +13 -13
- package/models/daytime.ts +3 -3
- package/models/deviceConfig.ts +8 -8
- package/models/dimmerSettings.ts +5 -5
- package/models/iTemperaturDataPoint.ts +9 -9
- package/models/lampSettings.ts +5 -5
- package/models/ledSettings.ts +19 -19
- package/models/logLevel.ts +9 -9
- package/models/persistence/BasicRoomInfo.ts +3 -3
- package/models/persistence/DailyMovementCount.ts +3 -3
- package/models/persistence/RoomDetailInfo.ts +4 -4
- package/models/persistence/temperaturDataPoint.ts +12 -12
- package/models/persistence/todaysCount.ts +3 -3
- package/models/rooms/RoomBase.ts +357 -357
- package/models/rooms/RoomSettings/RoomSettings.ts +159 -159
- package/models/rooms/RoomSettings/hmIPRoomSettings.ts +53 -53
- package/models/rooms/RoomSettings/iRoomDefaultSettings.ts +17 -17
- package/models/rooms/RoomSettings/readme.md +17 -17
- package/models/rooms/RoomSettings/zigbeeRoomSettings.ts +51 -51
- package/models/rooms/iRoomImportEnforcer.ts +3 -3
- package/models/rooms/readme.md +11 -11
- package/models/temperaturSettings.ts +22 -22
- package/models/timeCallback.ts +90 -90
- package/package.json +1 -1
- package/server/config/config-readme.md +19 -19
- package/server/config/iConfig.ts +53 -53
- package/server/config/private/mainConfig.json +64 -64
- package/server/devices/DeviceInfo.ts +66 -66
- package/server/devices/Griffe.ts +31 -31
- package/server/devices/Heizgruppen.ts +91 -91
- package/server/devices/Rollos.ts +48 -48
- package/server/devices/deviceUpdater.ts +72 -72
- package/server/devices/devices.ts +189 -189
- package/server/devices/groups/fensterGroup.ts +175 -175
- package/server/devices/groups/heatGroup.ts +32 -32
- package/server/devices/groups/lampenGroup.ts +88 -88
- package/server/devices/groups/praesenzGroup.ts +182 -182
- package/server/devices/groups/smokeGroup.ts +16 -16
- package/server/devices/groups/sonosGroup.ts +33 -33
- package/server/devices/groups/tasterGroup.ts +48 -48
- package/server/devices/groups/waterGroup.ts +16 -16
- package/server/devices/hmIPDevices/Fenster.ts +114 -114
- package/server/devices/hmIPDevices/FensterPosition.ts +5 -5
- package/server/devices/hmIPDevices/TuerPosition.ts +4 -4
- package/server/devices/hmIPDevices/hmIpBewegung.ts +126 -126
- package/server/devices/hmIPDevices/hmIpDevice.ts +90 -90
- package/server/devices/hmIPDevices/hmIpDeviceType.ts +14 -14
- package/server/devices/hmIPDevices/hmIpGriff.ts +143 -143
- package/server/devices/hmIPDevices/hmIpHeizgruppe.ts +172 -172
- package/server/devices/hmIPDevices/hmIpHeizung.ts +69 -69
- package/server/devices/hmIPDevices/hmIpLampe.ts +119 -119
- package/server/devices/hmIPDevices/hmIpPraezenz.ts +99 -99
- package/server/devices/hmIPDevices/hmIpRoll.ts +133 -133
- package/server/devices/hmIPDevices/hmIpTaster.ts +82 -73
- package/server/devices/hmIPDevices/hmIpTherm.ts +19 -19
- package/server/devices/hmIPDevices/hmIpTuer.ts +115 -115
- package/server/devices/hmIPDevices/hmIpWippe.ts +55 -55
- package/server/devices/iDeviceUpdater.ts +4 -4
- package/server/devices/iIoBrokerDevice.ts +44 -44
- package/server/devices/iTaster.ts +6 -0
- package/server/devices/{hmIPDevices/hmIpTaste.ts → taste.ts} +84 -72
- package/server/devices/wledDevice.ts +124 -124
- package/server/devices/zigbee/ZigbeeActuator.ts +113 -113
- package/server/devices/zigbee/zigbeeAquaraVibra.ts +171 -171
- package/server/devices/zigbee/zigbeeAquaraWater.ts +94 -94
- package/server/devices/zigbee/zigbeeBlitzShp.ts +77 -77
- package/server/devices/zigbee/zigbeeDevice.ts +115 -115
- package/server/devices/zigbee/zigbeeDeviceType.ts +13 -13
- package/server/devices/zigbee/zigbeeHeimanSmoke.ts +99 -99
- package/server/devices/zigbee/zigbeeIkeaSteckdose.ts +31 -31
- package/server/devices/zigbee/zigbeeIlluActuator.ts +37 -37
- package/server/devices/zigbee/zigbeeIlluDimmer.ts +165 -165
- package/server/devices/zigbee/zigbeeIlluLampe.ts +33 -33
- package/server/devices/zigbee/zigbeeIlluLedRGBCCT.ts +137 -137
- package/server/ioBroker/connection.ts +1655 -1655
- package/server/ioBroker/ioBroker.main.ts +99 -99
- package/server/ioBroker/socketIOAuthInfo.ts +5 -5
- package/server/ioBroker/socketIOConnectOptions.ts +6 -6
- package/server/ioBroker/socketIOLogging.ts +29 -29
- package/server/ioBroker/socketIOVisCommand.ts +11 -11
- package/server/services/HTTPSOptions.ts +14 -14
- package/server/services/Sonos/OwnSonosDevices.ts +9 -0
- package/server/services/Sonos/mp3-server.ts +75 -75
- package/server/services/Sonos/polly-service.ts +100 -100
- package/server/services/Sonos/sonos-service.ts +194 -199
- package/server/services/Telegram/telegram-Commands.ts +237 -215
- package/server/services/Telegram/telegram-service.ts +171 -171
- package/server/services/Telegram/telegramMessageCalback.ts +11 -11
- package/server/services/calendar/muell-tonne.ts +82 -83
- package/server/services/calendar/m/303/274ll-service.ts +147 -146
- package/server/services/dbo/persist.ts +125 -125
- package/server/services/https-service.ts +71 -71
- package/server/services/log-service.ts +69 -69
- package/server/services/news-service.ts +81 -81
- package/server/services/settings-service.ts +15 -15
- package/server/services/time-callback-service.ts +223 -223
- package/server/services/utils/ringstorage.ts +24 -24
- package/server/services/utils/utils.ts +52 -52
- package/server/services/weather/weather-alert.ts +7 -7
- package/server/services/weather/weather-current.ts +26 -26
- package/server/services/weather/weather-daily.ts +22 -22
- package/server/services/weather/weather-feelsLike.ts +6 -6
- package/server/services/weather/weather-hourly.ts +17 -17
- package/server/services/weather/weather-item.ts +6 -6
- package/server/services/weather/weather-minutes.ts +4 -4
- package/server/services/weather/weather-service.ts +277 -277
- package/server/services/weather/weather-temp.ts +8 -8
- package/tsconfig.json +58 -58
|
@@ -1,99 +1,99 @@
|
|
|
1
|
-
import { LogLevel } from '../../models/logLevel';
|
|
2
|
-
import { Devices } from '../devices/devices';
|
|
3
|
-
import { DeviceUpdater } from '../devices/deviceUpdater';
|
|
4
|
-
import { IDeviceUpdater } from '../devices/iDeviceUpdater';
|
|
5
|
-
import { ServerLogService } from '../services/log-service';
|
|
6
|
-
import { TimeCallbackService } from '../services/time-callback-service';
|
|
7
|
-
import { IOBrokerConnection } from './connection';
|
|
8
|
-
import { ConnectionCallbacks } from '../../models/connectionCallbacks';
|
|
9
|
-
import { RoomBase } from '../../models/rooms/RoomBase';
|
|
10
|
-
import { Utils } from '../services/utils/utils';
|
|
11
|
-
import { SettingsService } from
|
|
12
|
-
|
|
13
|
-
export class ioBrokerMain {
|
|
14
|
-
private static roomConstructors: { [roomName: string]: { new (): RoomBase } } = {};
|
|
15
|
-
private servConn: IOBrokerConnection;
|
|
16
|
-
private deviceUpdater: IDeviceUpdater;
|
|
17
|
-
private states: Record<string, ioBroker.State> = {};
|
|
18
|
-
private connectionCallbacks: ConnectionCallbacks;
|
|
19
|
-
|
|
20
|
-
public static addRoomConstructor(roomName: string, constr: { new (): RoomBase }): void {
|
|
21
|
-
if (ioBrokerMain.roomConstructors[roomName] !== undefined) {
|
|
22
|
-
ServerLogService.writeLog(LogLevel.Error, `Konstruktor für Raum mit Namen "${roomName}" bereits hinzugefügt`);
|
|
23
|
-
return;
|
|
24
|
-
}
|
|
25
|
-
ioBrokerMain.roomConstructors[roomName] = constr;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
public constructor(pDeviceUpdater: DeviceUpdater) {
|
|
29
|
-
this.deviceUpdater = pDeviceUpdater;
|
|
30
|
-
this.connectionCallbacks = new ConnectionCallbacks();
|
|
31
|
-
this.initConnCallbacks();
|
|
32
|
-
|
|
33
|
-
this.servConn = new IOBrokerConnection(
|
|
34
|
-
{
|
|
35
|
-
name: '', // optional - default 'vis.0'
|
|
36
|
-
connLink: SettingsService.settings.ioBrokerUrl, // optional URL of the socket.io adapter
|
|
37
|
-
socketSession: '', // optional - used by authentication
|
|
38
|
-
},
|
|
39
|
-
this.connectionCallbacks,
|
|
40
|
-
);
|
|
41
|
-
|
|
42
|
-
Devices.addIoConnection(this.servConn);
|
|
43
|
-
ioBrokerMain.initRooms();
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
private static initRooms(): void {
|
|
47
|
-
for (const key in ioBrokerMain.roomConstructors) {
|
|
48
|
-
new ioBrokerMain.roomConstructors[key]();
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
private initConnCallbacks(): void {
|
|
53
|
-
this.connectionCallbacks.onObjectChange = (pId: string, pObj: ioBroker.Object) => {
|
|
54
|
-
Utils.guardedNewThread(() => {
|
|
55
|
-
this.deviceUpdater.updateObject(pId, pObj);
|
|
56
|
-
}, this);
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
this.connectionCallbacks.onConnChange = (isConnected: boolean) => {
|
|
60
|
-
if (!isConnected) {
|
|
61
|
-
console.log('disconnected');
|
|
62
|
-
return;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
console.log('connected');
|
|
66
|
-
this.servConn.getStates(null, (err, _states) => {
|
|
67
|
-
if (_states === undefined) {
|
|
68
|
-
return;
|
|
69
|
-
}
|
|
70
|
-
ServerLogService.writeLog(LogLevel.Debug, `Im initialen GetStates Callback`);
|
|
71
|
-
|
|
72
|
-
let count = 0;
|
|
73
|
-
for (const id in _states) {
|
|
74
|
-
this.deviceUpdater.updateState(id, _states[id], true);
|
|
75
|
-
count++;
|
|
76
|
-
}
|
|
77
|
-
console.log('Received ' + count + ' states.');
|
|
78
|
-
this.states = _states;
|
|
79
|
-
TimeCallbackService.performCheck();
|
|
80
|
-
TimeCallbackService.performCheck();
|
|
81
|
-
});
|
|
82
|
-
};
|
|
83
|
-
this.connectionCallbacks.onRefresh = () => {
|
|
84
|
-
//
|
|
85
|
-
};
|
|
86
|
-
|
|
87
|
-
this.connectionCallbacks.onUpdate = (id: string, state: ioBroker.State) => {
|
|
88
|
-
Utils.guardedNewThread(() => {
|
|
89
|
-
// console.log('NEW VALUE of ' + id + ': ' + JSON.stringify(state));
|
|
90
|
-
this.states[id] = state;
|
|
91
|
-
this.deviceUpdater.updateState(id, state);
|
|
92
|
-
}, this);
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
this.connectionCallbacks.onError = (err: any) => {
|
|
96
|
-
console.log(`Cannot execute ${err.command} for ${err.arg}, because of insufficient permissions`);
|
|
97
|
-
};
|
|
98
|
-
}
|
|
99
|
-
}
|
|
1
|
+
import { LogLevel } from '../../models/logLevel';
|
|
2
|
+
import { Devices } from '../devices/devices';
|
|
3
|
+
import { DeviceUpdater } from '../devices/deviceUpdater';
|
|
4
|
+
import { IDeviceUpdater } from '../devices/iDeviceUpdater';
|
|
5
|
+
import { ServerLogService } from '../services/log-service';
|
|
6
|
+
import { TimeCallbackService } from '../services/time-callback-service';
|
|
7
|
+
import { IOBrokerConnection } from './connection';
|
|
8
|
+
import { ConnectionCallbacks } from '../../models/connectionCallbacks';
|
|
9
|
+
import { RoomBase } from '../../models/rooms/RoomBase';
|
|
10
|
+
import { Utils } from '../services/utils/utils';
|
|
11
|
+
import { SettingsService } from '../services/settings-service';
|
|
12
|
+
|
|
13
|
+
export class ioBrokerMain {
|
|
14
|
+
private static roomConstructors: { [roomName: string]: { new (): RoomBase } } = {};
|
|
15
|
+
private servConn: IOBrokerConnection;
|
|
16
|
+
private deviceUpdater: IDeviceUpdater;
|
|
17
|
+
private states: Record<string, ioBroker.State> = {};
|
|
18
|
+
private connectionCallbacks: ConnectionCallbacks;
|
|
19
|
+
|
|
20
|
+
public static addRoomConstructor(roomName: string, constr: { new (): RoomBase }): void {
|
|
21
|
+
if (ioBrokerMain.roomConstructors[roomName] !== undefined) {
|
|
22
|
+
ServerLogService.writeLog(LogLevel.Error, `Konstruktor für Raum mit Namen "${roomName}" bereits hinzugefügt`);
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
ioBrokerMain.roomConstructors[roomName] = constr;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
public constructor(pDeviceUpdater: DeviceUpdater) {
|
|
29
|
+
this.deviceUpdater = pDeviceUpdater;
|
|
30
|
+
this.connectionCallbacks = new ConnectionCallbacks();
|
|
31
|
+
this.initConnCallbacks();
|
|
32
|
+
|
|
33
|
+
this.servConn = new IOBrokerConnection(
|
|
34
|
+
{
|
|
35
|
+
name: '', // optional - default 'vis.0'
|
|
36
|
+
connLink: SettingsService.settings.ioBrokerUrl, // optional URL of the socket.io adapter
|
|
37
|
+
socketSession: '', // optional - used by authentication
|
|
38
|
+
},
|
|
39
|
+
this.connectionCallbacks,
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
Devices.addIoConnection(this.servConn);
|
|
43
|
+
ioBrokerMain.initRooms();
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
private static initRooms(): void {
|
|
47
|
+
for (const key in ioBrokerMain.roomConstructors) {
|
|
48
|
+
new ioBrokerMain.roomConstructors[key]();
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
private initConnCallbacks(): void {
|
|
53
|
+
this.connectionCallbacks.onObjectChange = (pId: string, pObj: ioBroker.Object) => {
|
|
54
|
+
Utils.guardedNewThread(() => {
|
|
55
|
+
this.deviceUpdater.updateObject(pId, pObj);
|
|
56
|
+
}, this);
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
this.connectionCallbacks.onConnChange = (isConnected: boolean) => {
|
|
60
|
+
if (!isConnected) {
|
|
61
|
+
console.log('disconnected');
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
console.log('connected');
|
|
66
|
+
this.servConn.getStates(null, (err, _states) => {
|
|
67
|
+
if (_states === undefined) {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
ServerLogService.writeLog(LogLevel.Debug, `Im initialen GetStates Callback`);
|
|
71
|
+
|
|
72
|
+
let count = 0;
|
|
73
|
+
for (const id in _states) {
|
|
74
|
+
this.deviceUpdater.updateState(id, _states[id], true);
|
|
75
|
+
count++;
|
|
76
|
+
}
|
|
77
|
+
console.log('Received ' + count + ' states.');
|
|
78
|
+
this.states = _states;
|
|
79
|
+
TimeCallbackService.performCheck();
|
|
80
|
+
TimeCallbackService.performCheck();
|
|
81
|
+
});
|
|
82
|
+
};
|
|
83
|
+
this.connectionCallbacks.onRefresh = () => {
|
|
84
|
+
//
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
this.connectionCallbacks.onUpdate = (id: string, state: ioBroker.State) => {
|
|
88
|
+
Utils.guardedNewThread(() => {
|
|
89
|
+
// console.log('NEW VALUE of ' + id + ': ' + JSON.stringify(state));
|
|
90
|
+
this.states[id] = state;
|
|
91
|
+
this.deviceUpdater.updateState(id, state);
|
|
92
|
+
}, this);
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
this.connectionCallbacks.onError = (err: any) => {
|
|
96
|
+
console.log(`Cannot execute ${err.command} for ${err.arg}, because of insufficient permissions`);
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export class SocketIOAuthInfo {
|
|
2
|
-
public user: any;
|
|
3
|
-
public hash: any;
|
|
4
|
-
public salt: any;
|
|
5
|
-
}
|
|
1
|
+
export class SocketIOAuthInfo {
|
|
2
|
+
public user: any;
|
|
3
|
+
public hash: any;
|
|
4
|
+
public salt: any;
|
|
5
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export class SocketIOConnectOpts {
|
|
2
|
-
public name?: string;
|
|
3
|
-
public connLink?: any;
|
|
4
|
-
public socketSession?: any;
|
|
5
|
-
public socketForceWebSockets?: boolean;
|
|
6
|
-
}
|
|
1
|
+
export class SocketIOConnectOpts {
|
|
2
|
+
public name?: string;
|
|
3
|
+
public connLink?: any;
|
|
4
|
+
public socketSession?: any;
|
|
5
|
+
public socketForceWebSockets?: boolean;
|
|
6
|
+
}
|
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
export class SocketIoLogging {
|
|
2
|
-
public static LogLevel = 5;
|
|
3
|
-
public static writeLog(pLevel: SocketIoLogLevel, pMessage: string): void {
|
|
4
|
-
if (pLevel > SocketIoLogging.LogLevel) {
|
|
5
|
-
return;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
switch (pLevel) {
|
|
9
|
-
case SocketIoLogLevel.Error:
|
|
10
|
-
console.error(pMessage);
|
|
11
|
-
break;
|
|
12
|
-
case SocketIoLogLevel.Error:
|
|
13
|
-
console.warn(pMessage);
|
|
14
|
-
break;
|
|
15
|
-
default:
|
|
16
|
-
console.log(pMessage);
|
|
17
|
-
break;
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export enum SocketIoLogLevel {
|
|
23
|
-
Error = 1,
|
|
24
|
-
Warn = 2,
|
|
25
|
-
Info = 3,
|
|
26
|
-
Debug = 4,
|
|
27
|
-
Trace = 5,
|
|
28
|
-
DeepTrace = 6,
|
|
29
|
-
}
|
|
1
|
+
export class SocketIoLogging {
|
|
2
|
+
public static LogLevel = 5;
|
|
3
|
+
public static writeLog(pLevel: SocketIoLogLevel, pMessage: string): void {
|
|
4
|
+
if (pLevel > SocketIoLogging.LogLevel) {
|
|
5
|
+
return;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
switch (pLevel) {
|
|
9
|
+
case SocketIoLogLevel.Error:
|
|
10
|
+
console.error(pMessage);
|
|
11
|
+
break;
|
|
12
|
+
case SocketIoLogLevel.Error:
|
|
13
|
+
console.warn(pMessage);
|
|
14
|
+
break;
|
|
15
|
+
default:
|
|
16
|
+
console.log(pMessage);
|
|
17
|
+
break;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export enum SocketIoLogLevel {
|
|
23
|
+
Error = 1,
|
|
24
|
+
Warn = 2,
|
|
25
|
+
Info = 3,
|
|
26
|
+
Debug = 4,
|
|
27
|
+
Trace = 5,
|
|
28
|
+
DeepTrace = 6,
|
|
29
|
+
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
export class SocketIOVisCommand {
|
|
2
|
-
public command: string;
|
|
3
|
-
public data: string;
|
|
4
|
-
public instance: string;
|
|
5
|
-
|
|
6
|
-
constructor(pObject: any) {
|
|
7
|
-
this.command = pObject.command;
|
|
8
|
-
this.data = pObject.data;
|
|
9
|
-
this.instance = pObject.instance;
|
|
10
|
-
}
|
|
11
|
-
}
|
|
1
|
+
export class SocketIOVisCommand {
|
|
2
|
+
public command: string;
|
|
3
|
+
public data: string;
|
|
4
|
+
public instance: string;
|
|
5
|
+
|
|
6
|
+
constructor(pObject: any) {
|
|
7
|
+
this.command = pObject.command;
|
|
8
|
+
this.data = pObject.data;
|
|
9
|
+
this.instance = pObject.instance;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { ServerLogService } from './log-service';
|
|
2
|
-
import { LogLevel } from '../../models/logLevel';
|
|
3
|
-
|
|
4
|
-
export class HTTPSOptions {
|
|
5
|
-
constructor(
|
|
6
|
-
public hostname: string,
|
|
7
|
-
public path: string,
|
|
8
|
-
public headers: { [id: string]: string } = {},
|
|
9
|
-
public method: string = 'POST',
|
|
10
|
-
public port: number = 443,
|
|
11
|
-
) {
|
|
12
|
-
ServerLogService.writeLog(LogLevel.Debug, `${method} Request at '${hostname}' for '${path}'`);
|
|
13
|
-
}
|
|
14
|
-
}
|
|
1
|
+
import { ServerLogService } from './log-service';
|
|
2
|
+
import { LogLevel } from '../../models/logLevel';
|
|
3
|
+
|
|
4
|
+
export class HTTPSOptions {
|
|
5
|
+
constructor(
|
|
6
|
+
public hostname: string,
|
|
7
|
+
public path: string,
|
|
8
|
+
public headers: { [id: string]: string } = {},
|
|
9
|
+
public method: string = 'POST',
|
|
10
|
+
public port: number = 443,
|
|
11
|
+
) {
|
|
12
|
+
ServerLogService.writeLog(LogLevel.Debug, `${method} Request at '${hostname}' for '${path}'`);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -1,75 +1,75 @@
|
|
|
1
|
-
import * as http from 'http';
|
|
2
|
-
import * as url from 'url';
|
|
3
|
-
import * as fs from 'fs';
|
|
4
|
-
import { ServerLogService } from '../log-service';
|
|
5
|
-
import { LogLevel } from '../../../models/logLevel';
|
|
6
|
-
import { iMp3Settings } from '../../config/iConfig';
|
|
7
|
-
|
|
8
|
-
export class MP3Server {
|
|
9
|
-
public static active: boolean = false;
|
|
10
|
-
public count: number = 0;
|
|
11
|
-
private mp3Path: string = '';
|
|
12
|
-
|
|
13
|
-
public constructor(settings: iMp3Settings) {
|
|
14
|
-
if (!settings) {
|
|
15
|
-
return;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
this.mp3Path = settings.path;
|
|
19
|
-
MP3Server.active = true;
|
|
20
|
-
http
|
|
21
|
-
.createServer((req, response) => {
|
|
22
|
-
if (req.url === undefined) {
|
|
23
|
-
response.writeHead(500);
|
|
24
|
-
response.end('ungültige Anfrage', 'utf-8');
|
|
25
|
-
return;
|
|
26
|
-
}
|
|
27
|
-
const q = url.parse(req.url, true).query;
|
|
28
|
-
|
|
29
|
-
const fName = q.fname;
|
|
30
|
-
|
|
31
|
-
if (!fName || fName.indexOf('.') >= 0) {
|
|
32
|
-
response.writeHead(500);
|
|
33
|
-
response.end('ungültiger Dateiname', 'utf-8');
|
|
34
|
-
return;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
ServerLogService.writeLog(LogLevel.DeepTrace, `Anfrage für ${fName}`);
|
|
38
|
-
const fPath: string = this.mp3Path + fName + '.mp3';
|
|
39
|
-
try {
|
|
40
|
-
if (!fs.existsSync(fPath)) {
|
|
41
|
-
ServerLogService.writeLog(LogLevel.Error, `Die angefragte Datei existiert nicht ${fName}`);
|
|
42
|
-
return;
|
|
43
|
-
}
|
|
44
|
-
} catch (err) {
|
|
45
|
-
console.error(err);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
const filestream = fs.createReadStream(fPath);
|
|
49
|
-
response.writeHead(200, { 'Content-Type': 'audio/mpeg3' });
|
|
50
|
-
filestream.pipe(response, { end: true });
|
|
51
|
-
|
|
52
|
-
/*
|
|
53
|
-
fs.readFile(fPath, (error, data) => {
|
|
54
|
-
if (error) {
|
|
55
|
-
if(error.code == 'ENOENT'){
|
|
56
|
-
fs.readFile('./404.html', (err, cont) => {
|
|
57
|
-
response.writeHead(200, { 'Content-Type': "audio/mpeg3" });
|
|
58
|
-
response.end(cont, 'utf-8');
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
else {
|
|
62
|
-
response.writeHead(500);
|
|
63
|
-
response.end('Sorry, check with the site admin for error: '+error.code+' ..\n');
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
else {
|
|
67
|
-
response.writeHead(200, { 'Content-Type': "audio/mpeg3" });
|
|
68
|
-
response.end(data, 'utf-8');
|
|
69
|
-
}
|
|
70
|
-
})
|
|
71
|
-
*/
|
|
72
|
-
})
|
|
73
|
-
.listen(8081);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
1
|
+
import * as http from 'http';
|
|
2
|
+
import * as url from 'url';
|
|
3
|
+
import * as fs from 'fs';
|
|
4
|
+
import { ServerLogService } from '../log-service';
|
|
5
|
+
import { LogLevel } from '../../../models/logLevel';
|
|
6
|
+
import { iMp3Settings } from '../../config/iConfig';
|
|
7
|
+
|
|
8
|
+
export class MP3Server {
|
|
9
|
+
public static active: boolean = false;
|
|
10
|
+
public count: number = 0;
|
|
11
|
+
private mp3Path: string = '';
|
|
12
|
+
|
|
13
|
+
public constructor(settings: iMp3Settings) {
|
|
14
|
+
if (!settings) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
this.mp3Path = settings.path;
|
|
19
|
+
MP3Server.active = true;
|
|
20
|
+
http
|
|
21
|
+
.createServer((req, response) => {
|
|
22
|
+
if (req.url === undefined) {
|
|
23
|
+
response.writeHead(500);
|
|
24
|
+
response.end('ungültige Anfrage', 'utf-8');
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
const q = url.parse(req.url, true).query;
|
|
28
|
+
|
|
29
|
+
const fName = q.fname;
|
|
30
|
+
|
|
31
|
+
if (!fName || fName.indexOf('.') >= 0) {
|
|
32
|
+
response.writeHead(500);
|
|
33
|
+
response.end('ungültiger Dateiname', 'utf-8');
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
ServerLogService.writeLog(LogLevel.DeepTrace, `Anfrage für ${fName}`);
|
|
38
|
+
const fPath: string = this.mp3Path + fName + '.mp3';
|
|
39
|
+
try {
|
|
40
|
+
if (!fs.existsSync(fPath)) {
|
|
41
|
+
ServerLogService.writeLog(LogLevel.Error, `Die angefragte Datei existiert nicht ${fName}`);
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
} catch (err) {
|
|
45
|
+
console.error(err);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const filestream = fs.createReadStream(fPath);
|
|
49
|
+
response.writeHead(200, { 'Content-Type': 'audio/mpeg3' });
|
|
50
|
+
filestream.pipe(response, { end: true });
|
|
51
|
+
|
|
52
|
+
/*
|
|
53
|
+
fs.readFile(fPath, (error, data) => {
|
|
54
|
+
if (error) {
|
|
55
|
+
if(error.code == 'ENOENT'){
|
|
56
|
+
fs.readFile('./404.html', (err, cont) => {
|
|
57
|
+
response.writeHead(200, { 'Content-Type': "audio/mpeg3" });
|
|
58
|
+
response.end(cont, 'utf-8');
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
response.writeHead(500);
|
|
63
|
+
response.end('Sorry, check with the site admin for error: '+error.code+' ..\n');
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
response.writeHead(200, { 'Content-Type': "audio/mpeg3" });
|
|
68
|
+
response.end(data, 'utf-8');
|
|
69
|
+
}
|
|
70
|
+
})
|
|
71
|
+
*/
|
|
72
|
+
})
|
|
73
|
+
.listen(8081);
|
|
74
|
+
}
|
|
75
|
+
}
|