Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -1408,7 +1408,10 @@ document.addEventListener('DOMContentLoaded', () => {
renderFocusTasks();
});
}

document.getElementById('cal-prev').addEventListener('click', () => {
currentMonthDate.setMonth(currentMonthDate.getMonth() - 1);
renderCalendar();
});
document.getElementById('cal-next').addEventListener('click', () => {
currentMonthDate.setMonth(currentMonthDate.getMonth() + 1);
renderCalendar();
Expand Down
10 changes: 10 additions & 0 deletions js/utils/nlpDateExtractor.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,16 @@ function matchAbsoluteDate(lower, now) {
return toISO(startOf(resolveYear(now, month, day)));
}

m = lower.match(/\b(\d{4})[\/\-\.](\d{1,2})[\/\-\.](\d{1,2})\b/);

if (m) {
const year = parseInt(m[1]);
const month = parseInt(m[2]) - 1;
const day = parseInt(m[3]);

return toISO(startOf(new Date(year, month, day)));
}

m = lower.match(/\b(\d{1,2})[\/\-\.](\d{1,2})(?:[\/\-\.](\d{2,4}))?\b/);
if (m) {
const day = parseInt(m[1]);
Expand Down
46 changes: 35 additions & 11 deletions server.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require('dotenv').config();
const express = require('express');
const cors = require('cors');
const bcrypt = require('bcrypt');
const { db, initDb } = require('./database');
const { GoogleGenAI } = require('@google/genai');
const path = require('path');
Expand Down Expand Up @@ -74,12 +75,12 @@ const NLP_MONTHS = {
oct:9,october:9,nov:10,november:10,dec:11,december:11
};

function nlpResolveYear(now, month, day, explicitYear = null) {
if (explicitYear) return new Date(explicitYear, month, day);
const c = new Date(now.getFullYear(), month, day);
if (c < now) c.setFullYear(c.getFullYear() + 1);
return c;
}
function nlpResolveYear(now, month, day, explicitYear = null) {
if (explicitYear) return new Date(explicitYear, month, day);
const c = new Date(now.getFullYear(), month, day);
if (c < now) c.setFullYear(c.getFullYear() + 1);
return c;
}

function nlpExtractDate(text, now = new Date()) {
const lower = text.toLowerCase();
Expand Down Expand Up @@ -117,6 +118,19 @@ function nlpExtractDate(text, now = new Date()) {
m = lower.match(new RegExp(`\\b${ord}\\s+(${monthNames})\\b`));
if (m) return nlpWithTime(nlpStartOf(nlpResolveYear(now, NLP_MONTHS[m[2]], parseInt(m[1]))).toISOString(), time);

m = lower.match(/\b(\d{4})[\/\-\.](\d{1,2})[\/\-\.](\d{1,2})\b/);

if (m) {
const year = parseInt(m[1]);
const month = parseInt(m[2]) - 1;
const day = parseInt(m[3]);

return nlpWithTime(
nlpStartOf(new Date(year, month, day)).toISOString(),
time
);
}

m = lower.match(/\b(\d{1,2})[\/\-\.](\d{1,2})(?:[\/\-\.](\d{2,4}))?\b/);
if (m) {
const day = parseInt(m[1]), month = parseInt(m[2]) - 1;
Expand Down Expand Up @@ -555,7 +569,7 @@ Text: "${text}"
// ================= AUTH =================

// SIGNUP
app.post('/api/auth/signup', (req, res) => {
app.post('/api/auth/signup', async(req, res) => {
const { email, password } = req.body;

if (!email || !password) {
Expand All @@ -566,10 +580,11 @@ app.post('/api/auth/signup', (req, res) => {

const id = 'user_' + Date.now();

const hashedPassword = await bcrypt.hash(password, 10);
db.run(
`INSERT INTO users (id, email, password)
VALUES (?, ?, ?)`,
[id, email, password],
[id, email, hashedPassword],
function(err) {

if (err) {
Expand All @@ -594,7 +609,7 @@ app.post('/api/auth/signup', (req, res) => {
});

// LOGIN
app.post('/api/auth/login', (req, res) => {
app.post('/api/auth/login',async (req, res) => {
const { email, password } = req.body;

if (!email || !password) {
Expand All @@ -606,20 +621,29 @@ app.post('/api/auth/login', (req, res) => {
db.get(
`SELECT * FROM users WHERE email = ?`,
[email],
(err, user) => {
async (err, user) => {

if (err) {
return res.status(500).json({
error: err.message
});
}

if (!user || user.password !== password) {
if (!user) {
return res.status(401).json({
error: 'Invalid email or password'
});
}
const isValid = await bcrypt.compare(
password,
user.password
);

if (!isValid) {
return res.status(401).json({
error: 'Invalid email or password'
});
}
res.json({
success: true,
email: user.email
Expand Down