forked from mfts/papermark
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
56 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { getTriggerClient } from "@/trigger"; | ||
import { log } from "@/lib/utils"; | ||
|
||
export default async function sendNotification({ viewId }: { viewId: string }) { | ||
const client = getTriggerClient(); | ||
|
||
if (!client) { | ||
/** If client does not exist, use fetch to send notifications */ | ||
return await fetch( | ||
`${process.env.NEXTAUTH_URL}/api/jobs/send-notification`, | ||
{ | ||
method: "POST", | ||
headers: { | ||
"Content-Type": "application/json", | ||
Authorization: `Bearer ${process.env.INTERNAL_API_KEY}`, | ||
}, | ||
body: JSON.stringify({ viewId: viewId }), | ||
}, | ||
) | ||
.then(() => {}) | ||
.catch((error) => { | ||
log({ | ||
message: `Failed to fetch notifications job in _/api/views_ route. \n\n Error: ${error} \n\n*Metadata*: \`{viewId: ${viewId}}\``, | ||
type: "error", | ||
mention: true, | ||
}); | ||
}); | ||
} | ||
|
||
/** If client exists, use trigger to send notifications */ | ||
return await client.sendEvent({ | ||
name: "link.viewed", | ||
payload: { | ||
viewId: viewId, | ||
}, | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters