mirror of
https://github.com/deployflare/CronWorker.git
synced 2026-01-13 16:18:00 +00:00
This build was committed by a bot.
This commit is contained in:
175
.gitignore
vendored
Normal file
175
.gitignore
vendored
Normal file
@@ -0,0 +1,175 @@
|
|||||||
|
package-lock.json
|
||||||
|
.idea
|
||||||
|
|
||||||
|
# Logs
|
||||||
|
|
||||||
|
logs
|
||||||
|
_.log
|
||||||
|
npm-debug.log_
|
||||||
|
yarn-debug.log*
|
||||||
|
yarn-error.log*
|
||||||
|
lerna-debug.log*
|
||||||
|
.pnpm-debug.log*
|
||||||
|
|
||||||
|
# Diagnostic reports (https://nodejs.org/api/report.html)
|
||||||
|
|
||||||
|
report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json
|
||||||
|
|
||||||
|
# Runtime data
|
||||||
|
|
||||||
|
pids
|
||||||
|
_.pid
|
||||||
|
_.seed
|
||||||
|
\*.pid.lock
|
||||||
|
|
||||||
|
# Directory for instrumented libs generated by jscoverage/JSCover
|
||||||
|
|
||||||
|
lib-cov
|
||||||
|
|
||||||
|
# Coverage directory used by tools like istanbul
|
||||||
|
|
||||||
|
coverage
|
||||||
|
\*.lcov
|
||||||
|
|
||||||
|
# nyc test coverage
|
||||||
|
|
||||||
|
.nyc_output
|
||||||
|
|
||||||
|
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
|
||||||
|
|
||||||
|
.grunt
|
||||||
|
|
||||||
|
# Bower dependency directory (https://bower.io/)
|
||||||
|
|
||||||
|
bower_components
|
||||||
|
|
||||||
|
# node-waf configuration
|
||||||
|
|
||||||
|
.lock-wscript
|
||||||
|
|
||||||
|
# Compiled binary addons (https://nodejs.org/api/addons.html)
|
||||||
|
|
||||||
|
build/Release
|
||||||
|
|
||||||
|
# Dependency directories
|
||||||
|
|
||||||
|
node_modules/
|
||||||
|
jspm_packages/
|
||||||
|
|
||||||
|
# Snowpack dependency directory (https://snowpack.dev/)
|
||||||
|
|
||||||
|
web_modules/
|
||||||
|
|
||||||
|
# TypeScript cache
|
||||||
|
|
||||||
|
\*.tsbuildinfo
|
||||||
|
|
||||||
|
# Optional npm cache directory
|
||||||
|
|
||||||
|
.npm
|
||||||
|
|
||||||
|
# Optional eslint cache
|
||||||
|
|
||||||
|
.eslintcache
|
||||||
|
|
||||||
|
# Optional stylelint cache
|
||||||
|
|
||||||
|
.stylelintcache
|
||||||
|
|
||||||
|
# Microbundle cache
|
||||||
|
|
||||||
|
.rpt2_cache/
|
||||||
|
.rts2_cache_cjs/
|
||||||
|
.rts2_cache_es/
|
||||||
|
.rts2_cache_umd/
|
||||||
|
|
||||||
|
# Optional REPL history
|
||||||
|
|
||||||
|
.node_repl_history
|
||||||
|
|
||||||
|
# Output of 'npm pack'
|
||||||
|
|
||||||
|
\*.tgz
|
||||||
|
|
||||||
|
# Yarn Integrity file
|
||||||
|
|
||||||
|
.yarn-integrity
|
||||||
|
|
||||||
|
# dotenv environment variable files
|
||||||
|
|
||||||
|
.env
|
||||||
|
.env.development.local
|
||||||
|
.env.test.local
|
||||||
|
.env.production.local
|
||||||
|
.env.local
|
||||||
|
|
||||||
|
# parcel-bundler cache (https://parceljs.org/)
|
||||||
|
|
||||||
|
.cache
|
||||||
|
.parcel-cache
|
||||||
|
|
||||||
|
# Next.js build output
|
||||||
|
|
||||||
|
.next
|
||||||
|
out
|
||||||
|
|
||||||
|
# Nuxt.js build / generate output
|
||||||
|
|
||||||
|
.nuxt
|
||||||
|
dist
|
||||||
|
|
||||||
|
# Gatsby files
|
||||||
|
|
||||||
|
.cache/
|
||||||
|
|
||||||
|
# Comment in the public line in if your project uses Gatsby and not Next.js
|
||||||
|
|
||||||
|
# https://nextjs.org/blog/next-9-1#public-directory-support
|
||||||
|
|
||||||
|
# public
|
||||||
|
|
||||||
|
# vuepress build output
|
||||||
|
|
||||||
|
.vuepress/dist
|
||||||
|
|
||||||
|
# vuepress v2.x temp and cache directory
|
||||||
|
|
||||||
|
.temp
|
||||||
|
.cache
|
||||||
|
|
||||||
|
# Docusaurus cache and generated files
|
||||||
|
|
||||||
|
.docusaurus
|
||||||
|
|
||||||
|
# Serverless directories
|
||||||
|
|
||||||
|
.serverless/
|
||||||
|
|
||||||
|
# FuseBox cache
|
||||||
|
|
||||||
|
.fusebox/
|
||||||
|
|
||||||
|
# DynamoDB Local files
|
||||||
|
|
||||||
|
.dynamodb/
|
||||||
|
|
||||||
|
# TernJS port file
|
||||||
|
|
||||||
|
.tern-port
|
||||||
|
|
||||||
|
# Stores VSCode versions used for testing VSCode extensions
|
||||||
|
|
||||||
|
.vscode-test
|
||||||
|
|
||||||
|
# yarn v2
|
||||||
|
|
||||||
|
.yarn/cache
|
||||||
|
.yarn/unplugged
|
||||||
|
.yarn/build-state.yml
|
||||||
|
.yarn/install-state.gz
|
||||||
|
.pnp.\*
|
||||||
|
|
||||||
|
# wrangler project
|
||||||
|
|
||||||
|
.dev.vars
|
||||||
|
.wrangler/
|
||||||
16
package.json
Normal file
16
package.json
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
{
|
||||||
|
"name": "blank",
|
||||||
|
"version": "0.0.1",
|
||||||
|
"private": true,
|
||||||
|
"scripts": {
|
||||||
|
"deploy": "wrangler deploy",
|
||||||
|
"dev": "wrangler dev",
|
||||||
|
"start": "wrangler dev"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"mimetext": "^3.0.16"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"wrangler": "4.16.*"
|
||||||
|
}
|
||||||
|
}
|
||||||
12
src/index.js
Normal file
12
src/index.js
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
import mail from './mailer.js'
|
||||||
|
async function scheduled(controller, env, ctx) {
|
||||||
|
const lastCount = await env.KV_MIE.get('count')
|
||||||
|
const latestCount = (await env.KV_MIE.list()).keys.length-1
|
||||||
|
if (lastCount != latestCount)
|
||||||
|
{
|
||||||
|
await mail(env, latestCount-lastCount, 'New Mie Sub!')
|
||||||
|
await env.KV_MIE.put('count', latestCount)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default { scheduled }
|
||||||
27
src/mailer.js
Normal file
27
src/mailer.js
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
import { EmailMessage } from "cloudflare:email";
|
||||||
|
import { createMimeMessage } from "mimetext";
|
||||||
|
async function send(env, message, subject) {
|
||||||
|
//console.log("Attempting to send email...");
|
||||||
|
const msg = createMimeMessage();
|
||||||
|
msg.setSender({ name: "Worker", addr: "i@planetrenox.com" });
|
||||||
|
msg.setRecipient("planetrenox@protonmail.com");
|
||||||
|
msg.setSubject(subject);
|
||||||
|
msg.addMessage({
|
||||||
|
contentType: 'text/plain',
|
||||||
|
data: message
|
||||||
|
});
|
||||||
|
const email = new EmailMessage(
|
||||||
|
"i@planetrenox.com",
|
||||||
|
"planetrenox@protonmail.com",
|
||||||
|
msg.asRaw()
|
||||||
|
);
|
||||||
|
try {
|
||||||
|
const result = await env.MAILER.send(email);
|
||||||
|
//console.log("Email sent successfully:", result);
|
||||||
|
return result;
|
||||||
|
} catch (err) {
|
||||||
|
console.error("Email send error:", err);
|
||||||
|
throw new Error(`Failed to send email: ${err.message || err}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
export default send
|
||||||
51
wrangler.toml
Normal file
51
wrangler.toml
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
# For more details on how to configure Wrangler, refer to:
|
||||||
|
# https://developers.cloudflare.com/workers/wrangler/configuration/
|
||||||
|
|
||||||
|
name = "cron"
|
||||||
|
main = "src/index.js"
|
||||||
|
compatibility_date = "2025-05-25"
|
||||||
|
compatibility_flags = [ "nodejs_compat" ]
|
||||||
|
|
||||||
|
[observability]
|
||||||
|
enabled = true
|
||||||
|
|
||||||
|
[triggers]
|
||||||
|
# - at minute 0 of every 3rd hour (e.g., 00:00, 03:00, 06:00, ..., 21:00 UTC)
|
||||||
|
crons = [ "0 */3 * * *" ]
|
||||||
|
|
||||||
|
# Smart Placement
|
||||||
|
# Docs: https://developers.cloudflare.com/workers/configuration/smart-placement/#smart-placement
|
||||||
|
# [placement]
|
||||||
|
# mode = "smart"
|
||||||
|
|
||||||
|
# Bindings
|
||||||
|
# Bindings allow your Worker to interact with resources on the Cloudflare Developer Platform, including
|
||||||
|
# databases, object storage, AI inference, real-time communication and more.
|
||||||
|
# https://developers.cloudflare.com/workers/runtime-apis/bindings/
|
||||||
|
[[kv_namespaces]]
|
||||||
|
binding = "KV_MIE"
|
||||||
|
id = "d0b45970d3c04397a6e0dc6ad30216e3"
|
||||||
|
|
||||||
|
[[send_email]]
|
||||||
|
name = "MAILER"
|
||||||
|
|
||||||
|
|
||||||
|
# Environment Variables
|
||||||
|
# https://developers.cloudflare.com/workers/wrangler/configuration/#environment-variables
|
||||||
|
# [vars]
|
||||||
|
# MY_VARIABLE = "production_value"
|
||||||
|
|
||||||
|
# Note: Use secrets to store sensitive data.
|
||||||
|
# https://developers.cloudflare.com/workers/configuration/secrets/
|
||||||
|
|
||||||
|
# Static Assets
|
||||||
|
# https://developers.cloudflare.com/workers/static-assets/binding/
|
||||||
|
# [assets]
|
||||||
|
# directory = "./public/"
|
||||||
|
# binding = "ASSETS"
|
||||||
|
|
||||||
|
# Service Bindings (communicate between multiple Workers)
|
||||||
|
# https://developers.cloudflare.com/workers/wrangler/configuration/#service-bindings
|
||||||
|
# [[services]]
|
||||||
|
# binding = "MY_SERVICE"
|
||||||
|
# service = "my-service"
|
||||||
Reference in New Issue
Block a user