-
-
Notifications
You must be signed in to change notification settings - Fork 1
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
9 changed files
with
232 additions
and
7 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
import { createD1, createWorker } from './src/worker'; | ||
import { createD1, createWorker, sendEmail } from './src/worker'; | ||
|
||
export { createD1, createWorker }; | ||
export { createD1, createWorker, sendEmail }; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,44 @@ | ||
import { createMimeMessage } from 'mimetext'; | ||
import { Proxy } from '../proxy'; | ||
|
||
interface Payload { | ||
sebName: string; | ||
name: string; | ||
addr: string; | ||
recipent: string; | ||
subject: string; | ||
contentType: string; | ||
data: string; | ||
} | ||
|
||
class SendEmailProxy extends Proxy<Payload> { | ||
static readonly proxyType = 'SendEmailProxy'; | ||
constructor({ | ||
host, | ||
name, | ||
payload, | ||
}: { | ||
host?: string; | ||
name: string; | ||
payload: Payload; | ||
}) { | ||
const proxyType = SendEmailProxy.proxyType; | ||
super({ proxyType, host, name, payload }); | ||
} | ||
async execute(env: any) { | ||
const { sebName, name, addr, recipent, subject, contentType, data } = | ||
this.payload, | ||
seb = env[sebName] as SendEmail, | ||
msg = createMimeMessage(); | ||
msg.setSender({ name, addr }); | ||
msg.setRecipient(recipent); | ||
msg.setSubject(subject); | ||
msg.addMessage({ contentType, data }); | ||
const { EmailMessage } = await import('cloudflare:email'); | ||
const message = new EmailMessage(addr, recipent, msg.asRaw()); | ||
await seb.send(message); | ||
return {}; | ||
} | ||
} | ||
|
||
export { SendEmailProxy }; |
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 |
---|---|---|
@@ -1,6 +1,8 @@ | ||
import { createMimeMessage } from 'mimetext'; | ||
import type { ErrorResult, PostData, SuccessResult } from './data'; | ||
import { ProxyFactory } from './factory'; | ||
import { D1DatabaseProxyHolder } from './proxies/d1_database/proxy_holder'; | ||
import { SendEmailProxy } from './proxies/send_email/proxy'; | ||
|
||
const json = <T>(data: T) => { | ||
const result: SuccessResult<T> = { status: 200, data }, | ||
|
@@ -47,6 +49,49 @@ const json = <T>(data: T) => { | |
host: options?.hostname ?? 'http://localhost:8787', | ||
name, | ||
payload: {}, | ||
}); | ||
}), | ||
sendEmail = async ({ | ||
seb, | ||
sebName, | ||
name, | ||
addr, | ||
recipent, | ||
subject, | ||
contentType, | ||
data, | ||
options, | ||
}: { | ||
seb?: SendEmail; | ||
sebName: string; | ||
name: string; | ||
addr: string; | ||
recipent: string; | ||
subject: string; | ||
contentType: string; | ||
data: string; | ||
options?: { hostname?: string }; | ||
}) => { | ||
if (seb) { | ||
const msg = createMimeMessage(); | ||
msg.setSender({ name, addr }); | ||
msg.setRecipient(recipent); | ||
msg.setSubject(subject); | ||
msg.addMessage({ contentType, data }); | ||
const { EmailMessage } = await import('cloudflare:email'), | ||
message = new EmailMessage( | ||
'[email protected]', | ||
'[email protected]', | ||
msg.asRaw() | ||
); | ||
await seb.send(message); | ||
} else { | ||
const proxy = new SendEmailProxy({ | ||
host: options?.hostname ?? 'http://localhost:8787', | ||
name, | ||
payload: { sebName, name, addr, recipent, subject, contentType, data }, | ||
}); | ||
await proxy.post(); | ||
} | ||
}; | ||
|
||
export { createD1, createWorker }; | ||
export { createD1, createWorker, sendEmail }; |
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