Skip to content

Commit 1d13fb6

Browse files
committed
Merge branch 'dev'
2 parents ef579da + 94c81a4 commit 1d13fb6

File tree

4 files changed

+49
-21
lines changed

4 files changed

+49
-21
lines changed

components/table/TeacherItem.vue

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,13 @@
6767
const SESSION = useSessionStore();
6868
const { getResponse } = useFormInput();
6969
const Swal = useSwal();
70-
const { losEstudiantesUrl = "", losEstudiantesProfessorsPath = "" } =
71-
APP.instance?.config || {};
7270
73-
const losEstudiantesProfessors = `${losEstudiantesUrl}${losEstudiantesProfessorsPath}`;
71+
const losEstudiantesProfessors = computed(() => {
72+
const config = APP.instance?.config || {};
73+
const { losEstudiantesUrl = "", losEstudiantesProfessorsPath = "" } = config;
74+
75+
return `${losEstudiantesUrl}${losEstudiantesProfessorsPath}`;
76+
});
7477
const estudiantesTheme = "estudiantes" as any;
7578
7679
const updatedSlug = ref("");

pages/cursos/[courseId].vue

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -290,8 +290,6 @@
290290
const { getResponse } = useFormInput();
291291
292292
const estudiantesTheme = "estudiantes" as any;
293-
const { losEstudiantesUrl = "", losEstudiantesCoursesPath = "" } = APP.instance?.config || {};
294-
const losEstudiantesCourses = `${losEstudiantesUrl}${losEstudiantesCoursesPath}`;
295293
const scraping = ref(false);
296294
const deactivated = ref(false);
297295
// Add group
@@ -303,6 +301,12 @@
303301
let unsub: Unsubscribe = () => undefined;
304302
305303
const routeId = computed(() => <string>route.params.courseId);
304+
const losEstudiantesCourses = computed(() => {
305+
const config = APP.instance?.config || {};
306+
const { losEstudiantesUrl = "", losEstudiantesCoursesPath = "" } = config;
307+
308+
return `${losEstudiantesUrl}${losEstudiantesCoursesPath}`;
309+
});
306310
307311
const { data: indexedCourse, pending: coursePending } = useAsyncData(
308312
`api:all:courses:${routeId.value}`,
@@ -642,7 +646,7 @@
642646
});
643647
}
644648
645-
const firebaseCourse: Course = resolveSnapshotDefaults(
649+
const { scrapedWithErrorsAt, ...firebaseCourse }: Course = resolveSnapshotDefaults(
646650
snapshot.ref.path,
647651
snapshot.data()
648652
);
@@ -652,7 +656,6 @@
652656
alternativeNames = [name],
653657
updatedAt,
654658
scrapedAt,
655-
scrapedWithErrorsAt,
656659
} = firebaseCourse;
657660
658661
// Update with hydration conditionally
@@ -668,7 +671,7 @@
668671
scrapedWithErrorsAt: scrapedWithErrorsAt,
669672
});
670673
// Update course
671-
course.value = { ...course.value, ...firebaseCourse };
674+
course.value = { ...course.value, ...firebaseCourse, scrapedWithErrorsAt };
672675
}
673676
674677
const minutes = APP.instance?.config?.coursesScrapeRate || 5;

resources/types/scraping.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ export interface ScrapedCourse {
77
code: string;
88
description: string;
99
lastScrapedWith: ScrapedWith;
10+
errors?: unknown[];
1011
}

