mirror of
https://github.com/Dokploy/dokploy.git
synced 2026-07-08 07:25:22 +02:00
feat: update notification handling to make accessToken optional
- Modified the notification schema to allow accessToken to be optional, enhancing flexibility in notification settings. - Updated related components and database schema to accommodate the change, ensuring backward compatibility. - Improved handling of accessToken in notification requests and responses, defaulting to null when not provided.
This commit is contained in:
@@ -116,7 +116,7 @@ export const ntfy = pgTable("ntfy", {
|
||||
.$defaultFn(() => nanoid()),
|
||||
serverUrl: text("serverUrl").notNull(),
|
||||
topic: text("topic").notNull(),
|
||||
accessToken: text("accessToken").notNull(),
|
||||
accessToken: text("accessToken"),
|
||||
priority: integer("priority").notNull().default(3),
|
||||
});
|
||||
|
||||
@@ -331,7 +331,7 @@ export const apiCreateNtfy = notificationsSchema
|
||||
.extend({
|
||||
serverUrl: z.string().min(1),
|
||||
topic: z.string().min(1),
|
||||
accessToken: z.string().min(1),
|
||||
accessToken: z.string().optional(),
|
||||
priority: z.number().min(1),
|
||||
})
|
||||
.required();
|
||||
@@ -395,7 +395,7 @@ export const apiSendTest = notificationsSchema
|
||||
serverUrl: z.string(),
|
||||
topic: z.string(),
|
||||
appToken: z.string(),
|
||||
accessToken: z.string(),
|
||||
accessToken: z.string().optional(),
|
||||
priority: z.number(),
|
||||
})
|
||||
.partial();
|
||||
|
||||
@@ -498,7 +498,7 @@ export const createNtfyNotification = async (
|
||||
.values({
|
||||
serverUrl: input.serverUrl,
|
||||
topic: input.topic,
|
||||
accessToken: input.accessToken,
|
||||
accessToken: input.accessToken ?? null,
|
||||
priority: input.priority,
|
||||
})
|
||||
.returning()
|
||||
@@ -569,7 +569,7 @@ export const updateNtfyNotification = async (
|
||||
.set({
|
||||
serverUrl: input.serverUrl,
|
||||
topic: input.topic,
|
||||
accessToken: input.accessToken,
|
||||
accessToken: input.accessToken ?? null,
|
||||
priority: input.priority,
|
||||
})
|
||||
.where(eq(ntfy.ntfyId, input.ntfyId));
|
||||
|
||||
@@ -156,15 +156,20 @@ export const sendNtfyNotification = async (
|
||||
actions: string,
|
||||
message: string,
|
||||
) => {
|
||||
const headers: Record<string, string> = {
|
||||
"X-Priority": connection.priority?.toString() || "3",
|
||||
"X-Title": title,
|
||||
"X-Tags": tags,
|
||||
"X-Actions": actions,
|
||||
};
|
||||
|
||||
if (connection.accessToken) {
|
||||
headers.Authorization = `Bearer ${connection.accessToken}`;
|
||||
}
|
||||
|
||||
const response = await fetch(`${connection.serverUrl}/${connection.topic}`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
Authorization: `Bearer ${connection.accessToken}`,
|
||||
"X-Priority": connection.priority?.toString() || "3",
|
||||
"X-Title": title,
|
||||
"X-Tags": tags,
|
||||
"X-Actions": actions,
|
||||
},
|
||||
headers,
|
||||
body: message,
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user