scripts/upload-exam/tentaApi.js
/** Download the exam with ID "fileId". Returns its content as a ReadableStream */
Download the exam with ID "fileId". Returns its content as a ReadableStream
Download the exam with ID " fileId " . Returns its content as a ReadableStream
async downloadExam(fileId) {
    const { body } = await this.client(`windream/file/${fileId}/true`, {
      responseType: "json",
    });
    const getValue = (index) =>
      body.wdFile.objectIndiceses.find((di) => di.index === index)?.value;
    const { fileName } = body.wdFile;
    const examDateTime = getValue("e_date");
    const examDate = examDateTime.split("T")[0];
    const student = {
      kthId: getValue("s_uid"),
      personNumber: getValue("s_pnr"),
      firstName: getValue("s_firstname"),
      lastName: getValue("s_lastname"),
    };
    if (!student.kthId)
      throw new Error(
        `Could not get KTH ID (s_uid) from TentaAPI (windream) for file id "${fileId}".`
      );
    return {
      content: Readable.from(
        Buffer.from(body.wdFile.fileAsBase64.toString("utf-8"), "base64")
      ),
      fileName,
      student,
      examDate,
    };
  }
async downloadExam ( fileId ) { const { body } = await this . client ( ` ${ fileId } ` , { responseType : "json" , } ) ; const getValue = ( index ) => body . wdFile . objectIndiceses . find ( ( di ) => di . index === index ) ?. value ; const { fileName } = body . wdFile ; const examDateTime = getValue ( "e_date" ) ; const examDate = examDateTime . split ( "T" ) [ 0 ] ; const student = { kthId : getValue ( "s_uid" ) , personNumber : getValue ( "s_pnr" ) , firstName : getValue ( "s_firstname" ) , lastName : getValue ( "s_lastname" ) , } ; if ( ! student . kthId ) throw new Error ( ` ${ fileId } ` ) ; return { content : Readable . from ( Buffer . from ( body . wdFile . fileAsBase64 . toString ( "utf-8" ) , "base64" ) ) , fileName , student , examDate , } ; }
Download the exam with ID "fileId".
Download the exam with ID " fileId " .