server/api/groups/scrape.get.ts

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,8 @@ export default defineConditionallyCachedEventHandler(async (event, instance, aut
231231
const courseLinks: CourseLink[] = await tableHandle.evaluate(async (table) => {
232232
const tbody = table?.querySelector("tbody");
233233

234-
if (tbody?.tagName !== "TBODY") throw new Error("No courses found");
234+
// No courses found
235+
if (tbody?.tagName !== "TBODY") return [];
235236

236237
const rows = tbody?.children;
237238

@@ -262,12 +263,14 @@ export default defineConditionallyCachedEventHandler(async (event, instance, aut
262263

263264
try {
264265
// Get groups
265-
const groups: Group[] = await puppetPage.evaluate(() => {
266+
const { groups, errors } = await puppetPage.evaluate(() => {
266267
const trimHTML = (el?: Element | null) => (el ? el.innerHTML.trim() : "");
267268
const activityH3 = document.querySelector("span[id$=w-titulo] h3");
268269
const activity = trimHTML(activityH3) || "Desconocida";
269-
270-
return Array.from(document.querySelectorAll("span[id$=pgl14]")).map((root) => {
270+
const errors: Error[] = [];
271+
// Map group
272+
const groupElements = document.querySelectorAll("span[id$=pgl14]");
273+
const parsedGroups: Group[] = Array.from(groupElements).map((root) => {
271274
const teacherSpan = root.querySelector("span[id$=ot8]");
272275
const spotsSpan = root.querySelector("span[id$=ot24]");
273276
const spots: number = Number(trimHTML(spotsSpan)) || 0;
@@ -277,6 +280,7 @@ export default defineConditionallyCachedEventHandler(async (event, instance, aut
277280
const schedule: tWeeklySchedule = ["", "", "", "", "", "", ""];
278281
let classrooms: string[] = [];
279282

283+
// Map schedule & classrooms
280284
Array.from(root.querySelectorAll("span[id$=pgl10]")).forEach(
281285
(scheduledSpace) => {
282286
const classroomSpan = scheduledSpace.lastElementChild?.children[1];
@@ -286,7 +290,7 @@ export default defineConditionallyCachedEventHandler(async (event, instance, aut
286290
.split(" de ");
287291

288292
if (!day || !unparsedSpan) {
289-
throw new Error("Non supported schedule format");
293+
return errors.push(new Error("Non supported schedule format"));
290294
}
291295

292296
const span = unparsedSpan.replaceAll(".", "").split(" a ").join("|");
@@ -338,8 +342,20 @@ export default defineConditionallyCachedEventHandler(async (event, instance, aut
338342
teachers: [teacher || "No Informado"],
339343
};
340344
});
345+
346+
return { groups: parsedGroups, errors };
341347
});
342348

349+
// Prevent indexing if invalid data
350+
if (errors.length) {
351+
return {
352+
code,
353+
name: courseLink.name,
354+
description: courseLink.description,
355+
errors,
356+
};
357+
}
358+
343359
debugFirebaseServer(
344360
event,
345361
"api:groups:scrape:getResponse:end",
@@ -493,13 +509,13 @@ export default defineConditionallyCachedEventHandler(async (event, instance, aut
493509
throw reject({ statusCode: 400, statusMessage: "No faculties matched" });
494510
}
495511

496-
const errors: any[] = [];
497512
let response: ScrapedCourse = {
498513
groups: [],
499514
code: "", // Valid response would replace this
500515
name: "",
501516
description: "",
502517
lastScrapedWith: [level, place],
518+
errors: [],
503519
};
504520

505521
for (const facultyValue of facultyValues) {
@@ -549,8 +565,9 @@ export default defineConditionallyCachedEventHandler(async (event, instance, aut
549565

550566
// Attempt to get groups from this program
551567
if (!typologies.length) {
552-
const partialResponse = await getResponse();
568+
const { errors = [], ...partialResponse } = await getResponse();
553569

570+
response.errors?.push(...errors);
554571
response = {
555572
...partialResponse,
556573
lastScrapedWith: [
@@ -559,6 +576,7 @@ export default defineConditionallyCachedEventHandler(async (event, instance, aut
559576
<uSIAFaculty>facultyValue.alias,
560577
<uSIAProgram>programValue.alias,
561578
],
579+
errors,
562580
};
563581

564582
continue;
@@ -644,10 +662,11 @@ export default defineConditionallyCachedEventHandler(async (event, instance, aut
644662
await puppetPage.waitForNetworkIdle();
645663

646664
// Attempt to get groups from this typology
647-
const partialResponse = await getResponse();
665+
const { errors = [], ...partial } = await getResponse();
648666

667+
response.errors?.push(...errors);
649668
response = {
650-
...partialResponse,
669+
...partial,
651670
lastScrapedWith: [
652671
level,
653672
place,
@@ -657,7 +676,7 @@ export default defineConditionallyCachedEventHandler(async (event, instance, aut
657676
],
658677
};
659678
} catch (err) {
660-
errors.push(err); // save typologies errors
679+
response.errors?.push(err); // save typologies errors
661680

662681
debugFirebaseServer(
663682
event,
@@ -668,7 +687,7 @@ export default defineConditionallyCachedEventHandler(async (event, instance, aut
668687
}
669688
}
670689
} catch (err) {
671-
errors.push(err); // save programs errors
690+
response.errors?.push(err); // save programs errors
672691

673692
debugFirebaseServer(
674693
event,
@@ -679,7 +698,7 @@ export default defineConditionallyCachedEventHandler(async (event, instance, aut
679698
}
680699
}
681700
} catch (err) {
682-
errors.push(err); // save faculties errors
701+
response.errors?.push(err); // save faculties errors
683702

684703
debugFirebaseServer(
685704
event,
@@ -691,7 +710,9 @@ export default defineConditionallyCachedEventHandler(async (event, instance, aut
691710
}
692711

693712
// If no groups found, throw errors if any
694-
if (!response.groups?.length && errors.length) throw reject(errors.pop());
713+
if (!response.groups?.length && response.errors?.length) {
714+
throw reject(response.errors.pop());
715+
}
695716

696717
resolve(response);
697718
},

0 commit comments

Comments
 (0)