Skip to content

Commit

Permalink
- Added next week fetching
Browse files Browse the repository at this point in the history
- Bumped up to version v1.0.9.1
  • Loading branch information
developerfromjokela committed Feb 5, 2022
1 parent b5499e6 commit b251392
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "foodmenu",
"version": "1.0.9",
"version": "1.0.9.1",
"description": "This API provides additional food menus which are not available as JSON.\nThis middleware converts them to JSON format.",
"main": "build/main.js",
"scripts": {
Expand Down
23 changes: 18 additions & 5 deletions src/handlers/aromav2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {HashUtils} from "../crypto/hash";
import {Day} from "../models/Day";
import {Diet} from "../models/Diet";
import {Options} from "selenium-webdriver/chrome";
import moment from "moment";

const urlRegex = /https?:\/\/(www\.)?[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_+.~#?&/=]*)/;
let httpClient = new Http();
Expand Down Expand Up @@ -250,17 +251,29 @@ export function getRestaurantPage(req: Request, res: Response) {
});
});
};
/*const contains = (item: string, items: Diet[]) => {
const contains = (item: string, items: Diet[]) => {
let found = false;
items.forEach(item2 => {
if (item.toLowerCase() == item2.name.toLowerCase())
found = true;
});
return found;
}*/
// Revert to single week, because request is taking too long to complete
}
// Now that performance issues are fixed, include next week
fetchDate("1", (restaurants, diets) => {
responseStatus(res, 200, true, {menu: restaurants, diets: diets});
// Fetch next week, if it's necessary. Otherwise, skip it.
if (restaurants.filter(i => {return moment() > i.date}).length < 1) {
fetchDate("2", ((restaurants1, diets1) => {
restaurants1.forEach(item => restaurants.push(item));
diets1.forEach(dItem => {if (!contains(dItem.name, diets)) {diets.push(dItem)}});
responseStatus(res, 200, true, {menu: restaurants, diets: diets});
}), error => {
errorResponse(res, 500, error);
return;
});
} else {
responseStatus(res, 200, true, {menu: restaurants, diets: diets});
}
}, error => {
errorResponse(res, 500, error);
return;
Expand Down Expand Up @@ -298,7 +311,7 @@ export function getRestaurantPage(req: Request, res: Response) {
responseStatus(res, 200, true, {menu: [], diets: []});
return;
}
pdfUrl = pdfUrl.replace("DateMode=0", "DateMode=%dmd%");
pdfUrl = pdfUrl.replace(/DateMode=[0-9]/, "DateMode=%dmd%");
userCache.setItem(hashKey, pdfUrl, {ttl: 3600}).then(() => {
fetchDocument(pdfUrl);
}).catch(error => {
Expand Down

0 comments on commit b251392

Please sign in to comment.