Skip to content

Commit

Permalink
Merge branch 'julianpoy:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
levyitay authored Apr 6, 2024
2 parents 584d8b8 + 963fea6 commit 02ea2b3
Show file tree
Hide file tree
Showing 94 changed files with 2,687 additions and 1,476 deletions.
7 changes: 2 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,8 @@ WORKDIR /app
# mdbtools
RUN apk add --no-cache mdbtools mdbtools-utils

# node-gyp
RUN apk add --no-cache python3 make clang build-base

# node canvas
RUN apk add --no-cache build-base g++ cairo-dev jpeg-dev pango-dev giflib-dev
# pdftotext
RUN apk add --no-cache poppler-utils

# dev watch script
RUN apk add --no-cache inotify-tools
Expand Down
1,001 changes: 517 additions & 484 deletions package-lock.json

Large diffs are not rendered by default.

10 changes: 4 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
"@capacitor/ios": "5.5.1",
"@capawesome/capacitor-file-picker": "^5.3.0",
"@elastic/elasticsearch": "~8.10.0",
"@fanoutio/grip": "^3.3.1",
"@fanoutio/serve-grip": "^1.3.1",
"@google-cloud/vision": "^4.0.2",
"@ionic/angular": "^7.7.3",
"@julianpoy/recipe-clipper": "^3.1.0",
Expand All @@ -35,22 +37,19 @@
"@trpc/server": "^10.43.6",
"axios": "^1.6.8",
"body-parser": "~1.20.2",
"canvas": "^2.11.2",
"commander": "^11.1.0",
"cookie-parser": "^1.4.6",
"core-js": "^3.33.2",
"cors": "^2.8.5",
"dayjs": "^1.11.10",
"debug": "~4.3.4",
"express": "~4.18.2",
"express-grip": "^1.2.1",
"express": "~4.19.2",
"extract-zip": "^2.0.1",
"firebase": "^10.8.1",
"firebase-admin": "^11.11.0",
"fraction.js": "^4.3.7",
"fs-extra": "^11.1.1",
"google-auth-library": "^9.4.2",
"grip": "^1.5.0",
"he": "^1.2.0",
"https-proxy-agent": "^7.0.2",
"ical-generator": "^6.0.0",
Expand All @@ -67,7 +66,6 @@
"node-fetch": "^2.6.7",
"openai": "^4.24.1",
"p-limit": "^3.1.0",
"pdfjs-dist": "^3.11.174",
"pdfmake": "^0.2.8",
"pg": "8.11.3",
"pg-hstore": "^2.3.4",
Expand Down Expand Up @@ -95,7 +93,7 @@
},
"devDependencies": {
"@angular-devkit/architect": "0.1701.0",
"@angular-devkit/build-angular": "17.2.0",
"@angular-devkit/build-angular": "17.3.2",
"@angular-devkit/core": "17.1.0",
"@angular-devkit/schematics": "17.1.0",
"@angular-eslint/builder": "17.2.1",
Expand Down
2 changes: 0 additions & 2 deletions packages/backend/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import clip from "./routes/clip.js";
import data from "./routes/data.js";
import proxy from "./routes/proxy.js";

import ws from "./routes/ws.js";
import { ErrorRequestHandler } from "express";

const app = express();
Expand Down Expand Up @@ -91,7 +90,6 @@ app.use("/images", images);
app.use("/clip", clip);
app.use("/proxy", proxy);
app.use("/data", data);
app.use("/ws", ws);

// catch 404 and forward to error handler
app.use(function (req, res, next) {
Expand Down
4 changes: 4 additions & 0 deletions packages/backend/src/models/mealplanitem.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ export const MealPlanItemInit = (sequelize, DataTypes) => {
allowNull: false,
},
scheduled: {
type: DataTypes.DATE,
allowNull: true,
},
scheduledDate: {
type: DataTypes.DATE,
allowNull: false,
},
Expand Down
141 changes: 20 additions & 121 deletions packages/backend/src/routes/mealPlans.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import * as express from "express";
const router = express.Router();
import * as cors from "cors";
import ical from "ical-generator";

// DB
import { Op } from "sequelize";
Expand All @@ -18,7 +17,7 @@ import {

// Service
import * as MiddlewareService from "../services/middleware.js";
import * as GripService from "../services/grip.js";
import { broadcastWSEvent } from "@recipesage/util/server/general";

// Util
import { wrapRequestWithErrorHandler } from "../utils/wrapRequestWithErrorHandler.js";
Expand Down Expand Up @@ -49,7 +48,7 @@ router.post(
});

for (let i = 0; i < (req.body.collaborators || []).length; i++) {
GripService.broadcast(req.body.collaborators[i], "mealPlan:received", {
broadcastWSEvent(req.body.collaborators[i], "mealPlan:received", {
mealPlanId: mealPlan.id,
from: {
id: res.locals.user.id,
Expand Down Expand Up @@ -165,9 +164,14 @@ router.post(
);
}

// REST api does not support new date format
const legacyScheduled = new Date(req.body.scheduled);
const legacyScheduledDate = legacyScheduled.toISOString().split("T")[0];

await MealPlanItem.create({
title: req.body.title,
scheduled: new Date(req.body.scheduled),
scheduled: legacyScheduled,
scheduledDate: legacyScheduledDate,
meal: req.body.meal,
recipeId: req.body.recipeId || null,
userId: res.locals.session.userId,
Expand All @@ -186,13 +190,13 @@ router.post(
reference,
};

GripService.broadcast(
broadcastWSEvent(
mealPlan.userId,
"mealPlan:itemsUpdated",
broadcastPayload,
);
for (let i = 0; i < mealPlan.collaborators.length; i++) {
GripService.broadcast(
broadcastWSEvent(
mealPlan.collaborators[i].id,
"mealPlan:itemsUpdated",
broadcastPayload,
Expand Down Expand Up @@ -236,7 +240,7 @@ router.delete(
if (mealPlan.userId === res.locals.session.userId) {
await mealPlan.destroy();
for (let i = 0; i < (mealPlan.collaborators || []).length; i++) {
GripService.broadcast(mealPlan.collaborators[i], "mealPlan:removed", {
broadcastWSEvent(mealPlan.collaborators[i], "mealPlan:removed", {
mealPlanId: mealPlan.id,
updatedBy: {
id: res.locals.user.id,
Expand Down Expand Up @@ -300,13 +304,13 @@ router.delete(
reference,
};

GripService.broadcast(
broadcastWSEvent(
mealPlan.userId,
"mealPlan:itemsUpdated",
deletedItemBroadcast,
);
for (let i = 0; i < mealPlan.collaborators.length; i++) {
GripService.broadcast(
broadcastWSEvent(
mealPlan.collaborators[i].id,
"mealPlan:itemsUpdated",
deletedItemBroadcast,
Expand Down Expand Up @@ -382,13 +386,9 @@ router.put(
reference,
};

GripService.broadcast(
mealPlan.userId,
"mealPlan:itemsUpdated",
updateBroadcast,
);
broadcastWSEvent(mealPlan.userId, "mealPlan:itemsUpdated", updateBroadcast);
for (let i = 0; i < mealPlan.collaborators.length; i++) {
GripService.broadcast(
broadcastWSEvent(
mealPlan.collaborators[i].id,
"mealPlan:itemsUpdated",
updateBroadcast,
Expand Down Expand Up @@ -460,13 +460,9 @@ router.post(
reference,
};

GripService.broadcast(
mealPlan.userId,
"mealPlan:itemsUpdated",
updateBroadcast,
);
broadcastWSEvent(mealPlan.userId, "mealPlan:itemsUpdated", updateBroadcast);
for (let i = 0; i < mealPlan.collaborators.length; i++) {
GripService.broadcast(
broadcastWSEvent(
mealPlan.collaborators[i].id,
"mealPlan:itemsUpdated",
updateBroadcast,
Expand Down Expand Up @@ -536,13 +532,9 @@ router.delete(
reference,
};

GripService.broadcast(
mealPlan.userId,
"mealPlan:itemsUpdated",
updateBroadcast,
);
broadcastWSEvent(mealPlan.userId, "mealPlan:itemsUpdated", updateBroadcast);
for (let i = 0; i < mealPlan.collaborators.length; i++) {
GripService.broadcast(
broadcastWSEvent(
mealPlan.collaborators[i].id,
"mealPlan:itemsUpdated",
updateBroadcast,
Expand Down Expand Up @@ -605,6 +597,7 @@ router.get(
"id",
"title",
"scheduled",
"scheduledDate",
"meal",
"createdAt",
"updatedAt",
Expand Down Expand Up @@ -648,98 +641,4 @@ router.get(
}),
);

// Get ical for meal plan
router.get(
"/:mealPlanId/ical",
cors(),
wrapRequestWithErrorHandler(async (req, res) => {
const mealPlan = await MealPlan.findOne({
where: {
id: req.params.mealPlanId,
},
include: [
{
model: MealPlanItem,
as: "items",
attributes: [
"id",
"title",
"scheduled",
"meal",
"createdAt",
"updatedAt",
],
include: [
{
model: Recipe,
as: "recipe",
attributes: ["id", "title", "ingredients"],
},
],
},
],
});

if (!mealPlan) {
throw NotFound("Meal plan not found or you do not have access");
}

const icalEvents = mealPlan.items.map((item) => ({
start: new Date(item.scheduled),
allDay: true,
summary: item.recipe?.title || item.title,
url: `https://recipesage.com/#/meal-planners/${mealPlan.id}`,
}));

const mealPlanICal = ical({
name: `RecipeSage ${mealPlan.title}`,
events: icalEvents,
});

res.writeHead(200, {
"Content-Type": "text/calendar; charset=utf-8",
"Content-Disposition": 'attachment; filename="calendar.ics"',
});

res.end(mealPlanICal.toString());
}),
);

// Update a meal plan meta info (NOT INCLUDING ITEMS)
// router.put(
// '/:mealPlanId',
// cors(),
// MiddlewareService.validateSession(['user']),
// MiddlewareService.validateUser,
// function(req, res) {

// MealPlan.findOne({
// _id: req.params.mealPlanId,
// accountId: res.locals.accountId
// }, function(err, mealPlan) {
// if (err) {
// res.status(500).json({
// msg: "Couldn't search the database for meal plan!"
// });
// } else if (!mealPlan) {
// res.status(404).json({
// msg: "Meal plan with that ID does not exist or you do not have access!"
// });
// } else {
// if (typeof req.body.title === 'string') mealPlan.title = req.body.title;
// if (req.body.collaborators) mealPlan.collaborators = req.body.collaborators;

// mealPlan.updated = Date.now();

// mealPlan.save(function (err, mealPlan) {
// if (err) {
// res.status(500).send("Could not save updated meal plan!");
// } else {
// res.status(200).json(mealPlan);
// }
// });
// }
// });
// });

export default router;
Loading

0 comments on commit 02ea2b3

Please sign in to comment.