Skip to content

Commit ec7d3a2

Browse files
committed
fix: override year (closes #54)
1 parent 0eb106d commit ec7d3a2

4 files changed

Lines changed: 30 additions & 13 deletions

File tree

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "unicenotes",
33
"main": "expo-router/entry",
4-
"version": "3.1.2",
4+
"version": "3.1.3",
55
"scripts": {
66
"start": "expo start --dev-client",
77
"android": "expo run:android",

src/constants/config.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
export const APP_VERSION = '3.1.2';
1+
import { version } from '../../package.json';
2+
3+
export const APP_VERSION = version;
24
export const IS_BETA = false;
35

46
export const RELEASE_NOTES = {
57
"info": "Vous avez mis à jour l\'application ! 🎉",
6-
"subtitle": "Nouveautés :\n- Mise à jour de la connexion à ADE\n\nMerci d'utiliser UniceNotes !"
8+
"subtitle": "Nouveautés :\n- Correction de bugs\n\nMerci d'utiliser UniceNotes !"
79
}

src/services/edt.ts

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,17 @@ const CALENDAR_FILE = new File(Paths.document, 'calendar.json');
2222
const ONGOING_THRESHOLD_MS = 15 * 60 * 1000;
2323
const ADE_PROJECT_OVERRIDE_KEY = 'adeProjectOverride';
2424

25-
function getAcademicYearDateRange(): string {
26-
const now = new Date();
27-
const month = now.getMonth() + 1;
28-
const year = now.getFullYear();
29-
const startYear = month >= 9 ? year : year - 1;
25+
function getAcademicYearDateRange(projectName?: string): string {
26+
const match = projectName?.match(/(\d{4})-(\d{4})/);
27+
let startYear: number;
28+
if (match) {
29+
startYear = Number(match[1]);
30+
} else {
31+
const now = new Date();
32+
const month = now.getMonth() + 1;
33+
const year = now.getFullYear();
34+
startYear = month >= 9 ? year : year - 1;
35+
}
3036
const endYear = startYear + 1;
3137
return `&firstDate=${startYear}-09-01&lastDate=${endYear}-08-31`;
3238
}
@@ -81,6 +87,14 @@ function pickAutoProjectId(projects: AdeProject[]): string | null {
8187
return match?.id ?? null;
8288
}
8389

90+
async function disconnectSession(sessionId: string): Promise<void> {
91+
try {
92+
await fetch(`${ADE_BASE}/jsp/webapi?function=disconnect&sessionId=${sessionId}`);
93+
} catch {
94+
// la session expirera d'elle-même côté serveur
95+
}
96+
}
97+
8498
async function getCalendarFromCache(): Promise<CalendarEvent[]> {
8599
try {
86100
const json = await CALENDAR_FILE.text();
@@ -94,18 +108,17 @@ export class EDT {
94108
private ADE_PROJECT: string | null = null;
95109
private isOverridden = false;
96110
private projects: AdeProject[] = [];
97-
private readonly ADE_DATE: string;
98111
private readonly _ready: Promise<void>;
99112

100113
constructor() {
101-
this.ADE_DATE = getAcademicYearDateRange();
102114
this._ready = this.resolveProject();
103115
}
104116

105117
private async resolveProject(): Promise<void> {
106118
const sessionId = await fetchSessionId();
107119
if (!sessionId) return;
108120
this.projects = await fetchProjects(sessionId);
121+
await disconnectSession(sessionId);
109122

110123
const override = await getAsync(ADE_PROJECT_OVERRIDE_KEY);
111124
if (override) {
@@ -154,9 +167,11 @@ export class EDT {
154167
await this.waitUntilReady();
155168
if (!this.ADE_PROJECT) return null;
156169
try {
170+
const projectName = this.projects.find((p) => p.id === this.ADE_PROJECT)?.name;
171+
const dateRange = getAcademicYearDateRange(projectName);
157172
const url =
158173
`${ADE_BASE}/jsp/custom/modules/plannings/anonymous_cal.jsp` +
159-
`?code=${adeid}&projectId=${this.ADE_PROJECT}&calType=ical${this.ADE_DATE}`;
174+
`?code=${adeid}&projectId=${this.ADE_PROJECT}&calType=ical${dateRange}`;
160175
const res = await fetch(url);
161176
if (!res.ok) return null;
162177
return res.text();

0 commit comments

Comments
 (0)