@atmosx/event-product-parser 3.0.62 → 3.0.622

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.
Files changed (92) hide show
  1. package/README.md +6 -4
  2. package/dist/cjs/index.cjs +21171 -6858
  3. package/dist/esm/index.mjs +21270 -6957
  4. package/package.json +49 -47
  5. package/pnpm-workspace.yaml +3 -0
  6. package/src/@building/CreateEvent.ts +10 -12
  7. package/src/@building/GetEventAttachments.ts +5 -5
  8. package/src/@building/GetEventEnhancedName.ts +2 -4
  9. package/src/@building/GetEventGeometry.ts +4 -4
  10. package/src/@building/GetEventHeader.ts +2 -2
  11. package/src/@building/GetEventNodes.ts +8 -8
  12. package/src/@building/GetEventOffice.ts +3 -3
  13. package/src/@building/GetEventProperties.ts +16 -11
  14. package/src/@building/GetEventSignature.ts +6 -6
  15. package/src/@building/GetEventTags.ts +1 -1
  16. package/src/@building/GetEventTracking.ts +4 -4
  17. package/src/@core/ClearEvents.ts +2 -2
  18. package/src/@core/CreateListener.ts +1 -1
  19. package/src/@core/GetEvents.ts +1 -1
  20. package/src/@core/GetNodes.ts +1 -1
  21. package/src/@core/GetRandomEvent.ts +1 -1
  22. package/src/@core/GetVersion.ts +1 -1
  23. package/src/@core/ManualEvent.ts +3 -4
  24. package/src/@core/QueryStanza.ts +2 -2
  25. package/src/@core/SetNode.ts +9 -3
  26. package/src/@core/StartService.ts +11 -11
  27. package/src/@core/StopService.ts +1 -1
  28. package/src/@enums/Tags.ts +1 -1
  29. package/src/@events/ParseAPI.ts +15 -10
  30. package/src/@events/ParseText.ts +8 -8
  31. package/src/@events/ParseUGC.ts +9 -9
  32. package/src/@events/ParseVTEC.ts +12 -12
  33. package/src/@manager/MakeEvents.ts +20 -17
  34. package/src/@manager/RemoveEvent.ts +8 -8
  35. package/src/@manager/SetHash.ts +3 -3
  36. package/src/@manager/UpdateEvents.ts +4 -4
  37. package/src/@manager/UpdateNode.ts +4 -4
  38. package/src/@manager/ValidateEvents.ts +13 -14
  39. package/src/@modules/@database/GetCachedEvents.ts +6 -7
  40. package/src/@modules/@database/ImportBroadcastify.ts +3 -3
  41. package/src/@modules/@database/ImportShapefiles.ts +11 -11
  42. package/src/@modules/@database/ImportStanza.ts +4 -4
  43. package/src/@modules/@database/InitializeDatabase.ts +6 -6
  44. package/src/@modules/@eas/GenerateEASMessage.ts +26 -18
  45. package/src/@modules/@eas/GetTTS.ts +2 -2
  46. package/src/@modules/@eas/SetNoise.ts +2 -2
  47. package/src/@modules/@eas/SetRadioEffect.ts +2 -2
  48. package/src/@modules/@eas/SetSameHeader.ts +3 -3
  49. package/src/@modules/@stanza/GetAwipsType.ts +2 -2
  50. package/src/@modules/@stanza/ValidateStanza.ts +4 -4
  51. package/src/@modules/@utilities/GetSettings.ts +2 -2
  52. package/src/@modules/@utilities/QueueManager.ts +71 -0
  53. package/src/@modules/@utilities/SetCronSchedule.ts +8 -8
  54. package/src/@modules/@utilities/SetDebug.ts +2 -2
  55. package/src/@modules/@utilities/SetEventEmit.ts +3 -3
  56. package/src/@modules/@utilities/SetListener.ts +1 -1
  57. package/src/@modules/@utilities/SetSettings.ts +2 -2
  58. package/src/@modules/@utilities/SetTimeoutAction.ts +1 -1
  59. package/src/@modules/@utilities/SetWarning.ts +2 -2
  60. package/src/@modules/@xmpp/DeployXMPP.ts +8 -8
  61. package/src/@modules/@xmpp/ErrorXMPP.ts +1 -1
  62. package/src/@modules/@xmpp/OfflineXMPP.ts +2 -2
  63. package/src/@modules/@xmpp/OnlineXMPP.ts +3 -3
  64. package/src/@modules/@xmpp/ReconnectXMPP.ts +4 -4
  65. package/src/@modules/@xmpp/StanzaXMPP.ts +6 -6
  66. package/src/@parsers/@hvtec/HVExtract.ts +5 -5
  67. package/src/@parsers/@pvtec/VTECExtract.ts +7 -7
  68. package/src/@parsers/@text/GetDescriptionFromProduct.ts +1 -1
  69. package/src/@parsers/@text/GetEmbededText.ts +3 -3
  70. package/src/@parsers/@text/GetStringText.ts +5 -5
  71. package/src/@parsers/@ugc/GetCache.ts +1 -1
  72. package/src/@parsers/@ugc/GetLocations.ts +3 -3
  73. package/src/@parsers/@ugc/GetUGCHeader.ts +1 -1
  74. package/src/@parsers/@ugc/GetZonePolygon.ts +2 -2
  75. package/src/@parsers/@ugc/SetCache.ts +1 -1
  76. package/src/@parsers/@ugc/UGCExtract.ts +5 -5
  77. package/src/@tasks/CreateTasks.ts +110 -0
  78. package/src/@tasks/TaskGenerateAudio.ts +35 -0
  79. package/src/@tasks/TaskGenerateJSON.ts +35 -0
  80. package/src/@tasks/TaskGenerateText.ts +35 -0
  81. package/src/@tasks/TaskSendNTFY.ts +93 -0
  82. package/src/@tasks/TaskSendWebhook.ts +101 -0
  83. package/src/@types/Event.ts +3 -3
  84. package/src/@types/Properties.ts +2 -1
  85. package/src/@types/Settings.ts +1 -1
  86. package/src/@types/StanzaCompiled.ts +1 -1
  87. package/src/bootstrap.ts +3 -3
  88. package/src/index.ts +21 -19
  89. package/tools/build.js +45 -0
  90. package/tsconfig.json +20 -1
  91. package/src/@manager/Tasks.ts +0 -246
  92. package/tsup.config.ts +0 -16
