Remove Cloudflare Workers types and related configurations; delete email worker implementation and add reset tokens JSON file.
This commit is contained in:
1 parent
8bf6445cf6
commit
f902c80dc6
44 files changed
+200
-350741
No files matched your search
+4
-19
@@ -23,7 +23,7 @@
|
||||
<section class="panel account-hero">
|
||||
<p class="hero-kicker">FEDL account</p>
|
||||
<h2>Manage your account</h2>
|
||||
<p class="muted">Update the email tied to your account, change your password, and send yourself a password reset link.</p>
|
||||
<p class="muted">Change your password and view your account details.</p>
|
||||
<p id="account-overview-status" class="muted" role="status"></p>
|
||||
<div class="account-summary-grid">
|
||||
<article class="account-summary-card">
|
||||
@@ -38,26 +38,11 @@
|
||||
</section>
|
||||
|
||||
<section class="panel account-panel">
|
||||
<h3>Email</h3>
|
||||
<p class="muted">Add the inbox you want FEDL to use for account recovery.</p>
|
||||
<form id="account-email-form" class="auth-form">
|
||||
<label class="admin-password-field" for="account-email">
|
||||
<span>Email address</span>
|
||||
<input id="account-email" name="email" type="email" autocomplete="email" required />
|
||||
</label>
|
||||
<p id="account-email-status" class="muted" role="status"></p>
|
||||
<div class="auth-actions">
|
||||
<button type="submit" class="btn">Save email</button>
|
||||
</div>
|
||||
</form>
|
||||
</section>
|
||||
|
||||
<section class="panel account-panel">
|
||||
<h3>Password reset email</h3>
|
||||
<p id="account-reset-support" class="muted">Loading reset email settings…</p>
|
||||
<h3>Password reset</h3>
|
||||
<p class="muted">Forgot your password? Request a reset code which will be sent to your messages.</p>
|
||||
<p id="account-reset-status" class="muted" role="status"></p>
|
||||
<div class="auth-actions">
|
||||
<button type="button" class="btn" id="account-reset-email-btn">Email me a reset link</button>
|
||||
<button type="button" class="btn" id="account-reset-email-btn">Send reset to my messages</button>
|
||||
<a class="text-link" href="reset-password.html">Open reset page</a>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
@@ -2880,17 +2880,12 @@
|
||||
return;
|
||||
}
|
||||
const username = String(qs('signup-username').value || '').trim().toLowerCase();
|
||||
const email = String((qs('signup-email') && qs('signup-email').value) || '').trim().toLowerCase();
|
||||
const password = qs('signup-password').value || '';
|
||||
const password2 = qs('signup-password2').value || '';
|
||||
if (!FEDL_USERNAME_RE.test(username)) {
|
||||
setSignupStatus('Use 3–24 characters: lowercase letters, numbers, or underscore only.', 'error');
|
||||
return;
|
||||
}
|
||||
if (email && !FEDL_EMAIL_RE.test(email)) {
|
||||
setSignupStatus('Enter a valid email address.', 'error');
|
||||
return;
|
||||
}
|
||||
if (password.length < 8) {
|
||||
setSignupStatus('Password must be at least 8 characters.', 'error');
|
||||
return;
|
||||
@@ -2904,7 +2899,7 @@
|
||||
fetch(liveApiPath('/api/auth/signup'), {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ username, email, password })
|
||||
body: JSON.stringify({ username, password })
|
||||
}).then(async r=>{
|
||||
const { data, message } = await fedlReadJsonResponse(r);
|
||||
if (!r.ok) {
|
||||
@@ -2984,12 +2979,8 @@
|
||||
|
||||
if (page === 'account') {
|
||||
const overviewStatusEl = qs('account-overview-status');
|
||||
const emailForm = qs('account-email-form');
|
||||
const emailStatusEl = qs('account-email-status');
|
||||
const emailInput = qs('account-email');
|
||||
const accountUsernameEl = qs('account-username');
|
||||
const accountCreatedEl = qs('account-created');
|
||||
const resetSupportEl = qs('account-reset-support');
|
||||
const resetBtn = qs('account-reset-email-btn');
|
||||
const resetStatusEl = qs('account-reset-status');
|
||||
const passwordForm = qs('account-password-form');
|
||||
@@ -2999,9 +2990,6 @@
|
||||
function setOverviewStatus(msg, kind){
|
||||
fedlSetFormStatus(overviewStatusEl, msg, kind);
|
||||
}
|
||||
function setEmailStatus(msg, kind){
|
||||
fedlSetFormStatus(emailStatusEl, msg, kind);
|
||||
}
|
||||
function setResetStatus(msg, kind){
|
||||
fedlSetFormStatus(resetStatusEl, msg, kind);
|
||||
}
|
||||
@@ -3040,21 +3028,6 @@
|
||||
if (accountCreatedEl) {
|
||||
accountCreatedEl.textContent = formatJoinedDate(data.createdAt);
|
||||
}
|
||||
if (emailInput) {
|
||||
emailInput.value = data.email || '';
|
||||
}
|
||||
if (resetBtn) {
|
||||
resetBtn.disabled = !data.email;
|
||||
}
|
||||
if (resetSupportEl) {
|
||||
if (!data.emailDeliveryConfigured) {
|
||||
resetSupportEl.textContent = 'Password reset email is ready in the app, but the server still needs SMTP configured for [email protected] before it can send mail.';
|
||||
} else if (!data.email) {
|
||||
resetSupportEl.textContent = 'Add your email address first, then you can send yourself a reset link from this page.';
|
||||
} else {
|
||||
resetSupportEl.textContent = `Reset emails will be sent to ${data.email} from [email protected] once mail delivery is configured with that sender.`;
|
||||
}
|
||||
}
|
||||
setOverviewStatus('');
|
||||
}).catch(err=>{
|
||||
console.error(err);
|
||||
@@ -3065,54 +3038,22 @@
|
||||
});
|
||||
}
|
||||
|
||||
if (emailForm) {
|
||||
emailForm.addEventListener('submit', function(ev){
|
||||
ev.preventDefault();
|
||||
const email = String(emailInput ? emailInput.value : '').trim().toLowerCase();
|
||||
if (!FEDL_EMAIL_RE.test(email)) {
|
||||
setEmailStatus('Enter a valid email address.', 'error');
|
||||
return;
|
||||
}
|
||||
setEmailStatus('Saving your email…');
|
||||
fetch(liveApiPath('/api/account'), {
|
||||
method: 'PUT',
|
||||
headers: authHeaders(),
|
||||
body: JSON.stringify({ email })
|
||||
}).then(async r=>{
|
||||
const { message } = await fedlReadJsonResponse(r);
|
||||
if (!r.ok) {
|
||||
throw new Error(message || 'Could not update email.');
|
||||
}
|
||||
setEmailStatus('Email updated.', 'success');
|
||||
if (resetBtn) {
|
||||
resetBtn.disabled = false;
|
||||
}
|
||||
if (resetSupportEl) {
|
||||
resetSupportEl.textContent = `Reset emails will be sent to ${email} from [email protected] once mail delivery is configured with that sender.`;
|
||||
}
|
||||
}).catch(err=>{
|
||||
console.error(err);
|
||||
setEmailStatus(err.message || 'Could not update email.', 'error');
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
if (resetBtn) {
|
||||
resetBtn.addEventListener('click', function(){
|
||||
resetBtn.disabled = true;
|
||||
setResetStatus('Sending reset email…');
|
||||
setResetStatus('Sending reset code to your messages…');
|
||||
fetch(liveApiPath('/api/account/password-reset-email'), {
|
||||
method: 'POST',
|
||||
headers: { Authorization: `Bearer ${fedlGetAuthToken()}` }
|
||||
}).then(async r=>{
|
||||
const { message } = await fedlReadJsonResponse(r);
|
||||
if (!r.ok) {
|
||||
throw new Error(message || 'Could not send reset email.');
|
||||
throw new Error(message || 'Could not send reset code.');
|
||||
}
|
||||
setResetStatus('Reset email sent. Check your inbox for a link from [email protected].', 'success');
|
||||
setResetStatus('Reset code sent! Check your messages.', 'success');
|
||||
}).catch(err=>{
|
||||
console.error(err);
|
||||
setResetStatus(err.message || 'Could not send reset email.', 'error');
|
||||
setResetStatus(err.message || 'Could not send reset code.', 'error');
|
||||
}).finally(()=>{
|
||||
resetBtn.disabled = false;
|
||||
});
|
||||
@@ -3212,11 +3153,14 @@
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ identifier })
|
||||
}).then(async r=>{
|
||||
const { message } = await fedlReadJsonResponse(r);
|
||||
const data = await fedlReadJsonResponse(r);
|
||||
if (!r.ok) {
|
||||
throw new Error(message || 'Could not request password reset.');
|
||||
throw new Error(data.message || 'Could not request password reset.');
|
||||
}
|
||||
setRequestStatus(data.message || 'Check your messages for the reset code.', 'success');
|
||||
if (requestInput) {
|
||||
requestInput.value = '';
|
||||
}
|
||||
setRequestStatus('If that account has an email on file, we sent a reset link.', 'success');
|
||||
}).catch(err=>{
|
||||
console.error(err);
|
||||
setRequestStatus(err.message || 'Could not request password reset.', 'error');
|
||||
@@ -3239,7 +3183,7 @@
|
||||
const newPassword = String(qs('reset-new-password').value || '');
|
||||
const confirmPassword = String(qs('reset-confirm-password').value || '');
|
||||
if (!token) {
|
||||
setResetPasswordStatus('Paste the reset token or open the link from your email.', 'error');
|
||||
setResetPasswordStatus('Paste the reset code below.', 'error');
|
||||
return;
|
||||
}
|
||||
if (newPassword.length < 8) {
|
||||
|
||||
+54
-14
@@ -24,6 +24,8 @@
|
||||
.dm-message{padding:12px 16px;border-radius:12px;max-width:70%;word-wrap:break-word}
|
||||
.dm-message.sent{background:var(--accent);color:#042;align-self:flex-end;border-bottom-right-radius:4px}
|
||||
.dm-message.received{background:rgba(255,255,255,0.1);align-self:flex-start;border-bottom-left-radius:4px}
|
||||
.dm-message.system{background:rgba(255,184,77,0.12);border:1px solid rgba(255,184,77,0.25);align-self:stretch;max-width:90%}
|
||||
.dm-message.system .dm-message-content{white-space:pre-wrap}
|
||||
.dm-message-time{font-size:0.7rem;opacity:0.7;margin-top:4px}
|
||||
.dm-input-row{display:flex;gap:12px;padding:16px;border-top:1px solid rgba(255,255,255,0.1)}
|
||||
.dm-input-row input{flex:1;padding:12px;border-radius:8px;border:1px solid rgba(255,255,255,0.1);background:rgba(255,255,255,0.05);color:var(--text);font-size:1rem}
|
||||
@@ -159,17 +161,35 @@
|
||||
|
||||
function renderConversations() {
|
||||
const list = document.getElementById('conversationsList');
|
||||
if (!conversations.length) {
|
||||
|
||||
const hasSystemMessages = conversations.some(c => c.userId === 'system');
|
||||
const userConversations = conversations.filter(c => c.userId !== 'system');
|
||||
|
||||
let html = '';
|
||||
|
||||
if (hasSystemMessages) {
|
||||
html += `
|
||||
<div class="dm-conversation system ${selectedConversation === 'system' ? 'active' : ''}" data-user="system" style="border-left: 3px solid var(--accent-warm);">
|
||||
<div class="dm-conversation-name" style="color: var(--accent-warm);">System Notifications</div>
|
||||
<div class="dm-conversation-preview">Password resets and alerts</div>
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
|
||||
if (!userConversations.length && !hasSystemMessages) {
|
||||
list.innerHTML = '<div class="empty-state">No conversations yet</div>';
|
||||
return;
|
||||
}
|
||||
list.innerHTML = conversations.map(c => `
|
||||
|
||||
html += userConversations.map(c => `
|
||||
<div class="dm-conversation ${c.unreadCount > 0 ? 'unread' : ''} ${selectedConversation === c.userId ? 'active' : ''}" data-user="${escapeHtml(c.userId)}">
|
||||
<div class="dm-conversation-name">${escapeHtml(c.username)}</div>
|
||||
<div class="dm-conversation-preview">${escapeHtml(c.lastMessage.content)}</div>
|
||||
<div class="dm-conversation-time">${formatDate(c.lastMessage.timestamp)}</div>
|
||||
</div>
|
||||
`).join('');
|
||||
|
||||
list.innerHTML = html;
|
||||
list.querySelectorAll('.dm-conversation').forEach(el => {
|
||||
el.addEventListener('click', () => selectConversation(el.dataset.user));
|
||||
});
|
||||
@@ -177,11 +197,25 @@
|
||||
|
||||
function selectConversation(userId) {
|
||||
selectedConversation = userId;
|
||||
const conv = conversations.find(c => c.userId === userId);
|
||||
document.getElementById('chatWithName').textContent = conv ? conv.username : 'Chat';
|
||||
document.getElementById('messageInputRow').hidden = false;
|
||||
if (userId === 'system') {
|
||||
document.getElementById('chatWithName').textContent = 'System Notifications';
|
||||
document.getElementById('messageInputRow').hidden = true;
|
||||
loadSystemMessages();
|
||||
} else {
|
||||
const conv = conversations.find(c => c.userId === userId);
|
||||
document.getElementById('chatWithName').textContent = conv ? conv.username : 'Chat';
|
||||
document.getElementById('messageInputRow').hidden = false;
|
||||
loadMessages(userId);
|
||||
}
|
||||
renderConversations();
|
||||
loadMessages(userId);
|
||||
}
|
||||
|
||||
function loadSystemMessages() {
|
||||
api('/api/messages/system').then(res => {
|
||||
if (res.ok && res.data && res.data.messages) {
|
||||
renderMessages(res.data.messages, true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function loadMessages(userId) {
|
||||
@@ -192,18 +226,24 @@
|
||||
});
|
||||
}
|
||||
|
||||
function renderMessages(messages) {
|
||||
function renderMessages(messages, isSystem = false) {
|
||||
const list = document.getElementById('messagesList');
|
||||
if (!messages.length) {
|
||||
list.innerHTML = '<div class="empty-state">No messages yet. Start the conversation!</div>';
|
||||
list.innerHTML = '<div class="empty-state">No messages yet.</div>';
|
||||
return;
|
||||
}
|
||||
list.innerHTML = messages.map(m => `
|
||||
<div class="dm-message ${m.fromUserId === currentUserId ? 'sent' : 'received'}">
|
||||
<div class="dm-message-content">${escapeHtml(m.content)}</div>
|
||||
<div class="dm-message-time">${formatDate(m.timestamp)}</div>
|
||||
</div>
|
||||
`).join('');
|
||||
list.innerHTML = messages.map(m => {
|
||||
const isCode = m.type === 'password_reset';
|
||||
const content = isCode
|
||||
? `<strong style="color: var(--accent); font-family: monospace; font-size: 1.1em; display: block; margin: 8px 0; padding: 10px; background: rgba(255,255,255,0.1); border-radius: 8px; word-break: break-all;">${escapeHtml(m.content)}</strong>`
|
||||
: escapeHtml(m.content);
|
||||
return `
|
||||
<div class="dm-message ${isSystem ? 'system' : (m.fromUserId === currentUserId ? 'sent' : 'received')}" style="${isSystem ? 'background: rgba(255,184,77,0.15); border: 1px solid rgba(255,184,77,0.3); max-width: 85%;' : ''}">
|
||||
<div class="dm-message-content">${content}</div>
|
||||
<div class="dm-message-time">${formatDate(m.timestamp)}</div>
|
||||
</div>
|
||||
`;
|
||||
}).join('');
|
||||
list.scrollTop = list.scrollHeight;
|
||||
}
|
||||
|
||||
|
||||
+10
-9
@@ -21,26 +21,27 @@
|
||||
<main class="account-main">
|
||||
<section class="panel account-panel">
|
||||
<p class="hero-kicker">FEDL account</p>
|
||||
<h2>Request a reset link</h2>
|
||||
<p class="muted">Enter your username or email and FEDL will send a reset link to the email saved on that account.</p>
|
||||
<h2>Request a reset code</h2>
|
||||
<p class="muted">Enter your username to get a reset code sent to your messages.</p>
|
||||
<form id="reset-request-form" class="auth-form">
|
||||
<label class="admin-password-field" for="reset-identifier">
|
||||
<span>Username or email</span>
|
||||
<input id="reset-identifier" name="identifier" type="text" autocomplete="username email" required />
|
||||
<span>Username</span>
|
||||
<input id="reset-identifier" name="identifier" type="text" autocomplete="username" required />
|
||||
</label>
|
||||
<p id="reset-request-status" class="muted" role="status"></p>
|
||||
<div class="auth-actions">
|
||||
<button type="submit" class="btn" id="reset-request-submit">Send reset link</button>
|
||||
<button type="submit" class="btn" id="reset-request-submit">Get reset code</button>
|
||||
</div>
|
||||
</form>
|
||||
</section>
|
||||
|
||||
<section class="panel account-panel">
|
||||
<h2>Use your reset link</h2>
|
||||
<p class="muted">If you opened the email link on this page, the token should already be filled in.</p>
|
||||
<section id="reset-section" class="panel account-panel" style="display:none;">
|
||||
<h2>Enter your reset code</h2>
|
||||
<p class="muted">Enter the reset code you received above.</p>
|
||||
<div id="reset-code-display" style="display:none;"></div>
|
||||
<form id="reset-password-form" class="auth-form">
|
||||
<label class="admin-password-field" for="reset-token">
|
||||
<span>Reset token</span>
|
||||
<span>Reset code</span>
|
||||
<input id="reset-token" name="token" type="text" autocomplete="off" required />
|
||||
</label>
|
||||
<label class="admin-password-field" for="reset-new-password">
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"2351d1fa28dc758a60b985808c2f3f40815cf067c8087cd99ea00f77b7d75832": {
|
||||
"userId": "usr_mnsa4u5y537c2d59",
|
||||
"expiresAt": "2026-04-10T04:30:30.954Z",
|
||||
"createdAt": "2026-04-10T03:30:30.954Z"
|
||||
},
|
||||
"d1e6f33eccdaa0777c7d4f161223bdeb4d95d94c9bed9911dd754e1c24f67719": {
|
||||
"userId": "usr_mnsa4u5y537c2d59",
|
||||
"expiresAt": "2026-04-10T04:30:55.992Z",
|
||||
"createdAt": "2026-04-10T03:30:55.992Z"
|
||||
},
|
||||
"c9480b7c2d3953a6ad4aa25760949762ad18f3b8388a21685d59bed395737a3b": {
|
||||
"userId": "usr_mnsa4u5y537c2d59",
|
||||
"expiresAt": "2026-04-10T04:31:30.517Z",
|
||||
"createdAt": "2026-04-10T03:31:30.517Z"
|
||||
},
|
||||
"b05688c574332c89ad3a0575185eb7e2725dc12b387913212162a375282e9d3a": {
|
||||
"userId": "usr_mnsa4u5y537c2d59",
|
||||
"expiresAt": "2026-04-10T04:46:39.467Z",
|
||||
"createdAt": "2026-04-10T03:46:39.467Z"
|
||||
}
|
||||
}
|
||||
+97
-87
@@ -1120,7 +1120,6 @@ const server = http.createServer((req, res) => {
|
||||
const payload = JSON.parse(body || '{}');
|
||||
const username = normalizeUsername(payload.username);
|
||||
const password = String(payload.password || '');
|
||||
const email = normalizeEmail(payload.email);
|
||||
if (!usernameOk(username)) {
|
||||
sendJson(res, 400, {
|
||||
error: 'Username must be 3-24 characters: lowercase letters, numbers, or underscore.'
|
||||
@@ -1136,27 +1135,18 @@ const server = http.createServer((req, res) => {
|
||||
sendJson(res, 409, { error: 'That username is already taken.' });
|
||||
return;
|
||||
}
|
||||
if (email && !emailOk(email)) {
|
||||
sendJson(res, 400, { error: 'Enter a valid email address.' });
|
||||
return;
|
||||
}
|
||||
if (email && users.some(u => u.email && u.email === email)) {
|
||||
sendJson(res, 409, { error: 'That email is already being used by another account.' });
|
||||
return;
|
||||
}
|
||||
const { salt, hash } = hashPassword(password);
|
||||
const id = `usr_${Date.now().toString(36)}${crypto.randomBytes(4).toString('hex')}`;
|
||||
users.push({
|
||||
id,
|
||||
username,
|
||||
email,
|
||||
passwordHash: hash,
|
||||
salt,
|
||||
createdAt: new Date().toISOString()
|
||||
});
|
||||
writeUsers(users);
|
||||
const token = createSession(id, username);
|
||||
sendJson(res, 201, { ok: true, token, userId: id, username, email });
|
||||
sendJson(res, 201, { ok: true, token, userId: id, username });
|
||||
} catch (error) {
|
||||
sendJson(res, 400, { error: 'Invalid signup request' });
|
||||
}
|
||||
@@ -1209,8 +1199,7 @@ const server = http.createServer((req, res) => {
|
||||
const user = users.find(u => u.id === sess.userId);
|
||||
sendJson(res, 200, {
|
||||
userId: sess.userId,
|
||||
username: sess.username,
|
||||
email: user && user.email ? user.email : ''
|
||||
username: sess.username
|
||||
});
|
||||
return;
|
||||
}
|
||||
@@ -1221,28 +1210,53 @@ const server = http.createServer((req, res) => {
|
||||
body += chunk;
|
||||
if (body.length > 65536) req.destroy();
|
||||
});
|
||||
req.on('end', async () => {
|
||||
req.on('end', () => {
|
||||
try {
|
||||
const payload = JSON.parse(body || '{}');
|
||||
const identifier = String(payload.identifier || '').trim().toLowerCase();
|
||||
if (!identifier) {
|
||||
sendJson(res, 400, { error: 'Enter your username or email address.' });
|
||||
sendJson(res, 400, { error: 'Enter your username.' });
|
||||
return;
|
||||
}
|
||||
const users = readUsers();
|
||||
const user = users.find(u =>
|
||||
u.username === identifier || (u.email && String(u.email).toLowerCase() === identifier)
|
||||
);
|
||||
if (user && user.email && (mailConfigured() || workerEmailConfigured())) {
|
||||
try {
|
||||
await sendPasswordResetEmail(req, user);
|
||||
} catch (error) {
|
||||
console.error(`[FEDL] Password reset request email failed: ${error.message}`);
|
||||
}
|
||||
const user = users.find(u => u.username === identifier);
|
||||
if (user) {
|
||||
const token = crypto.randomBytes(32).toString('hex');
|
||||
const tokenHash = hashToken(token);
|
||||
const resetTokens = readResetTokensRaw();
|
||||
const expiresAt = new Date(Date.now() + PASSWORD_RESET_TTL_MS).toISOString();
|
||||
resetTokens[tokenHash] = {
|
||||
userId: user.id,
|
||||
expiresAt,
|
||||
createdAt: new Date().toISOString()
|
||||
};
|
||||
writeResetTokens(cleanResetTokens(resetTokens));
|
||||
|
||||
const messages = readMessages();
|
||||
const newMessage = {
|
||||
id: `msg_${Date.now().toString(36)}${crypto.randomBytes(4).toString('hex')}`,
|
||||
fromUserId: 'system',
|
||||
fromUsername: 'FEDL System',
|
||||
toUserId: user.id,
|
||||
toUsername: user.username,
|
||||
content: `Your password reset code is: ${token}\n\nThis code expires in 1 hour. If you did not request a reset, you can ignore this message.`,
|
||||
timestamp: new Date().toISOString(),
|
||||
read: false,
|
||||
type: 'password_reset'
|
||||
};
|
||||
messages.unshift(newMessage);
|
||||
writeMessages(messages);
|
||||
sendEvent('messages-update', { userId: user.id });
|
||||
|
||||
sendJson(res, 200, {
|
||||
ok: true,
|
||||
message: 'Check your messages for the reset code.'
|
||||
});
|
||||
return;
|
||||
}
|
||||
sendJson(res, 200, {
|
||||
ok: true,
|
||||
message: 'If that account has a reset email configured, we sent a reset link.'
|
||||
message: 'If that account exists, a reset code has been sent to their messages.'
|
||||
});
|
||||
} catch (error) {
|
||||
console.error(`[FEDL] Password reset request failed: ${error.message}`);
|
||||
@@ -1264,7 +1278,7 @@ const server = http.createServer((req, res) => {
|
||||
const token = String(payload.token || '').trim();
|
||||
const newPassword = String(payload.newPassword || '');
|
||||
if (!token) {
|
||||
sendJson(res, 400, { error: 'Reset token is required.' });
|
||||
sendJson(res, 400, { error: 'Reset code is required.' });
|
||||
return;
|
||||
}
|
||||
if (newPassword.length < 8) {
|
||||
@@ -1275,7 +1289,7 @@ const server = http.createServer((req, res) => {
|
||||
const tokenHash = hashToken(token);
|
||||
const row = tokens[tokenHash];
|
||||
if (!row || !row.userId) {
|
||||
sendJson(res, 400, { error: 'That reset link is invalid or has expired.' });
|
||||
sendJson(res, 400, { error: 'That reset code is invalid or has expired.' });
|
||||
return;
|
||||
}
|
||||
const users = readUsers();
|
||||
@@ -1283,7 +1297,7 @@ const server = http.createServer((req, res) => {
|
||||
if (!user) {
|
||||
delete tokens[tokenHash];
|
||||
writeResetTokens(cleanResetTokens(tokens));
|
||||
sendJson(res, 400, { error: 'That reset link is invalid or has expired.' });
|
||||
sendJson(res, 400, { error: 'That reset code is invalid or has expired.' });
|
||||
return;
|
||||
}
|
||||
const { salt, hash } = hashPassword(newPassword);
|
||||
@@ -1318,50 +1332,7 @@ const server = http.createServer((req, res) => {
|
||||
sendJson(res, 200, {
|
||||
userId: user.id,
|
||||
username: user.username,
|
||||
email: user.email || '',
|
||||
createdAt: user.createdAt || '',
|
||||
passwordResetEmailEnabled: !!(user.email && (mailConfigured() || workerEmailConfigured())),
|
||||
emailDeliveryConfigured: mailConfigured() || workerEmailConfigured()
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if (req.method === 'PUT' && pathname === '/api/account') {
|
||||
const sess = getSessionFromRequest(req);
|
||||
if (!sess) {
|
||||
sendJson(res, 401, { error: 'Not signed in' });
|
||||
return;
|
||||
}
|
||||
let body = '';
|
||||
req.on('data', chunk => {
|
||||
body += chunk;
|
||||
if (body.length > 65536) req.destroy();
|
||||
});
|
||||
req.on('end', () => {
|
||||
try {
|
||||
const payload = JSON.parse(body || '{}');
|
||||
const email = normalizeEmail(payload.email);
|
||||
if (!emailOk(email)) {
|
||||
sendJson(res, 400, { error: 'Enter a valid email address.' });
|
||||
return;
|
||||
}
|
||||
const users = readUsers();
|
||||
const user = users.find(u => u.id === sess.userId);
|
||||
if (!user) {
|
||||
sendJson(res, 404, { error: 'Account not found' });
|
||||
return;
|
||||
}
|
||||
if (users.some(u => u.id !== user.id && u.email && u.email === email)) {
|
||||
sendJson(res, 409, { error: 'That email is already being used by another account.' });
|
||||
return;
|
||||
}
|
||||
user.email = email;
|
||||
user.updatedAt = new Date().toISOString();
|
||||
writeUsers(users);
|
||||
sendJson(res, 200, { ok: true, email });
|
||||
} catch (error) {
|
||||
sendJson(res, 400, { error: 'Invalid account update request' });
|
||||
}
|
||||
createdAt: user.createdAt || ''
|
||||
});
|
||||
return;
|
||||
}
|
||||
@@ -1418,26 +1389,40 @@ const server = http.createServer((req, res) => {
|
||||
sendJson(res, 401, { error: 'Not signed in' });
|
||||
return;
|
||||
}
|
||||
if (!mailConfigured() && !workerEmailConfigured()) {
|
||||
sendJson(res, 503, { error: 'Password reset email is not configured on the server yet.' });
|
||||
return;
|
||||
}
|
||||
const users = readUsers();
|
||||
const user = users.find(u => u.id === sess.userId);
|
||||
if (!user) {
|
||||
sendJson(res, 404, { error: 'Account not found' });
|
||||
return;
|
||||
}
|
||||
if (!user.email) {
|
||||
sendJson(res, 400, { error: 'Add an email address to your account before requesting a reset email.' });
|
||||
return;
|
||||
}
|
||||
sendPasswordResetEmail(req, user).then(result => {
|
||||
sendJson(res, 200, { ok: true, expiresAt: result.expiresAt });
|
||||
}).catch(error => {
|
||||
console.error(`[FEDL] Password reset email failed: ${error.message}`);
|
||||
sendJson(res, 500, { error: 'Could not send the reset email right now.' });
|
||||
});
|
||||
const token = crypto.randomBytes(32).toString('hex');
|
||||
const tokenHash = hashToken(token);
|
||||
const resetTokens = readResetTokensRaw();
|
||||
const expiresAt = new Date(Date.now() + PASSWORD_RESET_TTL_MS).toISOString();
|
||||
resetTokens[tokenHash] = {
|
||||
userId: user.id,
|
||||
expiresAt,
|
||||
createdAt: new Date().toISOString()
|
||||
};
|
||||
writeResetTokens(cleanResetTokens(resetTokens));
|
||||
|
||||
const messages = readMessages();
|
||||
const newMessage = {
|
||||
id: `msg_${Date.now().toString(36)}${crypto.randomBytes(4).toString('hex')}`,
|
||||
fromUserId: 'system',
|
||||
fromUsername: 'FEDL System',
|
||||
toUserId: user.id,
|
||||
toUsername: user.username,
|
||||
content: `Your password reset code is: ${token}\n\nThis code expires in 1 hour. If you did not request a reset, you can ignore this message.`,
|
||||
timestamp: new Date().toISOString(),
|
||||
read: false,
|
||||
type: 'password_reset'
|
||||
};
|
||||
messages.unshift(newMessage);
|
||||
writeMessages(messages);
|
||||
sendEvent('messages-update', { userId: user.id });
|
||||
|
||||
sendJson(res, 200, { ok: true, expiresAt });
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -2074,13 +2059,38 @@ const server = http.createServer((req, res) => {
|
||||
conversationsMap.get(otherId).unreadCount++;
|
||||
}
|
||||
});
|
||||
const conversations = Array.from(conversationsMap.values()).sort((a, b) =>
|
||||
let conversations = Array.from(conversationsMap.values()).sort((a, b) =>
|
||||
new Date(b.lastMessage.timestamp) - new Date(a.lastMessage.timestamp)
|
||||
);
|
||||
|
||||
const systemMessages = messages.filter(m => m.toUserId === sess.userId && m.fromUserId === 'system');
|
||||
if (systemMessages.length > 0) {
|
||||
const lastSystem = systemMessages.reduce((latest, m) =>
|
||||
new Date(m.timestamp) > new Date(latest.timestamp) ? m : latest
|
||||
, systemMessages[0]);
|
||||
const unreadSystem = systemMessages.filter(m => !m.read).length;
|
||||
conversations.unshift({
|
||||
userId: 'system',
|
||||
username: 'System',
|
||||
lastMessage: lastSystem,
|
||||
unreadCount: unreadSystem
|
||||
});
|
||||
}
|
||||
|
||||
sendJson(res, 200, { conversations });
|
||||
return;
|
||||
}
|
||||
|
||||
if (req.method === 'GET' && pathname === '/api/messages/system') {
|
||||
if (!sess) { sendJson(res, 401, { error: 'Login required' }); return; }
|
||||
const messages = readMessages();
|
||||
const systemMessages = messages.filter(m => m.toUserId === sess.userId && m.fromUserId === 'system')
|
||||
.sort((a, b) => new Date(b.timestamp) - new Date(a.timestamp));
|
||||
const unreadCount = systemMessages.filter(m => !m.read).length;
|
||||
sendJson(res, 200, { messages: systemMessages, unreadCount });
|
||||
return;
|
||||
}
|
||||
|
||||
if (req.method === 'GET' && pathname.startsWith('/api/messages/')) {
|
||||
if (!sess) { sendJson(res, 401, { error: 'Login required' }); return; }
|
||||
const otherUserId = pathname.slice('/api/messages/'.length);
|
||||
|
||||
+1
-6
@@ -24,18 +24,13 @@
|
||||
<section class="panel auth-panel">
|
||||
<p class="hero-kicker">FEDL account</p>
|
||||
<h2>Create an account</h2>
|
||||
<p class="muted">Username and password are stored on your FEDL server. Roulette progress and list % sync to the server when you are signed in.</p>
|
||||
<p class="muted">Username and password are stored on your FEDL server. Roulette progress and list % sync to the server when you are signed in. Password resets are sent via the app's messages.</p>
|
||||
<form id="signup-form" class="auth-form">
|
||||
<label class="admin-password-field" for="signup-username">
|
||||
<span>Username</span>
|
||||
<input id="signup-username" name="username" type="text" autocomplete="username" required minlength="3" maxlength="24" pattern="[a-z0-9_]{3,24}" placeholder="letters, numbers, underscore" />
|
||||
</label>
|
||||
<p class="muted small auth-hint">3–24 characters, lowercase letters, numbers, or underscore only.</p>
|
||||
<label class="admin-password-field" for="signup-email">
|
||||
<span>Email</span>
|
||||
<input id="signup-email" name="email" type="email" autocomplete="email" placeholder="Needed for password reset emails" />
|
||||
</label>
|
||||
<p class="muted small auth-hint">Optional now, but needed if you want FEDL to send password reset links.</p>
|
||||
<label class="admin-password-field" for="signup-password">
|
||||
<span>Password</span>
|
||||
<input id="signup-password" name="password" type="password" autocomplete="new-password" required minlength="8" placeholder="At least 8 characters" />
|
||||
|
||||
@@ -1,62 +0,0 @@
|
||||
# FEDL Email Worker
|
||||
|
||||
Handles incoming emails and can send emails using Cloudflare Workers Email.
|
||||
|
||||
## Setup
|
||||
|
||||
### 1. Configure Email Routing (Cloudflare Dashboard)
|
||||
|
||||
1. Go to **Email** → **Email Routing** in Cloudflare Dashboard
|
||||
2. Select your domain **fedl.site**
|
||||
3. Add an email address: `[email protected]`
|
||||
4. Create a routing rule:
|
||||
- **When**: A message is sent to `[email protected]`
|
||||
- **Then**: Route to **Worker** → `fedl-email-worker`
|
||||
|
||||
### 2. Deploy the Worker
|
||||
|
||||
```bash
|
||||
cd worker
|
||||
npm install
|
||||
npx wrangler deploy
|
||||
```
|
||||
|
||||
### 3. Configure Worker Bindings
|
||||
|
||||
In `wrangler.jsonc`, add:
|
||||
|
||||
```json
|
||||
{
|
||||
"name": "fedl-email-worker",
|
||||
"main": "src/index.ts",
|
||||
"compatibility_date": "2024-01-01",
|
||||
"vars": {
|
||||
"FORWARD_TO": "your-inbox@gmail.com"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 4. Environment Variables
|
||||
|
||||
| Variable | Purpose |
|
||||
|----------|---------|
|
||||
| `FORWARD_TO` | Email address to forward incoming emails to |
|
||||
| `SEND_EMAIL` | Cloudflare Email binding (auto-configured) |
|
||||
|
||||
## API Endpoints
|
||||
|
||||
### Send Email
|
||||
```
|
||||
POST /send
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"to": "user@example.com",
|
||||
"subject": "Password Reset",
|
||||
"text": "Click here to reset: ..."
|
||||
}
|
||||
```
|
||||
|
||||
### Update wrangler.jsonc for Cloudflare Pages/Workers
|
||||
|
||||
Make sure your `wrangler.jsonc` has the email binding configured in the Cloudflare dashboard under Workers & Pages → your worker → Settings → Variables.
|
||||
-6
@@ -1,6 +0,0 @@
|
||||
{
|
||||
"account": {
|
||||
"id": "b383c4fd325135e56323d694db7a06d3",
|
||||
"name": "[email protected]'s Account"
|
||||
}
|
||||
}
|
||||
-15
@@ -1,15 +0,0 @@
|
||||
{
|
||||
"name": "fedl-email-worker",
|
||||
"version": "1.0.0",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"node_modules/@cloudflare/workers-types": {
|
||||
"version": "4.20260410.1",
|
||||
"resolved": "https://registry.npmjs.org/@cloudflare/workers-types/-/workers-types-4.20260410.1.tgz",
|
||||
"integrity": "sha512-dPZT4aXxwhGHFhWA9iZhWVfFoO8g9exiLzeaS8y43Dw0Sard6Gb3o5LJjReav3ejHbQLHUfGEiZsRPGW8qmgMg==",
|
||||
"dev": true,
|
||||
"license": "MIT OR Apache-2.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
-14482
File diff suppressed because it is too large.
Load diff
-14430
File diff suppressed because it is too large.
Load diff
-14549
File diff suppressed because it is too large.
Load diff
-14497
File diff suppressed because it is too large.
Load diff
-14557
File diff suppressed because it is too large.
Load diff
-14505
File diff suppressed because it is too large.
Load diff
-14558
File diff suppressed because it is too large.
Load diff
-14506
File diff suppressed because it is too large.
Load diff
-14578
File diff suppressed because it is too large.
Load diff
-14526
File diff suppressed because it is too large.
Load diff
-14583
File diff suppressed because it is too large.
Load diff
-14531
File diff suppressed because it is too large.
Load diff
-14589
File diff suppressed because it is too large.
Load diff
-14537
File diff suppressed because it is too large.
Load diff
-14589
File diff suppressed because it is too large.
Load diff
-14537
File diff suppressed because it is too large.
Load diff
-135
@@ -1,135 +0,0 @@
|
||||
# Cloudflare Workers Types
|
||||
|
||||
> **Note**
|
||||
>
|
||||
> We now recommend using the [Wrangler CLI](https://www.npmjs.com/package/wrangler) and the `wrangler types` command to generate types based on your compatibility date _and_ compatibility flags. You can learn more about this, and how to migrate from @cloudflare/workers-types [here in our docs](https://developers.cloudflare.com/workers/languages/typescript/#generate-types).
|
||||
>
|
||||
> @cloudflare/workers-types will continue to be published on the same schedule.
|
||||
|
||||
|
||||
## Install
|
||||
|
||||
```bash
|
||||
npm install -D @cloudflare/workers-types
|
||||
-- Or
|
||||
yarn add -D @cloudflare/workers-types
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
The following is a minimal `tsconfig.json` for use alongside this package:
|
||||
|
||||
**`tsconfig.json`**
|
||||
|
||||
```json
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "esnext",
|
||||
"module": "esnext",
|
||||
"lib": ["esnext"],
|
||||
"types": ["@cloudflare/workers-types"]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Compatibility dates
|
||||
|
||||

|
||||
|
||||
The Cloudflare Workers runtime manages backwards compatibility through the use of [Compatibility Dates](https://developers.cloudflare.com/workers/platform/compatibility-dates/). Using different compatibility dates affects the runtime types available to your Worker, and so it's important you specify the correct entrypoint to the `workers-types` package to match your compatibility date (which is usually set in your `wrangler.toml` configuration file). `workers-types` currently exposes the following entrypoints to choose from:
|
||||
|
||||
- `@cloudflare/workers-types`
|
||||
|
||||
The default entrypoint exposes the runtime types for a compatibility date before `2021-11-03`.
|
||||
|
||||
- `@cloudflare/workers-types/2021-11-03`
|
||||
|
||||
This entrypoint exposes the runtime types for a compatibility date between `2021-11-03` and `2022-01-31`.
|
||||
|
||||
- `@cloudflare/workers-types/2022-01-31`
|
||||
|
||||
This entrypoint exposes the runtime types for a compatibility date between `2022-01-31` and `2022-03-21`.
|
||||
|
||||
- `@cloudflare/workers-types/2022-03-21`
|
||||
|
||||
This entrypoint exposes the runtime types for a compatibility date between `2022-03-21` and `2022-08-04`.
|
||||
|
||||
- `@cloudflare/workers-types/2022-08-04`
|
||||
|
||||
This entrypoint exposes the runtime types for a compatibility date between `2022-08-04` and `2022-10-31`.
|
||||
|
||||
- `@cloudflare/workers-types/2022-10-31`
|
||||
|
||||
This entrypoint exposes the runtime types for a compatibility date between `2022-10-31` and `2022-11-30`.
|
||||
|
||||
- `@cloudflare/workers-types/2022-11-30`
|
||||
|
||||
This entrypoint exposes the runtime types for a compatibility date between `2022-11-30` and `2023-03-01`.
|
||||
|
||||
- `@cloudflare/workers-types/2023-03-01`
|
||||
|
||||
This entrypoint exposes the runtime types for a compatibility date between `2023-03-01` and `2023-07-01`.
|
||||
|
||||
- `@cloudflare/workers-types/2023-07-01`
|
||||
|
||||
This entrypoint exposes the runtime types for a compatibility date after `2023-07-01`.
|
||||
|
||||
- `@cloudflare/workers-types/experimental`
|
||||
|
||||
This entrypoint exposes the runtime types for the latest compatibility date. The types exposed by this entrypoint will change over time to always reflect the latest version of the Workers runtime.
|
||||
|
||||
To use one of these entrypoints, you need to specify them in your `tsconfig.json`. For example, this is a sample `tsconfig.json` for using the `2022-08-04` entrypoint.
|
||||
|
||||
```json
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "esnext",
|
||||
"module": "esnext",
|
||||
"lib": ["esnext"],
|
||||
"types": ["@cloudflare/workers-types/2022-08-04"]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Importable Types
|
||||
|
||||
It's not always possible (or desirable) to modify the `tsconfig.json` settings for a project to include all the Cloudflare Workers types. For use cases like that, this package provides importable versions of its types, which are usable with no additional `tsconfig.json` setup. For example:
|
||||
|
||||
```ts
|
||||
import type { Request as WorkerRequest, ExecutionContext } from "@cloudflare/workers-types/experimental"
|
||||
|
||||
export default {
|
||||
fetch(request: WorkerRequest, env: unknown, ctx: ExecutionContext) {
|
||||
return new Response("OK")
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
### Using bindings
|
||||
|
||||
It's recommended that you create a type file for any bindings your Worker uses. Create a file named
|
||||
`worker-configuration.d.ts` in your src directory.
|
||||
|
||||
If you're using Module Workers, it should look like this:
|
||||
```typescript
|
||||
// worker-configuration.d.ts
|
||||
interface Env {
|
||||
MY_ENV_VAR: string;
|
||||
MY_SECRET: string;
|
||||
myKVNamespace: KVNamespace;
|
||||
}
|
||||
```
|
||||
For Service Workers, it should augment the global scope:
|
||||
```typescript
|
||||
// worker-configuration.d.ts
|
||||
declare global {
|
||||
const MY_ENV_VAR: string;
|
||||
const MY_SECRET: string;
|
||||
const myKVNamespace: KVNamespace;
|
||||
}
|
||||
export {}
|
||||
```
|
||||
|
||||
Wrangler can also generate this for you automatically from your `wrangler.toml` configuration file, using the `wrangler types` command.
|
||||
|
||||
-53
@@ -1,53 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<svg viewBox="0 0 540 280" width="540px" height="280px" xmlns="http://www.w3.org/2000/svg">
|
||||
<rect width="540" height="280" style="fill: rgb(255, 255, 255);"/>
|
||||
<g transform="matrix(1, 0, 0, 1, 61.018997, -319.418854)">
|
||||
<rect x="128.981" y="349.42" width="340" height="30" style="fill: rgb(238, 238, 238);"/>
|
||||
<text style="font-family: monospace; font-size: 14px; white-space: pre;" x="135.709" y="369.298">@cloudflare/workers-types</text>
|
||||
</g>
|
||||
<g transform="matrix(1, 0, 0, 1, 61.018997, -289.418793)">
|
||||
<rect x="128.981" y="349.42" width="340" height="30" style="fill: rgb(221, 221, 221);"/>
|
||||
<text style="font-family: monospace; font-size: 14px; white-space: pre;"><tspan x="135.709" y="369.298">@cloudflare/workers-types/</tspan><tspan style="fill: rgb(0, 85, 220); font-weight: 700;">2021-11-03</tspan></text>
|
||||
</g>
|
||||
<g transform="matrix(1, 0, 0, 1, 61.018997, -259.418793)">
|
||||
<rect x="128.981" y="349.42" width="340" height="30" style="fill: rgb(238, 238, 238);"/>
|
||||
<text style="font-family: monospace; font-size: 14px; white-space: pre;"><tspan x="135.709" y="369.298">@cloudflare/workers-types/</tspan><tspan style="fill: rgb(0, 54, 130); font-weight: 700;">2022-01-31</tspan></text>
|
||||
</g>
|
||||
<g transform="matrix(1, 0, 0, 1, 61.018997, -229.418869)">
|
||||
<rect x="128.981" y="349.42" width="340" height="30" style="fill: rgb(221, 221, 221);"/>
|
||||
<text style="font-family: monospace; font-size: 14px; white-space: pre;"><tspan x="135.709" y="369.298">@cloudflare/workers-types/</tspan><tspan style="fill: rgb(0, 85, 220); font-weight: 700;">2022-03-21</tspan></text>
|
||||
</g>
|
||||
<g transform="matrix(1, 0, 0, 1, 61.018997, -199.418839)">
|
||||
<rect x="128.981" y="349.42" width="340" height="30" style="fill: rgb(238, 238, 238);"/>
|
||||
<text style="font-family: monospace; font-size: 14px; white-space: pre;"><tspan x="135.709" y="369.298">@cloudflare/workers-types/</tspan><tspan style="fill: rgb(0, 54, 130); font-weight: 700;">2022-08-04</tspan></text>
|
||||
</g>
|
||||
<g transform="matrix(1, 0, 0, 1, 61.018997, -169.418839)">
|
||||
<rect x="128.981" y="349.42" width="340" height="30" style="fill: rgb(221, 221, 221);"/>
|
||||
<text style="font-family: monospace; font-size: 14px; white-space: pre;"><tspan x="135.709" y="369.298">@cloudflare/workers-types/</tspan><tspan style="fill: rgb(0, 85, 220); font-weight: 700;">2022-10-31</tspan></text>
|
||||
</g>
|
||||
<g transform="matrix(1, 0, 0, 1, 61.017925, -139.418854)">
|
||||
<rect x="128.981" y="349.42" width="340" height="30" style="fill: rgb(238, 238, 238);"/>
|
||||
<text style="font-family: monospace; font-size: 14px; white-space: pre;"><tspan x="135.709" y="369.298">@cloudflare/workers-types/</tspan><tspan style="fill: rgb(0, 54, 130); font-weight: 700;">2022-11-30</tspan></text>
|
||||
</g>
|
||||
<g transform="matrix(1, 0, 0, 1, 61.017925, -109.418816)">
|
||||
<rect x="128.981" y="349.42" width="340" height="30" style="fill: rgb(221, 221, 221);"/>
|
||||
<text style="font-family: monospace; font-size: 14px; white-space: pre;" x="135.709" y="369.298">@cloudflare/workers-types/experimental</text>
|
||||
</g>
|
||||
<line style="fill: rgb(216, 216, 216); stroke: rgb(0, 0, 0);" x1="160" y1="60" x2="190" y2="60"/>
|
||||
<line style="fill: rgb(216, 216, 216); stroke: rgb(0, 0, 0);" x1="160" y1="90" x2="190" y2="90"/>
|
||||
<line style="fill: rgb(216, 216, 216); stroke: rgb(0, 0, 0);" x1="160" y1="120" x2="190" y2="120"/>
|
||||
<line style="fill: rgb(216, 216, 216); stroke: rgb(0, 0, 0);" x1="160" y1="150" x2="190" y2="150"/>
|
||||
<line style="fill: rgb(216, 216, 216); stroke: rgb(0, 0, 0);" x1="160" y1="180" x2="190" y2="180"/>
|
||||
<line style="fill: rgb(216, 216, 216); stroke: rgb(0, 0, 0);" x1="160" y1="210" x2="190" y2="210"/>
|
||||
<line style="fill: rgb(216, 216, 216); stroke: rgb(0, 0, 0);" x1="175" y1="60" x2="175" y2="240"/>
|
||||
<line style="fill: rgb(216, 216, 216); stroke: rgb(0, 0, 0); stroke-dasharray: 2px;" x1="175" y1="30" x2="175" y2="60"/>
|
||||
<line style="fill: rgb(216, 216, 216); stroke: rgb(0, 0, 0); stroke-dasharray: 2px;" x1="175" y1="240" x2="175" y2="270"/>
|
||||
<text style="fill: rgb(51, 51, 51); font-family: monospace; font-size: 14px; font-weight: 700; text-anchor: middle; white-space: pre;" transform="matrix(1, 0, 0, 1, 307.347992, -77.253761)"><tspan x="52.652" y="98.052">types Entrypoint</tspan></text>
|
||||
<text style="fill: rgb(51, 51, 51); font-family: monospace; font-size: 14px; font-weight: 700; text-anchor: end; white-space: pre;" x="157.185" y="20.798">compatibility_date</text>
|
||||
<text style="fill: rgb(0, 85, 220); font-family: monospace; font-size: 14px; font-weight: 700; text-anchor: end; white-space: pre;" x="153.994" y="64.798">2021-11-03</text>
|
||||
<text style="fill: rgb(0, 54, 130); font-family: monospace; font-size: 14px; font-weight: 700; text-anchor: end; white-space: pre;" x="153.994" y="94.798">2022-01-31</text>
|
||||
<text style="fill: rgb(0, 85, 220); font-family: monospace; font-size: 14px; font-weight: 700; text-anchor: end; white-space: pre;" x="153.994" y="124.798">2022-03-21</text>
|
||||
<text style="fill: rgb(0, 54, 130); font-family: monospace; font-size: 14px; font-weight: 700; text-anchor: end; white-space: pre;" x="153.994" y="154.798">2022-08-04</text>
|
||||
<text style="fill: rgb(0, 85, 220); font-family: monospace; font-size: 14px; font-weight: 700; text-anchor: end; white-space: pre;" x="153.994" y="184.798">2022-10-31</text>
|
||||
<text style="fill: rgb(0, 54, 130); font-family: monospace; font-size: 14px; font-weight: 700; text-anchor: end; white-space: pre;" x="153.994" y="214.798">2022-11-30</text>
|
||||
</svg>
|
||||
|
Before Width: | Height: | Size: 5.4 KiB |
-15314
File diff suppressed because it is too large.
Load diff
-15262
File diff suppressed because it is too large.
Load diff
-14482
File diff suppressed because it is too large.
Load diff
-14430
File diff suppressed because it is too large.
Load diff
-14622
File diff suppressed because it is too large.
Load diff
-14570
File diff suppressed because it is too large.
Load diff
-14482
File diff suppressed because it is too large.
Load diff
-14430
File diff suppressed because it is too large.
Load diff
-11
@@ -1,11 +0,0 @@
|
||||
{
|
||||
"name": "@cloudflare/workers-types",
|
||||
"description": "TypeScript typings for Cloudflare Workers",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/cloudflare/workerd"
|
||||
},
|
||||
"author": "Cloudflare Workers DevProd Team <[email protected]> (https://workers.cloudflare.com)",
|
||||
"license": "MIT OR Apache-2.0",
|
||||
"version": "4.20260410.1"
|
||||
}
|
||||
Generated
-22
@@ -1,22 +0,0 @@
|
||||
{
|
||||
"name": "fedl-email-worker",
|
||||
"version": "1.0.0",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "fedl-email-worker",
|
||||
"version": "1.0.0",
|
||||
"devDependencies": {
|
||||
"@cloudflare/workers-types": "^4.20241127.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@cloudflare/workers-types": {
|
||||
"version": "4.20260410.1",
|
||||
"resolved": "https://registry.npmjs.org/@cloudflare/workers-types/-/workers-types-4.20260410.1.tgz",
|
||||
"integrity": "sha512-dPZT4aXxwhGHFhWA9iZhWVfFoO8g9exiLzeaS8y43Dw0Sard6Gb3o5LJjReav3ejHbQLHUfGEiZsRPGW8qmgMg==",
|
||||
"dev": true,
|
||||
"license": "MIT OR Apache-2.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
{
|
||||
"name": "fedl-email-worker",
|
||||
"version": "1.0.0",
|
||||
"private": true,
|
||||
"devDependencies": {
|
||||
"@cloudflare/workers-types": "^4.20241127.0"
|
||||
}
|
||||
}
|
||||
Vendored
-3
@@ -1,3 +0,0 @@
|
||||
export interface Env {
|
||||
FORWARD_TO: string;
|
||||
}
|
||||
@@ -1,66 +0,0 @@
|
||||
export default {
|
||||
async email(message, env, ctx) {
|
||||
const subject = message.headers.get('subject') || 'No Subject';
|
||||
const from = message.from;
|
||||
const to = message.to;
|
||||
|
||||
console.log(`[FEDL Email] Received email from: ${from}, to: ${to}, subject: ${subject}`);
|
||||
|
||||
const forwardedAddress = env.FORWARD_TO || '';
|
||||
|
||||
if (forwardedAddress) {
|
||||
await message.forward(forwardedAddress);
|
||||
console.log(`[FEDL Email] Forwarded to: ${forwardedAddress}`);
|
||||
} else {
|
||||
console.log(`[FEDL Email] No forwarding address configured (FORWARD_TO not set)`);
|
||||
}
|
||||
},
|
||||
|
||||
async fetch(request: Request, env: Env): Promise<Response> {
|
||||
const url = new URL(request.url);
|
||||
|
||||
if (url.pathname === '/send' && request.method === 'POST') {
|
||||
const body = await request.json() as { to: string; subject: string; text: string };
|
||||
|
||||
if (!body.to || !body.subject || !body.text) {
|
||||
return new Response(JSON.stringify({ error: 'Missing to, subject, or text' }), {
|
||||
status: 400,
|
||||
headers: { 'Content-Type': 'application/json' }
|
||||
});
|
||||
}
|
||||
|
||||
try {
|
||||
if (env.SEND_EMAIL) {
|
||||
await env.SEND_EMAIL.send({
|
||||
from: `FEDL <[email protected]>`,
|
||||
to: body.to,
|
||||
subject: body.subject,
|
||||
text: body.text,
|
||||
});
|
||||
} else {
|
||||
throw new Error('SEND_EMAIL binding not configured. Go to Workers & Pages → your worker → Settings → Bindings to add it.');
|
||||
}
|
||||
|
||||
return new Response(JSON.stringify({ ok: true }), {
|
||||
status: 200,
|
||||
headers: { 'Content-Type': 'application/json' }
|
||||
});
|
||||
} catch (error: any) {
|
||||
console.error(`[FEDL Email] Send failed: ${error.message}`);
|
||||
return new Response(JSON.stringify({ error: error.message }), {
|
||||
status: 500,
|
||||
headers: { 'Content-Type': 'application/json' }
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return new Response('FEDL Email Worker\n', { status: 200 });
|
||||
}
|
||||
} satisfies ExportedHandler<Env>;
|
||||
|
||||
interface Env {
|
||||
SEND_EMAIL?: {
|
||||
send(options: { from: string; to: string; subject: string; text: string }): Promise<void>;
|
||||
};
|
||||
FORWARD_TO: string;
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
{
|
||||
"name": "fedl-email-worker",
|
||||
"main": "src/index.ts",
|
||||
"compatibility_date": "2024-01-01"
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
name = "fedl-email-worker"
|
||||
main = "src/index.ts"
|
||||
compatibility_date = "2024-01-01"
|
||||
|
||||
[vars]
|
||||
FORWARD_TO = ""
|
||||
Reference in new issue
Block a user