@ranzenjs/client 0.4.1 → 0.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +31 -8
- package/dist/app.d.ts +2 -0
- package/dist/app.js +2 -0
- package/dist/apps/calendar/parse.js +13 -16
- package/dist/apps/calendar/types.d.ts +1 -0
- package/dist/apps/lessons/index.d.ts +19 -1
- package/dist/apps/lessons/index.js +60 -2
- package/dist/apps/lessons/parse.d.ts +3 -1
- package/dist/apps/lessons/parse.js +162 -0
- package/dist/apps/lessons/types.d.ts +58 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -32,13 +32,13 @@ await connection.logout();
|
|
|
32
32
|
|
|
33
33
|
Every portal feature is an app that you open on a connection. Opening makes no request.
|
|
34
34
|
|
|
35
|
-
| Import | App | Calls
|
|
36
|
-
| -------------------------------- | --------------- |
|
|
37
|
-
| `@ranzenjs/client/lessons` | Mein Unterricht | `overview()`, `course(id, { semester })`, `setHomeworkDone()`, `download()`, `downloadAll()` |
|
|
38
|
-
| `@ranzenjs/client/substitutions` | Vertretungsplan | `plan({ full })`
|
|
39
|
-
| `@ranzenjs/client/profile` | Benutzerdaten | `get()`
|
|
40
|
-
| `@ranzenjs/client/calendar` | Kalender | `events({ from, to })`, `categories()`, `details(id)`
|
|
41
|
-
| `@ranzenjs/client/catalog` | Start page | `list()`, `offers(app)`
|
|
35
|
+
| Import | App | Calls |
|
|
36
|
+
| -------------------------------- | --------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
37
|
+
| `@ranzenjs/client/lessons` | Mein Unterricht | `overview()`, `course(id, { semester })`, `setHomeworkDone()`, `download()`, `downloadAll()`, `submission()`, `submit()`, `downloadSubmitted()`, `deleteSubmitted()` |
|
|
38
|
+
| `@ranzenjs/client/substitutions` | Vertretungsplan | `plan({ full })` |
|
|
39
|
+
| `@ranzenjs/client/profile` | Benutzerdaten | `get()` |
|
|
40
|
+
| `@ranzenjs/client/calendar` | Kalender | `events({ from, to })`, `categories()`, `details(id)` |
|
|
41
|
+
| `@ranzenjs/client/catalog` | Start page | `list()`, `offers(app)` |
|
|
42
42
|
|
|
43
43
|
Schools turn apps on and off. To find out whether an account has an app, ask
|
|
44
44
|
`connection.open(catalog).offers(lessons)`.
|
|
@@ -53,6 +53,26 @@ const file = await connection
|
|
|
53
53
|
await Bun.write('blatt.pdf', new Response(file.body));
|
|
54
54
|
```
|
|
55
55
|
|
|
56
|
+
### Hand-ins
|
|
57
|
+
|
|
58
|
+
Entries list their hand-ins in `entry.submissions`. `submission()` reads one hand-in's rules
|
|
59
|
+
and the files already handed in; `submit()` uploads up to five files while it is open:
|
|
60
|
+
|
|
61
|
+
```ts
|
|
62
|
+
const target = { course: '101', entry: '55', submission: '1' };
|
|
63
|
+
const details = await app.submission(target);
|
|
64
|
+
if (details.open) {
|
|
65
|
+
const file = new File([await Bun.file('loesung.pdf').arrayBuffer()], 'loesung.pdf');
|
|
66
|
+
const { results, submission } = await app.submit({ ...target, files: [file] });
|
|
67
|
+
}
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
`results` says per sent file whether the portal took it (`ok: null` when its answer leaves
|
|
71
|
+
that open), and `submission` is the hand-in afterwards.
|
|
72
|
+
An upload is not idempotent, so after a failed `submit()` read `submission()` again before
|
|
73
|
+
retrying. `downloadSubmitted()` fetches a handed-in file by its id, and `deleteSubmitted()`
|
|
74
|
+
removes one; the portal asks for the account password again for that.
|
|
75
|
+
|
|
56
76
|
### Calendar
|
|
57
77
|
|
|
58
78
|
```ts
|
|
@@ -67,7 +87,10 @@ const categories = await dates.categories(); // { id, name, color }, as events r
|
|
|
67
87
|
recurrence, so each event is one occurrence. Dates and times are the portal's Europe/Berlin wall
|
|
68
88
|
clock as written. ranzen never converts them through UTC, so `"2026-10-25"` and `"02:30"` mean
|
|
69
89
|
exactly what the school entered. `endDate` is inclusive and never before `startDate`. All-day
|
|
70
|
-
events have `startTime` and `endTime` set to `null`.
|
|
90
|
+
events have `startTime` and `endTime` set to `null`. An event without a readable end is read as
|
|
91
|
+
starting only: `endDate` equals `startDate` and `endTime` is `null`. Since callers can treat the
|
|
92
|
+
list as complete, an event without a readable id, title or start fails the whole call with
|
|
93
|
+
`LAYOUT_CHANGED` instead of going missing. Descriptions are plain text with their line
|
|
71
94
|
breaks. The portal sometimes encodes them twice. ranzen then turns encoded `<br />` into line
|
|
72
95
|
breaks and keeps any other encoded markup as visible text.
|
|
73
96
|
|
package/dist/app.d.ts
CHANGED
|
@@ -29,6 +29,8 @@ export interface AppContext {
|
|
|
29
29
|
page(request: PageRequest): Promise<Page>;
|
|
30
30
|
document(request: PageRequest): Promise<Document>;
|
|
31
31
|
download(request: PageRequest): Promise<Download>;
|
|
32
|
+
/** Encrypts a value the way the portal's own $.crypt() does, e.g. a password it asks for again. */
|
|
33
|
+
encrypt(value: string): string;
|
|
32
34
|
/** Reports a non-fatal mismatch with the portal, e.g. an unknown table column. */
|
|
33
35
|
drift(detail: string): void;
|
|
34
36
|
}
|
package/dist/app.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { RanzenError, fail, layoutChanged } from './errors.js';
|
|
2
2
|
import { all, one, parseHtml, text } from './html.js';
|
|
3
|
+
import { seal } from './protocol/cipher.js';
|
|
3
4
|
import { PAGES } from './protocol/endpoints.js';
|
|
4
5
|
/** Apps are stateless definitions; Connection.open() binds one to a session. */
|
|
5
6
|
export function defineApp(info, create) {
|
|
@@ -13,6 +14,7 @@ export function createContext(session, drift) {
|
|
|
13
14
|
return session.account;
|
|
14
15
|
},
|
|
15
16
|
drift,
|
|
17
|
+
encrypt: (value) => seal(value, session.secret),
|
|
16
18
|
async page(request) {
|
|
17
19
|
const exchange = toExchange(request);
|
|
18
20
|
const reply = await session.send(exchange);
|
|
@@ -13,6 +13,7 @@ export function isIsoDate(value) {
|
|
|
13
13
|
function addDays(date, days) {
|
|
14
14
|
return new Date(Date.parse(`${date}T00:00:00Z`) + days * 86_400_000).toISOString().slice(0, 10);
|
|
15
15
|
}
|
|
16
|
+
// Callers treat the list as complete, so an unreadable event fails the whole read.
|
|
16
17
|
export function parseEvents(body, drift = ignoreDrift) {
|
|
17
18
|
const data = parseJson(body, 'calendar events');
|
|
18
19
|
if (!Array.isArray(data))
|
|
@@ -21,34 +22,30 @@ export function parseEvents(body, drift = ignoreDrift) {
|
|
|
21
22
|
for (const raw of data) {
|
|
22
23
|
const event = parseEvent(raw, drift);
|
|
23
24
|
// The same id twice is the same event; the first one wins.
|
|
24
|
-
if (
|
|
25
|
+
if (!events.has(event.id))
|
|
25
26
|
events.set(event.id, event);
|
|
26
27
|
}
|
|
27
28
|
return [...events.values()];
|
|
28
29
|
}
|
|
29
30
|
function parseEvent(raw, drift) {
|
|
30
|
-
if (!isRecord(raw))
|
|
31
|
-
|
|
32
|
-
return null;
|
|
33
|
-
}
|
|
31
|
+
if (!isRecord(raw))
|
|
32
|
+
throw layoutChanged('every calendar event as an object');
|
|
34
33
|
const id = idOf(raw.Id);
|
|
35
34
|
const title = plain(raw.title);
|
|
36
35
|
const start = stamp(raw.Anfang);
|
|
36
|
+
if (!id || !title || !start) {
|
|
37
|
+
throw layoutChanged('an id, a title and a readable start on every calendar event');
|
|
38
|
+
}
|
|
37
39
|
const end = stamp(raw.Ende);
|
|
38
|
-
if (!
|
|
39
|
-
drift('A calendar event has
|
|
40
|
-
else if (!title)
|
|
41
|
-
drift('A calendar event has no title.');
|
|
42
|
-
else if (!start || !end)
|
|
43
|
-
drift('A calendar event has no readable start and end.');
|
|
44
|
-
if (!id || !title || !start || !end)
|
|
45
|
-
return null;
|
|
40
|
+
if (!end && raw.Ende != null && raw.Ende !== '')
|
|
41
|
+
drift('A calendar event has an unreadable end.');
|
|
46
42
|
if (typeof raw.allDay !== 'boolean')
|
|
47
43
|
drift('A calendar event has no allDay flag.');
|
|
48
44
|
const allDay = raw.allDay === true;
|
|
49
|
-
|
|
45
|
+
// Without a readable end the event is read as starting only.
|
|
46
|
+
let last = end ?? start;
|
|
50
47
|
// The portal ends all-day events at 23:59; an end at midnight of a later day is read as exclusive.
|
|
51
|
-
if (allDay && end.time === '00:00:00' && end.date > start.date) {
|
|
48
|
+
if (allDay && end && end.time === '00:00:00' && end.date > start.date) {
|
|
52
49
|
last = { date: addDays(end.date, -1), time: end.time };
|
|
53
50
|
}
|
|
54
51
|
if (`${last.date} ${last.time}` < `${start.date} ${start.time}`)
|
|
@@ -67,7 +64,7 @@ function parseEvent(raw, drift) {
|
|
|
67
64
|
startDate: start.date,
|
|
68
65
|
endDate: last.date,
|
|
69
66
|
startTime: allDay ? null : start.time.slice(0, 5),
|
|
70
|
-
endTime: allDay ? null : last.time.slice(0, 5),
|
|
67
|
+
endTime: allDay || !end ? null : last.time.slice(0, 5),
|
|
71
68
|
updatedAt: changed && `${changed.date}T${changed.time}`,
|
|
72
69
|
isNew: flag(raw.Neu, drift),
|
|
73
70
|
isPublic: flag(raw.Oeffentlich, drift),
|
|
@@ -25,6 +25,7 @@ export interface CalendarEvent {
|
|
|
25
25
|
endDate: string;
|
|
26
26
|
/** "HH:MM"; null for all-day events. */
|
|
27
27
|
startTime: string | null;
|
|
28
|
+
/** "HH:MM"; null for all-day events and for events the portal gives no end. */
|
|
28
29
|
endTime: string | null;
|
|
29
30
|
/** Last change as local portal time, e.g. "2026-10-16T11:58:40". */
|
|
30
31
|
updatedAt: string | null;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type Download } from '../../app.js';
|
|
2
2
|
import type { SignalOption } from '../../connection.js';
|
|
3
|
-
import type { Course, EntryRef, Overview } from './types.js';
|
|
3
|
+
import type { Course, EntryRef, Overview, SubmissionDetails, SubmissionRef, SubmitResult } from './types.js';
|
|
4
4
|
export type * from './types.js';
|
|
5
5
|
export interface CourseOptions extends SignalOption {
|
|
6
6
|
/** Reads an earlier semester of the same course, e.g. 1 while in the second. */
|
|
@@ -21,6 +21,24 @@ export interface LessonsApi {
|
|
|
21
21
|
}, options?: SignalOption): Promise<Download>;
|
|
22
22
|
/** Every file of an entry as one zip archive. */
|
|
23
23
|
downloadAll(target: EntryRef, options?: SignalOption): Promise<Download>;
|
|
24
|
+
/** A hand-in of an entry, by Submission.id: its rules, whether it is open, and the files handed in. */
|
|
25
|
+
submission(target: SubmissionRef, options?: SignalOption): Promise<SubmissionDetails>;
|
|
26
|
+
/**
|
|
27
|
+
* Hands in up to five files in one upload; not idempotent on retry. Each result says how the
|
|
28
|
+
* portal took a file, and `submission` is the hand-in the portal shows afterwards.
|
|
29
|
+
*/
|
|
30
|
+
submit(target: SubmissionRef & {
|
|
31
|
+
files: File[];
|
|
32
|
+
}, options?: SignalOption): Promise<SubmitResult>;
|
|
33
|
+
/** A handed-in file, by SubmittedFile.id. */
|
|
34
|
+
downloadSubmitted(target: SubmissionRef & {
|
|
35
|
+
file: string;
|
|
36
|
+
}, options?: SignalOption): Promise<Download>;
|
|
37
|
+
/** Deletes a handed-in file; the portal asks for the password again, and AUTH_FAILED means it was wrong. */
|
|
38
|
+
deleteSubmitted(target: SubmissionRef & {
|
|
39
|
+
file: string;
|
|
40
|
+
password: string;
|
|
41
|
+
}, options?: SignalOption): Promise<void>;
|
|
24
42
|
}
|
|
25
43
|
/** "Mein Unterricht": course folders, entries, homework, marks and attendance. */
|
|
26
44
|
export declare const lessons: import("../../app.js").App<LessonsApi>;
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { defineApp } from '../../app.js';
|
|
2
|
-
import { RanzenError } from '../../errors.js';
|
|
3
|
-
import { parseCourse, parseOverview } from './parse.js';
|
|
2
|
+
import { RanzenError, fail } from '../../errors.js';
|
|
3
|
+
import { parseCourse, parseOverview, parseSubmission, parseUploadResults } from './parse.js';
|
|
4
4
|
const PAGE = 'meinunterricht.php';
|
|
5
|
+
// The portal's upload form has five file inputs.
|
|
6
|
+
const MAX_FILES = 5;
|
|
5
7
|
/** "Mein Unterricht": course folders, entries, homework, marks and attendance. */
|
|
6
8
|
export const lessons = defineApp({ id: 'lessons', page: PAGE }, (context) => ({
|
|
7
9
|
async overview({ signal } = {}) {
|
|
@@ -40,5 +42,61 @@ export const lessons = defineApp({ id: 'lessons', page: PAGE }, (context) => ({
|
|
|
40
42
|
query: { a: 'downloadFile', b: 'zip', id: course, e: entry },
|
|
41
43
|
signal
|
|
42
44
|
});
|
|
45
|
+
},
|
|
46
|
+
async submission({ course, entry, submission }, { signal } = {}) {
|
|
47
|
+
const document = await context.document({
|
|
48
|
+
path: PAGE,
|
|
49
|
+
query: { a: 'sus_abgabe', b: course, e: entry, id: submission },
|
|
50
|
+
signal
|
|
51
|
+
});
|
|
52
|
+
return parseSubmission(document, context.drift);
|
|
53
|
+
},
|
|
54
|
+
async submit({ course, entry, submission, files }, { signal } = {}) {
|
|
55
|
+
if (!files.length || files.length > MAX_FILES) {
|
|
56
|
+
throw fail('INVALID_OPTION', `submit() takes 1 to ${MAX_FILES} files.`);
|
|
57
|
+
}
|
|
58
|
+
const form = new FormData();
|
|
59
|
+
form.append('a', 'sus_abgabe');
|
|
60
|
+
form.append('b', course);
|
|
61
|
+
form.append('e', entry);
|
|
62
|
+
form.append('id', submission);
|
|
63
|
+
files.forEach((file, index) => form.append(`file${index + 1}`, file, file.name));
|
|
64
|
+
const document = await context.document({ path: PAGE, multipart: form, signal });
|
|
65
|
+
return {
|
|
66
|
+
results: parseUploadResults(document, files.map((file) => file.name), context.drift),
|
|
67
|
+
submission: parseSubmission(document, context.drift)
|
|
68
|
+
};
|
|
69
|
+
},
|
|
70
|
+
downloadSubmitted({ course, entry, submission, file }, { signal } = {}) {
|
|
71
|
+
return context.download({
|
|
72
|
+
path: PAGE,
|
|
73
|
+
query: { a: 'downloadFile', id: course, e: entry, abg: submission, f: file },
|
|
74
|
+
signal
|
|
75
|
+
});
|
|
76
|
+
},
|
|
77
|
+
async deleteSubmitted({ course, entry, submission, file, password }, { signal } = {}) {
|
|
78
|
+
const { text } = await context.page({
|
|
79
|
+
path: PAGE,
|
|
80
|
+
form: {
|
|
81
|
+
a: 'sus_abgabe',
|
|
82
|
+
d: 'delete',
|
|
83
|
+
b: course,
|
|
84
|
+
e: entry,
|
|
85
|
+
id: submission,
|
|
86
|
+
f: file,
|
|
87
|
+
pw: context.encrypt(password)
|
|
88
|
+
},
|
|
89
|
+
ajax: true,
|
|
90
|
+
signal
|
|
91
|
+
});
|
|
92
|
+
const answer = text.trim();
|
|
93
|
+
if (answer === '1')
|
|
94
|
+
return;
|
|
95
|
+
if (answer === '-1')
|
|
96
|
+
throw fail('AUTH_FAILED', 'The portal did not accept the password.');
|
|
97
|
+
throw new RanzenError({
|
|
98
|
+
code: 'PORTAL_ERROR',
|
|
99
|
+
notice: answer === '-2' ? 'Leider ist die Änderung fehlgeschlagen!' : 'Unbekannter Fehler!'
|
|
100
|
+
}, 'The portal did not delete the file.');
|
|
43
101
|
}
|
|
44
102
|
}));
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { type Document } from '../../html.js';
|
|
2
2
|
import { type DriftSink } from '../../util.js';
|
|
3
|
-
import type { Course, Overview } from './types.js';
|
|
3
|
+
import type { Course, Overview, SubmissionDetails, UploadResult } from './types.js';
|
|
4
4
|
export declare function parseOverview(document: Document, drift?: DriftSink): Overview;
|
|
5
5
|
export declare function parseCourse(document: Document, id: string, drift?: DriftSink): Course;
|
|
6
|
+
export declare function parseSubmission(document: Document, drift?: DriftSink): SubmissionDetails;
|
|
7
|
+
export declare function parseUploadResults(document: Document, sent: readonly string[], drift?: DriftSink): UploadResult[];
|
|
@@ -318,3 +318,165 @@ function emptyEntry(id) {
|
|
|
318
318
|
attendance: null
|
|
319
319
|
};
|
|
320
320
|
}
|
|
321
|
+
// One hand-in page: its rules, then the own files, then the upload form or a closed notice.
|
|
322
|
+
export function parseSubmission(document, drift = ignoreDrift) {
|
|
323
|
+
const heading = one('#content h1[data-abgabe]', document);
|
|
324
|
+
if (!heading)
|
|
325
|
+
throw layoutChanged('h1[data-abgabe] on the submission page');
|
|
326
|
+
const columns = all('#content .row > .col-md-12', document);
|
|
327
|
+
const rules = columns.find((column) => text(one('h3', column)) === 'Vorgaben');
|
|
328
|
+
const own = columns.find((column) => one('a[name="eigene"]', column));
|
|
329
|
+
if (!rules)
|
|
330
|
+
drift('The submission page has no rules.');
|
|
331
|
+
if (!own)
|
|
332
|
+
drift('The submission page has no own files.');
|
|
333
|
+
const form = one('#content form input[name="a"][value="sus_abgabe"]', document)?.parent;
|
|
334
|
+
const slots = form ? all('input[type="file"]', form).length : 0;
|
|
335
|
+
if (!form && !one('#content .col-md-7 .alert-warning', document)) {
|
|
336
|
+
drift('The submission page says neither open nor closed.');
|
|
337
|
+
}
|
|
338
|
+
const course = one('#content a.btn-primary[href*="sus_view"]', document);
|
|
339
|
+
const details = {
|
|
340
|
+
id: attr(heading, 'data-abgabe') ?? '',
|
|
341
|
+
name: rawText(heading),
|
|
342
|
+
course: { id: queryParam(attr(course, 'href'), 'id') ?? '', name: text(course) },
|
|
343
|
+
entry: attr(heading, 'data-eintrag') ?? '',
|
|
344
|
+
opens: editableTime(rules, 'Von', drift),
|
|
345
|
+
due: editableTime(rules, 'Bis', drift),
|
|
346
|
+
open: slots > 0,
|
|
347
|
+
slots,
|
|
348
|
+
multipleFiles: null,
|
|
349
|
+
repeatable: null,
|
|
350
|
+
visibleTo: null,
|
|
351
|
+
deletesOn: null,
|
|
352
|
+
fileTypes: [],
|
|
353
|
+
maxSize: null,
|
|
354
|
+
maxBytes: null,
|
|
355
|
+
notice: text(form && one('div:not([class])', form), true) || null,
|
|
356
|
+
files: own ? all('ul > li', own).map((item) => submittedFile(item, drift)) : []
|
|
357
|
+
};
|
|
358
|
+
for (const [label, value] of rules ? ruleLabels(rules) : []) {
|
|
359
|
+
const valueText = text(value);
|
|
360
|
+
if (label.startsWith('Abgabe mehrerer Dateien'))
|
|
361
|
+
details.multipleFiles = allowed(valueText);
|
|
362
|
+
else if (label.startsWith('Abgabe beliebig häufig'))
|
|
363
|
+
details.repeatable = allowed(valueText);
|
|
364
|
+
else if (label.startsWith('Abgabe sichtbar für'))
|
|
365
|
+
details.visibleTo = valueText || null;
|
|
366
|
+
else if (label.startsWith('Dateien werden automatisch gelöscht')) {
|
|
367
|
+
details.deletesOn = isoDate(valueText);
|
|
368
|
+
}
|
|
369
|
+
else if (label.startsWith('Erlaubte Dateitypen')) {
|
|
370
|
+
details.fileTypes = valueText
|
|
371
|
+
.split(',')
|
|
372
|
+
.map((type) => type.trim().toUpperCase())
|
|
373
|
+
.filter(Boolean);
|
|
374
|
+
}
|
|
375
|
+
else if (label.startsWith('maximale Dateigröße')) {
|
|
376
|
+
details.maxSize = valueText || null;
|
|
377
|
+
details.maxBytes = bytes(valueText);
|
|
378
|
+
if (valueText && details.maxBytes === null)
|
|
379
|
+
drift('A submission has an unreadable size limit.');
|
|
380
|
+
}
|
|
381
|
+
else
|
|
382
|
+
drift('A submission has an unknown rule.');
|
|
383
|
+
}
|
|
384
|
+
return details;
|
|
385
|
+
}
|
|
386
|
+
// The per-file report after an upload: name in <b>, outcome in a label, then an optional message.
|
|
387
|
+
// Every sent file gets a result; one the report does not mention has an unknown outcome.
|
|
388
|
+
export function parseUploadResults(document, sent, drift = ignoreDrift) {
|
|
389
|
+
const column = all('#content .col-md-12', document).find((c) => text(one('h3', c)).startsWith('Ergebnis des Uploads'));
|
|
390
|
+
const results = (column ? all('li', column) : []).flatMap((item) => {
|
|
391
|
+
const name = one('b', item);
|
|
392
|
+
const label = one('.label', item);
|
|
393
|
+
if (!name || !label) {
|
|
394
|
+
drift('An upload result has an unknown shape.');
|
|
395
|
+
return [];
|
|
396
|
+
}
|
|
397
|
+
const message = text(item)
|
|
398
|
+
.replace(text(name), '')
|
|
399
|
+
.replace(text(label), '')
|
|
400
|
+
.replace(/^[\s:–-]+/, '')
|
|
401
|
+
.trim();
|
|
402
|
+
return [
|
|
403
|
+
{
|
|
404
|
+
name: text(name),
|
|
405
|
+
ok: hasClass(label, 'label-success'),
|
|
406
|
+
status: text(label),
|
|
407
|
+
message: message || null
|
|
408
|
+
}
|
|
409
|
+
];
|
|
410
|
+
});
|
|
411
|
+
const listed = new Set(results.map((result) => result.name));
|
|
412
|
+
const missing = sent
|
|
413
|
+
.filter((name) => !listed.has(name))
|
|
414
|
+
.slice(0, Math.max(0, sent.length - results.length));
|
|
415
|
+
if (missing.length)
|
|
416
|
+
drift('The upload answer does not list every file.');
|
|
417
|
+
return [...results, ...missing.map((name) => ({ name, ok: null, status: null, message: null }))];
|
|
418
|
+
}
|
|
419
|
+
// Rules are lines of an icon, a label and a value badge, separated by <br>.
|
|
420
|
+
function ruleLabels(rules) {
|
|
421
|
+
const pairs = [];
|
|
422
|
+
let label = '';
|
|
423
|
+
for (const node of rules.children) {
|
|
424
|
+
if (node.type === 'text')
|
|
425
|
+
label += node.data;
|
|
426
|
+
else if (node.type === 'tag' && node.name === 'br')
|
|
427
|
+
label = '';
|
|
428
|
+
else if (node.type === 'tag' && hasClass(node, 'label')) {
|
|
429
|
+
pairs.push([label.replace(/\s+/g, ' ').trim(), node]);
|
|
430
|
+
label = '';
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
return pairs;
|
|
434
|
+
}
|
|
435
|
+
function allowed(value) {
|
|
436
|
+
if (/^nicht erlaubt$/i.test(value))
|
|
437
|
+
return false;
|
|
438
|
+
if (/^erlaubt$/i.test(value))
|
|
439
|
+
return true;
|
|
440
|
+
return null;
|
|
441
|
+
}
|
|
442
|
+
const UNITS = { B: 1, KB: 1e3, MB: 1e6, GB: 1e9 };
|
|
443
|
+
function bytes(value) {
|
|
444
|
+
const match = /^([\d.]+(?:,\d+)?)\s*([KMG]?B)$/i.exec(value.trim());
|
|
445
|
+
if (!match)
|
|
446
|
+
return null;
|
|
447
|
+
const amount = Number(match[1].replace(/\./g, '').replace(',', '.'));
|
|
448
|
+
return Math.floor(amount * UNITS[match[2].toUpperCase()]);
|
|
449
|
+
}
|
|
450
|
+
// The rule spans carry the moment machine-readable, e.g. data-value="04.11.2026 15:30".
|
|
451
|
+
function editableTime(rules, field, drift) {
|
|
452
|
+
const span = rules && one(`.editable[data-field="${field}"]`, rules);
|
|
453
|
+
if (!span)
|
|
454
|
+
return null;
|
|
455
|
+
const value = attr(span, 'data-value') ?? '';
|
|
456
|
+
const time = localTime(value, isoDate(value));
|
|
457
|
+
if (!time)
|
|
458
|
+
drift('A submission has an unreadable time.');
|
|
459
|
+
return time;
|
|
460
|
+
}
|
|
461
|
+
// Upload times are written with two-digit years, e.g. "28.10.26 13:55".
|
|
462
|
+
function submittedFile(item, drift) {
|
|
463
|
+
const link = one('a[href*="downloadFile"]', item);
|
|
464
|
+
const stamp = text(one('[title="Uploadzeitpunkt"]', item));
|
|
465
|
+
const short = /(\d{1,2})\.(\d{1,2})\.(\d{2})\b/.exec(stamp);
|
|
466
|
+
const day = short ? isoDate(`${short[1]}.${short[2]}.20${short[3]}`) : isoDate(stamp);
|
|
467
|
+
const uploaded = localTime(stamp, day);
|
|
468
|
+
if (stamp && !uploaded)
|
|
469
|
+
drift('A submitted file has an unreadable upload time.');
|
|
470
|
+
const remove = one('.deleteFile[data-file]', item);
|
|
471
|
+
const name = link ? text(link) : ownText(item);
|
|
472
|
+
return {
|
|
473
|
+
id: attr(remove, 'data-file') ?? queryParam(attr(link, 'href'), 'f'),
|
|
474
|
+
name,
|
|
475
|
+
uploaded,
|
|
476
|
+
deletable: !!remove
|
|
477
|
+
};
|
|
478
|
+
}
|
|
479
|
+
function localTime(value, day) {
|
|
480
|
+
const time = /\b([01]?\d|2[0-3]):([0-5]\d)\b/.exec(value);
|
|
481
|
+
return day && time ? `${day}T${time[1].padStart(2, '0')}:${time[2]}` : day;
|
|
482
|
+
}
|
|
@@ -102,3 +102,61 @@ export interface EntryRef {
|
|
|
102
102
|
course: string;
|
|
103
103
|
entry: string;
|
|
104
104
|
}
|
|
105
|
+
export interface SubmissionRef extends EntryRef {
|
|
106
|
+
/** Submission.id of the entry, e.g. "1". */
|
|
107
|
+
submission: string;
|
|
108
|
+
}
|
|
109
|
+
export interface SubmittedFile {
|
|
110
|
+
/** For downloadSubmitted() and deleteSubmitted(); null once the portal has deleted the file. */
|
|
111
|
+
id: string | null;
|
|
112
|
+
name: string;
|
|
113
|
+
/** Local date-time of the upload, e.g. "2026-10-28T13:55". */
|
|
114
|
+
uploaded: string | null;
|
|
115
|
+
/** The portal offers to delete it, which takes the account password. */
|
|
116
|
+
deletable: boolean;
|
|
117
|
+
}
|
|
118
|
+
export interface SubmissionDetails {
|
|
119
|
+
id: string;
|
|
120
|
+
/** As written, matching Submission.name. */
|
|
121
|
+
name: string;
|
|
122
|
+
course: CourseRef;
|
|
123
|
+
entry: string;
|
|
124
|
+
/** Local date-times the portal accepts files between, e.g. "2026-11-04T15:30". */
|
|
125
|
+
opens: string | null;
|
|
126
|
+
due: string | null;
|
|
127
|
+
/** The portal accepts files right now. */
|
|
128
|
+
open: boolean;
|
|
129
|
+
/** Files one submit() may carry; 0 while closed. */
|
|
130
|
+
slots: number;
|
|
131
|
+
/** Null when the page does not say. */
|
|
132
|
+
multipleFiles: boolean | null;
|
|
133
|
+
repeatable: boolean | null;
|
|
134
|
+
/** As shown, e.g. "Lehrkräfte der Kursmappe". */
|
|
135
|
+
visibleTo: string | null;
|
|
136
|
+
/** ISO calendar date the portal deletes the files on. */
|
|
137
|
+
deletesOn: string | null;
|
|
138
|
+
/** Upper-case extensions, e.g. ["PDF", "PNG"]; empty when the page names none. */
|
|
139
|
+
fileTypes: string[];
|
|
140
|
+
/** As shown, e.g. "10,00 MB". */
|
|
141
|
+
maxSize: string | null;
|
|
142
|
+
/** maxSize in decimal bytes, so never above what the portal accepts. */
|
|
143
|
+
maxBytes: number | null;
|
|
144
|
+
/** The hint above the upload form, e.g. how to name files; null while closed. */
|
|
145
|
+
notice: string | null;
|
|
146
|
+
files: SubmittedFile[];
|
|
147
|
+
}
|
|
148
|
+
export interface SubmitResult {
|
|
149
|
+
results: UploadResult[];
|
|
150
|
+
/** The hand-in as the portal shows it after the upload. */
|
|
151
|
+
submission: SubmissionDetails;
|
|
152
|
+
}
|
|
153
|
+
export interface UploadResult {
|
|
154
|
+
/** The file name as the portal lists it. */
|
|
155
|
+
name: string;
|
|
156
|
+
/** null when the portal's answer does not mention the file, so it may or may not have landed. */
|
|
157
|
+
ok: boolean | null;
|
|
158
|
+
/** The portal's label, e.g. "erfolgreich". */
|
|
159
|
+
status: string | null;
|
|
160
|
+
/** e.g. that the portal renamed a file whose name was taken. */
|
|
161
|
+
message: string | null;
|
|
162
|
+
}
|