@@ -0,0 +1,101 @@
1
+ /*
2
+ _ _ _ __ __
3
+ /\ | | | | (_) \ \ / /
4
+ / \ | |_ _ __ ___ ___ ___ _ __ | |__ ___ _ __ _ ___ \ V /
5
+ / /\ \| __| '_ ` _ \ / _ \/ __| '_ \| '_ \ / _ \ '__| |/ __| > <
6
+ / ____ \ |_| | | | | | (_) \__ \ |_) | | | | __/ | | | (__ / . \
7
+ /_/ \_\__|_| |_| |_|\___/|___/ .__/|_| |_|\___|_| |_|\___/_/ \_\
8
+ | |
9
+ |_|
10
+
11
+ Created with ♥ by the AtmosphericX Team (KiyoWx, StarflightWx, & CJ Ziegler)
12
+ Discord: https://atmosphericx-discord.scriptkitty.cafe
13
+ Ko-Fi: https://ko-fi.com/k3yomi
14
+ Documentation: http://localhost/documentation | https://atmosphericx.scriptkitty.cafe/documentation
15
+
16
+ Internal Package: @atmosx/event-product-parser
17
+
18
+ */
19
+
20
+ import { TypeEvent } from "types/Event"
21
+ import { CreateHttp } from "@utilities/CreateHttp";
22
+ import { SetTimeoutAction } from "@utilities/SetTimeoutAction";
23
+ import { GetEmebedText } from "@parsers/text/GetEmbededText";
24
+ import { parentPort } from "worker_threads"
25
+ import { readFile } from "fs/promises"
26
+
27
+ interface TaskSendWebhook {
28
+ event: TypeEvent;
29
+ webhook: {
30
+ enabled: boolean;
31
+ destination: string;
32
+ message: string;
33
+ title: string;
34
+ ratelimit: number;
35
+ };
36
+ attachments: {
37
+ text?: string;
38
+ eas?: string;
39
+ json?: string;
40
+ }
41
+ }
42
+
43
+ export const TaskSendWebhook = async function(options: TaskSendWebhook): Promise<void> {
44
+ const { event, webhook, attachments } = options;
45
+ const { properties } = event;
46
+ const isRatelimited = SetTimeoutAction({
47
+ identifier: webhook.destination,
48
+ interval: (webhook.ratelimit ?? 2) * 2,
49
+ max: (webhook.ratelimit ?? 2),
50
+ addTime: true
51
+ })
52
+ if (isRatelimited.limited) { return }
53
+ const newForm = new FormData();
54
+ const newEmbed = {
55
+ title: `${properties.event} (${properties.status})`,
56
+ description: GetEmebedText(event),
57
+ fields: [],
58
+ color: 16711680,
59
+ timestamp: new Date().toISOString(),
60
+ footer: { text: webhook.title ?? `AtmosphericX` }
61
+ };
62
+ if (properties.description && !properties.status_metadata.is_expired) {
63
+ const description = properties.description.length > 900
64
+ ? properties.description.substring(0, 900) + "\n\n[Message truncated due to length]"
65
+ : properties.description;
66
+ newEmbed.fields.push({
67
+ name: "Description",
68
+ value: description ? '```' + '\n' + description.split('\n').map(l => l.trim()).filter(Boolean).join('\n') + '\n' + '```' : ""
69
+ });
70
+ }
71
+ if (properties.metadata.attachments?.length > 0) {
72
+ const attachments = properties.metadata.attachments.slice(0, 5);
73
+ newEmbed.fields.push({
74
+ name: "Attachments",
75
+ value: attachments.map(attachment => `- [${attachment.name.length > 45 ? attachment.name.substring(0, 45) + '...' : attachment.name}](${attachment.link})`).join('\n')
76
+ });
77
+ }
78
+ if (attachments?.text) {
79
+ newForm.append("fUpload", new Blob([Buffer.from(attachments.text)], {type: "application/text"}), `${properties.event}_${properties.status}_${properties.metadata.tracking}.txt`)
80
+ }
81
+ if (attachments?.json) {
82
+ newForm.append("fUpload2", new Blob([Buffer.from(attachments.json)], {type: "application/json"}), `${properties.event}_${properties.status}_${properties.metadata.tracking}.json`)
83
+ }
84
+ if (attachments?.eas) {
85
+ const file = await readFile(attachments.eas);
86
+ newForm.append("fUpload3", new Blob([Buffer.from(file)], {type: "application/wav"}), `${properties.event}_${properties.status}_${properties.metadata.tracking}.wav`)
87
+ }
88
+
89
+ newForm.append("payload_json", JSON.stringify({
90
+ username: webhook.title ?? `AtmosphericX`,
91
+ content: webhook.message ?? "",
92
+ embeds: [newEmbed]
93
+ }));
94
+
95
+ await CreateHttp({
96
+ url: webhook.destination,
97
+ timeout: 15e3,
98
+ method: `POST`,
99
+ body: newForm
100
+ })
101
+ }
@@ -17,9 +17,9 @@
17
17
 
