feat: sincronización avanzada SIU por código ASIG, perfil con foto/nombre de Moodle y refinamiento visual violeta
This commit is contained in:
@@ -1,25 +1,15 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { CapacitorHttp, HttpResponse } from '@capacitor/core';
|
||||
import { AuthService } from './auth.service';
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class SiuService {
|
||||
constructor(private authService: AuthService) {}
|
||||
private readonly BASE_URL = 'https://siuuniciu.eastus2.cloudapp.azure.com/caba';
|
||||
|
||||
async getAcademicHistory(dni: string, pass: string, carreraId: string = '30'): Promise<any[]> {
|
||||
try {
|
||||
// 1. LOGIN POST
|
||||
const loginData = `usuario=${dni}&password=${pass}&login=Ingresar`;
|
||||
await CapacitorHttp.post({
|
||||
url: `${this.BASE_URL}/acceso?auth=form`,
|
||||
data: loginData,
|
||||
headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
|
||||
});
|
||||
|
||||
// 2. CAMBIO DE CARRERA (Simulando el GET que capturamos)
|
||||
// Esto es lo que destrabó el cuello de botella
|
||||
await CapacitorHttp.get({
|
||||
url: `${this.BASE_URL}/acceso/cambiar_carrera?id=${carreraId}&op=inicio_alumno`,
|
||||
});
|
||||
await this.loginSiu(dni, pass, carreraId);
|
||||
|
||||
// 3. OBTENER PLAN DE ESTUDIO
|
||||
const resPlan: HttpResponse = await CapacitorHttp.get({
|
||||
@@ -27,7 +17,6 @@ export class SiuService {
|
||||
});
|
||||
|
||||
// 4. PARSEO DEL JSON EMBEBIDO
|
||||
// Buscamos el bloque on_arrival que contiene "info_plan"
|
||||
const rawHtml = resPlan.data;
|
||||
const regex = /on_arrival\((\{.*?"id":"info_plan".*?\})\);/s;
|
||||
const match = rawHtml.match(regex);
|
||||
@@ -40,11 +29,73 @@ export class SiuService {
|
||||
|
||||
throw new Error('No se encontró el bloque de materias');
|
||||
} catch (error) {
|
||||
console.error('Error SIU:', error);
|
||||
console.error('Error SIU Academic History:', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
async getInscripcionesActivas(dni: string, pass: string, carreraId: string = '30'): Promise<any[]> {
|
||||
try {
|
||||
await this.loginSiu(dni, pass, carreraId);
|
||||
|
||||
// OBTENER PÁGINA DE CURSADA
|
||||
const resCursada: HttpResponse = await CapacitorHttp.get({
|
||||
url: `${this.BASE_URL}/cursada`,
|
||||
});
|
||||
|
||||
const rawHtml = resCursada.data;
|
||||
|
||||
// Buscamos el bloque on_arrival que contiene "info_materia" (donde están las inscripciones)
|
||||
const regex = /on_arrival\((\{.*?"id":"info_materia".*?\})\);/s;
|
||||
const match = rawHtml.match(regex);
|
||||
|
||||
if (match && match[1]) {
|
||||
const jsonData = JSON.parse(match[1]);
|
||||
const contentHtml = jsonData.content;
|
||||
return this.parseInscripcionesActivasHtml(contentHtml);
|
||||
}
|
||||
|
||||
return []; // Quizás no tiene inscripciones activas
|
||||
} catch (error) {
|
||||
console.error('Error SIU Active Inscriptions:', error);
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
private async loginSiu(dni: string, pass: string, carreraId: string): Promise<void> {
|
||||
// 1. LOGIN POST
|
||||
const loginData = `usuario=${dni}&password=${pass}&login=Ingresar`;
|
||||
await CapacitorHttp.post({
|
||||
url: `${this.BASE_URL}/acceso?auth=form`,
|
||||
data: loginData,
|
||||
headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
|
||||
});
|
||||
|
||||
// 2. CAMBIO DE CARRERA
|
||||
await CapacitorHttp.get({
|
||||
url: `${this.BASE_URL}/acceso/cambiar_carrera?id=${carreraId}&op=inicio_alumno`,
|
||||
});
|
||||
}
|
||||
|
||||
private parseInscripcionesActivasHtml(html: string): any[] {
|
||||
const parser = new DOMParser();
|
||||
const doc = parser.parseFromString(html, 'text/html');
|
||||
// Buscamos los elementos que contienen los nombres de las materias (según el HTML del usuario)
|
||||
const rows = Array.from(doc.querySelectorAll('.js-mis-inscripciones td'));
|
||||
|
||||
return rows.map(td => {
|
||||
const text = td.textContent?.trim() || '';
|
||||
// Formato esperado: "Nombre Materia - ASIG00125"
|
||||
const parts = text.split(' - ');
|
||||
if (parts.length >= 2) {
|
||||
const codigo = parts[parts.length - 1].trim();
|
||||
const nombre = parts.slice(0, -1).join(' - ').trim();
|
||||
return { nombre, codigo };
|
||||
}
|
||||
return null;
|
||||
}).filter(item => item !== null);
|
||||
}
|
||||
|
||||
private parseHtmlSubjects(html: string): any[] {
|
||||
const parser = new DOMParser();
|
||||
const doc = parser.parseFromString(html, 'text/html');
|
||||
|
||||
Reference in New Issue
Block a user