18
18
  */
19
19
 
20
- import { TypeEventProperties as BaseTypeEventProperties } from "./Properties";
21
- import { TypeHVTEC } from "./HVTEC";
22
- import { TypePVTEC } from "./VTEC";
20
+ import { TypeEventProperties as BaseTypeEventProperties } from "types/Properties"
21
+ import { TypeHVTEC } from "types/HVTEC"
22
+ import { TypePVTEC } from "types/VTEC"
23
23
 
24
24
  export type TypeEvent = {
25
25
  type: string
@@ -17,11 +17,12 @@
17
17
 
18
18
  */
19
19
 
20
- import { TypeAttributes } from "./Attributes";
20
+ import { TypeAttributes } from "types/Attributes"
21
21
 
22
22
  export type TypeEventProperties = {
23
23
  locations: string
24
24
  locations_array: string[]
25
+ location_states: string[]
25
26
  description: string
26
27
  attributes?: TypeAttributes
27
28
  geocode: {
@@ -17,7 +17,7 @@
17
17
 
18
18
  */
19
19
 
20
- import { TypeActions } from "./Actions"
20
+ import { TypeActions } from "types/Actions"
21
21
 
22
22
  type TypeTimezones = string | "CST" | "CDT" | "MDT" | "MST" | "EST" | "EDT" | "HST" | "HDT" | "PDT" | "UTC"
23
23
 
@@ -17,7 +17,7 @@
17
17
 
18
18
  */
19
19
 
20
- import { TypeAttributes } from "./Attributes"
20
+ import { TypeAttributes } from "types/Attributes"
21
21
 
22
22
  export type TypeStanzaCompiled = {
23
23
  message?: string
package/src/bootstrap.ts CHANGED
@@ -17,11 +17,11 @@
17
17
 
18
18
  */
19
19
 
20
- import path from 'path'
21
- import { EventEmitter } from 'node:events';
20
+ import path from "path"
21
+ import { EventEmitter } from "node:events"
22
22
 
23
23
  export const bootstrap = {
24
- version: `3.0.61`,
24
+ version: `3.0.622`,
25
25
  isReady: true,
26
26
  ratelimits: {},
27
27
  session_xmpp: null,
package/src/index.ts CHANGED
@@ -17,26 +17,28 @@
17
17
 
18
18
  */
19
19
 
20
- import { TypeSettings } from './@types/Settings'
21
- import { SetSettings } from "./@modules/@utilities/SetSettings"
22
- import { GetEventGeometry } from "./@building/GetEventGeometry";
23
- import { GetCleanedEvent } from "./@building/GetCleanedEvent"
24
- import { SetEventEmit } from './@modules/@utilities/SetEventEmit';
25
- import { SetWarning } from './@modules/@utilities/SetWarning';
26
- import { CreateListener } from "./@core/CreateListener"
27
- import { StartService } from "./@core/StartService"
28
- import { StopService } from "./@core/StopService"
29
- import { GenerateEASMessage } from './@modules/@eas/GenerateEASMessage';
30
- import { SetNode } from "./@core/SetNode"
31
- import { GetEvents } from "./@core/GetEvents"
32
- import { GetNodes } from "./@core/GetNodes"
33
- import { ManualEvent } from "./@core/ManualEvent"
34
- import { GetRandomEvent } from './@core/GetRandomEvent';
35
- import { QueryStanza } from './@core/QueryStanza';
36
- import { ClearEvents } from './@core/ClearEvents';
20
+ import { TypeSettings } from "types/Settings"
21
+ import { GetEventGeometry } from "@building/GetEventGeometry"
22
+ import { GetCleanedEvent } from "@building/GetCleanedEvent"
23
+ import { SetSettings } from "@utilities/SetSettings"
24
+ import { SetEventEmit } from "@utilities/SetEventEmit"
25
+ import { SetWarning } from "@utilities/SetWarning"
26
+ import { GenerateEASMessage } from "@eas/GenerateEASMessage"
27
+ import { SetNode } from "@core/SetNode"
28
+ import { GetEvents } from "@core/GetEvents"
29
+ import { GetNodes } from "@core/GetNodes"
30
+ import { ManualEvent } from "@core/ManualEvent"
31
+ import { GetRandomEvent } from "@core/GetRandomEvent"
32
+ import { QueryStanza } from "@core/QueryStanza"
33
+ import { ClearEvents } from "@core/ClearEvents"
34
+ import { CreateListener } from "@core/CreateListener"
35
+ import { StartService } from "@core/StartService"
36
+ import { StopService } from "@core/StopService"
37
37
 
38
38
  export class Manager {
39
- constructor(settings: TypeSettings) { this.trycatch(); StartService(settings) }
39
+ public constructor(settings: TypeSettings) {
40
+ this.trycatch(); StartService(settings)
41
+ }
40
42
 
41
43
  on(event: string, callback: () => void) {
42
44
  CreateListener(event, callback)
@@ -63,7 +65,7 @@ export class Manager {
63
65
  }
64
66
 
65
67
  export default Manager;
66
- export type { TypeEvent } from './@types/Event';
68
+ export type { TypeEvent } from "types/Event"
67
69
  export {
68
70
  SetSettings, GetEventGeometry, ManualEvent,
69
71
  GetCleanedEvent, StopService, ClearEvents,
package/tools/build.js ADDED
@@ -0,0 +1,45 @@
1
+ const { spawn } = require("child_process");
2
+ const watch = process.argv.includes("--watch");
3
+
4
+ const commands = [
5
+ {
6
+ name: "esm",
7
+ args: [
8
+ "--bundle",
9
+ "--platform=node",
10
+ "--target=node22",
11
+ "--format=esm",
12
+ "--external:better-sqlite3",
13
+ "--out-extension:.js=.mjs",
14
+ "--outdir=dist/esm",
15
+ ...(watch ? ["--watch"] : []),
16
+ "./src/index.ts",
17
+ ],
18
+ },
19
+ {
20
+ name: "cjs",
21
+ args: [
22
+ "--bundle",
23
+ "--platform=node",
24
+ "--target=node22",
25
+ "--format=cjs",
26
+ "--external:better-sqlite3",
27
+ "--out-extension:.js=.cjs",
28
+ "--outdir=dist/cjs",
29
+ ...(watch ? ["--watch"] : []),
30
+ "./src/index.ts",
31
+ ],
32
+ },
33
+ ];
34
+
35
+ function runBuild({ name, args }) {
36
+ return new Promise((resolve, reject) => {
37
+ const proc = spawn("esbuild", args, {
38
+ shell: true,
39
+ stdio: "inherit",
40
+ });
41
+ proc.on("error", reject);
42
+ });
43
+ }
44
+
45
+ Promise.all(commands.map(runBuild)).catch((err) => { console.error(err); process.exit(1); });
package/tsconfig.json CHANGED
@@ -8,7 +8,26 @@
8
8
  "declarationDir": "dist/types",
9
9
  "esModuleInterop": true,
10
10
  "allowSyntheticDefaultImports": true,
11
- "skipLibCheck": true
11
+ "skipLibCheck": true,
12
+ "paths": {
13
+ "@parsers/hvtec/*": ["./src/@parsers/@hvtec/*"],
14
+ "@parsers/pvtec/*": ["./src/@parsers/@pvtec/*"],
15
+ "@parsers/ugc/*": ["./src/@parsers/@ugc/*"],
16
+ "@parsers/text/*": ["./src/@parsers/@text/*"],
17
+ "@database/*": ["./src/@modules/@database/*"],
18
+ "@eas/*": ["./src/@modules/@eas/*"],
19
+ "@stanza/*": ["./src/@modules/@stanza/*"],
20
+ "@utilities/*": ["./src/@modules/@utilities/*"],
21
+ "@xmpp/*": ["./src/@modules/@xmpp/*"],
22
+ "@manager/*": ["./src/@manager/*"],
23
+ "@tasks/*": ["./src/@tasks/*"],
24
+ "@events/*": ["./src/@events/*"],
25
+ "@enums/*": ["./src/@enums/*"],
26
+ "@core/*": ["./src/@core/*"],
27
+ "@building/*": ["./src/@building/*"],
28
+ "types/*": ["./src/@types/*"],
29
+ "@bootstrap": ["./src/bootstrap.ts"],
30
+ }
12
31
  },
13
32
  "include": ["src"]
14
33
  }
@@ -1,246 +0,0 @@
1
- /*
2
- _ _ _ __ __
3
- /\ | | | | (_) \ \ / /
4
- / \ | |_ _ __ ___ ___ ___ _ __ | |__ ___ _ __ _ ___ \ V /
5
- / /\ \| __| '_ ` _ \ / _ \/ __| '_ \| '_ \ / _ \ '__| |/ __| > <
6
- / ____ \ |_| | | | | | (_) \__ \ |_) | | | | __/ | | | (__ / . \
7
- /_/ \_\__|_| |_| |_|\___/|___/ .__/|_| |_|\___|_| |_|\___/_/ \_\
8
- | |
9
- |_|
10
-
11
- Created with ♥ by the AtmosphericX Team (KiyoWx, StarflightWx, & CJ Ziegler)
12
- Discord: https://atmosphericx-discord.scriptkitty.cafe
13
- Ko-Fi: https://ko-fi.com/k3yomi
14
- Documentation: http://localhost/documentation | https://atmosphericx.scriptkitty.cafe/documentation
15
-
16
- Internal Package: @atmosx/event-product-parser
17
-
18
- */
19
-
20
- import { TypeSettings } from "../@types/Settings";
21
- import { TypeEvent } from "../@types/Event";
22
- import { TypeActions } from "../@types/Actions";
23
- import { bootstrap } from "../bootstrap"
24
- import { GenerateEASMessage } from "../@modules/@eas/GenerateEASMessage"
25
- import { SetTimeoutAction } from "../@modules/@utilities/SetTimeoutAction";
26
- import { GetEmebedText } from "../@parsers/@text/GetEmbededText";
27
- import { GetStringText } from "../@parsers/@text/GetStringText";
28
- import { GetCleanedEvent } from "../@building/GetCleanedEvent"
29
- import { CreateHttp } from "../@modules/@utilities/CreateHttp";
30
- import { SetDebug } from "../@modules/@utilities/SetDebug";
31
- import { GetMatched } from "../@modules/@utilities/GetMatched";
32
- import { mkdir, writeFile, readFile, appendFile } from "fs/promises";
33
-
34
- export const Tasks = async (events: TypeEvent[]): Promise<void> => {
35
- const tick = performance.now()
36
- const settings = bootstrap.settings as TypeSettings;
37
- const notifyServer = settings.NotifyServer;
38
- const actions = settings.ActionSettings as TypeActions[];
39
- for (const event of events) {
40
- const properties = event.properties;
41
- const hasActions = Array.isArray(actions) && actions.length > 0;
42
- if (!hasActions) {
43
- SetDebug({ title: `Tasks`, message: `${Math.round(performance.now() - tick)}ms` });
44
- return;
45
- }
46
- const metadata = {
47
- text: null,
48
- eas: null,
49
- json: null,
50
- name: properties.event,
51
- status: properties.status,
52
- description: properties.description,
53
- tracking: properties.metadata.tracking,
54
- header: properties.metadata.header,
55
- raw: properties.metadata.raw,
56
- expired: properties.status_metadata.is_expired,
57
- attachments: properties.metadata.attachments
58
- }
59
-
60
- const archiveSettings = settings.GlobalSettings?.ArchiveSettings;
61
- const textArchiveDir = archiveSettings?.TextDirectory;
62
- const jsonArchiveDir = archiveSettings?.JSONDirectory;
63
- const eventBaseName = `${metadata.name}_${metadata.tracking}`;
64
- const easTitle = `${metadata.name}_${metadata.status}_${metadata.tracking}`;
65
- const cleanedEventText = JSON.stringify(GetCleanedEvent(event), null, 2);
66
- const stringText = GetStringText(event);
67
- const embedText = GetEmebedText(event);
68
-
69
- for (const action of actions) {
70
- const events = action?.Events;
71
- const webhook = action?.Webhook;
72
- const notify = action?.NotificationServer;
73
- const uploads = action?.Uploads
74
- const isMatched = GetMatched(events ?? [], metadata.name)
75
-
76
- if (events?.length == 0 || isMatched) {
77
- const t = performance.now()
78
-
79
- if (uploads?.EAS && !metadata.eas) {
80
- metadata.eas = await GenerateEASMessage({
81
- title: easTitle,
82
- message: metadata.description,
83
- header: metadata.header
84
- });
85
- SetDebug({
86
- title: "Tasks/EAS",
87
- message: `${Math.round(performance.now() - t)}ms`
88
- });
89
- }
90
-
91
- if (uploads?.TEXT && metadata.text === null) {
92
- const t = performance.now()
93
- if (textArchiveDir) {
94
- const file = (`${textArchiveDir}/${eventBaseName}.txt`).replace(/[\\:*?"<>|]/g, "_").replace(/\s+/g, " ").trim();
95
- await mkdir(textArchiveDir, { recursive: true });
96
- await appendFile(file, `${"\n".repeat(7)}${metadata.raw}`);
97
- SetDebug({
98
- title: "Tasks/TEXT",
99
- message: `${Math.round(performance.now() - t)}ms`
100
- });
101
- }
102
- metadata.text = metadata.raw;
103
- }
104
-
105
- if (uploads?.JSON && metadata.json === null) {
106
- const t = performance.now()
107
- if (jsonArchiveDir) {
108
- const file = (`${jsonArchiveDir}/${eventBaseName}.json`).replace(/[\\:*?"<>|]/g, "_").replace(/\s+/g, " ").trim();
109
- await mkdir(jsonArchiveDir, { recursive: true });
110
- await writeFile(file, cleanedEventText);
111
- SetDebug({
112
- title: "Tasks/JSON",
113
- message: `${Math.round(performance.now() - t)}ms`
114
- });
115
- }
116
- metadata.json = cleanedEventText;
117
- }
118
-
119
- if (notifyServer?.Enabled && notify?.Enabled && notify?.Topic) {
120
- let buttons = [];
121
- const t = performance.now()
122
- const auth = notifyServer?.Credentials?.Username && notifyServer?.Credentials?.Password ? { username: notifyServer?.Credentials?.Username, password: notifyServer?.Credentials?.Password } : undefined;
123
- const image = metadata.attachments?.find(a => a.name === "Image: Graphic");
124
-
125
-
126
- if (notifyServer?.MediaStorage?.EAS) {
127
- if (metadata.eas) {
128
- buttons.push({
129
- "action": "view",
130
- "label": "Listen",
131
- "url": `${notifyServer?.MediaStorage?.EAS}/${metadata.name}_${metadata.status}_${metadata.tracking}.wav`,
132
- })
133
- }
134
- }
135
- if (metadata.json) {
136
- buttons.push({
137
- "action": "view",
138
- "label": "View JSON",
139
- "url": `${notifyServer?.MediaStorage?.JSON}/${metadata.name}_${metadata.tracking}.json`,
140
- })
141
- }
142
- if (metadata.text) {
143
- buttons.push({
144
- "action": "view",
145
- "label": "View Text",
146
- "url": `${notifyServer?.MediaStorage?.TEXT}/${metadata.name}_${metadata.tracking}.txt`,
147
- })
148
- }
149
- if (image) {
150
- buttons.push({
151
- "action": "view",
152
- "label": "View Image",
153
- "url": image.link,
154
- })
155
- }
156
- await CreateHttp({
157
- url: `${notifyServer?.Server?.replace(/\/$/, "")}/${notify.Topic}`,
158
- timeout: 15_000,
159
- method: "PUT",
160
- ...(auth && { auth }),
161
- headers: {
162
- "Title": `${metadata.name} (${metadata.status})`,
163
- "Tags": properties.parameters.tags?.join(",") ?? "N/A",
164
- "Priority": notify?.Priority ?? "5",
165
- ... (buttons.length > 0 && { "Actions": JSON.stringify(buttons) }),
166
- },
167
- body: stringText
168
- })
169
- SetDebug({
170
- title: "Tasks/NTFY",
171
- message: `${Math.round(performance.now() - t)}ms`
172
- });
173
- }
174
-
175
- if (webhook?.Enabled && webhook?.Destination) {
176
- const t = performance.now()
177
- const isRatelimited = SetTimeoutAction({ identifier: webhook.Destination, interval: (webhook.Ratelimit ?? 2) * 2, max: (webhook.Ratelimit ?? 2), addTime: true })
178
- const form = new FormData();
179
- const embed = {
180
- title: `${metadata.name} (${metadata.status})`,
181
- description: embedText,
182
- fields: [],
183
- color: 16711680,
184
- timestamp: new Date().toISOString(),
185
- footer: { text: webhook.Title ?? `AtmosphericX` }
186
- };
187
-
188
- if (isRatelimited.limited) { return }
189
-
190
-
191
- if (metadata.description && !metadata.expired) {
192
- const description = metadata.description.length > 900
193
- ? metadata.description.substring(0, 900) + "\n\n[Message truncated due to length]"
194
- : metadata.description;
195
- embed.fields.push({
196
- name: "Description",
197
- value: description ? '```' + '\n' + description.split('\n').map(l => l.trim()).filter(Boolean).join('\n') + '\n' + '```' : ""
198
- });
199
- }
200
-
201
-
202
- if (metadata.attachments?.length > 0) {
203
- const attachments = metadata.attachments.slice(0, 5);
204
- embed.fields.push({
205
- name: "Attachments",
206
- value: attachments.map(attachment => `- [${attachment.name.length > 45 ? attachment.name.substring(0, 45) + '...' : attachment.name}](${attachment.link})`).join('\n')
207
- });
208
- }
209
-
210
- if (uploads?.TEXT) {
211
- form.append("fUpload", new Blob([Buffer.from(metadata.text)], {type: "application/text"}), `${properties.event}_${properties.status}_${properties.metadata.tracking}.txt`)
212
- }
213
-
214
- if (uploads?.JSON) {
215
- form.append("fUpload2", new Blob([Buffer.from(metadata.json)], {type: "application/json"}), `${properties.event}_${properties.status}_${properties.metadata.tracking}.json`)
216
- }
217
-
218
- if (uploads?.EAS) {
219
- if (metadata.eas) {
220
- const file = await readFile(metadata.eas);
221
- form.append("fEas", new Blob([Buffer.from(file)], { type: "audio/mpeg" }), `${properties.event}_${properties.status}_${properties.metadata.tracking}_eas.mp3`)
222
- }
223
- }
224
-
225
- form.append("payload_json", JSON.stringify({
226
- username: webhook.Title ?? "AtmosphericX",
227
- content: webhook.Message ?? "",
228
- embeds: [embed]
229
- }));
230
-
231
- await CreateHttp({
232
- url: webhook.Destination,
233
- timeout: 15e3,
234
- method: `POST`,
235
- body: form
236
- })
237
- SetDebug({
238
- title: "Tasks/Webhook",
239
- message: `${Math.round(performance.now() - t)}ms`
240
- });
241
- }
242
- }
243
- }
244
- }
245
- SetDebug({ title: `Tasks`, message: `${Math.round(performance.now() - tick)}ms` })
246
- }
package/tsup.config.ts DELETED
@@ -1,16 +0,0 @@
1
- import { defineConfig } from 'tsup'
2
-
3
- export default defineConfig({
4
- entry: ['src/index.ts'],
5
- outDir: 'dist',
6
- format: ['esm', 'cjs'],
7
- dts: false,
8
- noExternal: ["@xmpp/client", "@xmpp/sasl", "@xmpp/sasl-plain"],
9
- clean: true,
10
- outExtension({ format }) {
11
- return { js: format === 'esm' ? '.mjs' : '.cjs' }
12
- },
13
- esbuildOptions(options, context) {
14
- options.outdir = `dist/${context.format}`
15
- },
16
- })