Skip to content

Commit

Permalink
Partial jupyter support
Browse files Browse the repository at this point in the history
  • Loading branch information
martenrichter committed Jan 1, 2025
1 parent 1ee0887 commit c3de46f
Show file tree
Hide file tree
Showing 5 changed files with 287 additions and 74 deletions.
74 changes: 42 additions & 32 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@
],
"dependencies": {
"@fails-components/config": "^1.3.0",
"@fails-components/data": "^1.2.0",
"@fails-components/security": "^1.3.2",
"@fails-components/data": "^1.4.0",
"@fails-components/security": "^1.4.1",
"@socket.io/redis-adapter": "^7.1.0",
"bson": "^4.7.0",
"cidr-matcher": "^2.1.1",
Expand Down
93 changes: 54 additions & 39 deletions src/commonhandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,51 +24,58 @@ import { serialize as BSONserialize } from 'bson'
import { createHash, webcrypto as crypto } from 'crypto'

export class CommonConnection {
async getBgpdf(notepadscreenid) {
async getUsedAssets(notepadscreenid) {
let lecturedoc = {}
try {
const lecturescol = this.mongo.collection('lectures')
lecturedoc = await lecturescol.findOne(
{ uuid: notepadscreenid.lectureuuid },
{
projection: { _id: 0, backgroundpdfuse: 1, backgroundpdf: 1 }
projection: {
_id: 0,
usedpictures: 1,
backgroundpdfuse: 1,
backgroundpdf: 1,
usedipynbs: 1
}
}
)
// console.log("lecturedoc",lecturedoc);
if (
!lecturedoc.backgroundpdfuse ||
!lecturedoc.backgroundpdf ||
!lecturedoc.backgroundpdf.sha
)
return null
return this.getFileURL(lecturedoc.backgroundpdf.sha, 'application/pdf')
} catch (err) {
console.log('error in getBgpdf pictures', err)
}
}

async getUsedPicts(notepadscreenid) {
let lecturedoc = {}
try {
const lecturescol = this.mongo.collection('lectures')
lecturedoc = await lecturescol.findOne(
{ uuid: notepadscreenid.lectureuuid },
{
projection: { _id: 0, usedpictures: 1 }
}
)
// console.log("lecturedoc",lecturedoc);
if (!lecturedoc.usedpictures) return []

return lecturedoc.usedpictures.map((el) => {
return {
name: el.name,
mimetype: el.mimetype,
sha: el.sha.buffer.toString('hex'),
url: this.getFileURL(el.sha.buffer, el.mimetype),
urlthumb: this.getFileURL(el.tsha.buffer, el.mimetype)
}
})
return {
usedpict:
lecturedoc.usedpictures?.map?.((el) => {
return {
name: el.name,
mimetype: el.mimetype,
sha: el.sha.buffer.toString('hex'),
url: this.getFileURL(el.sha.buffer, el.mimetype),
urlthumb: this.getFileURL(el.tsha.buffer, el.mimetype)
}
}) || [],
bgpdf:
(lecturedoc.backgroundpdfuse &&
lecturedoc.backgroundpdf &&
lecturedoc.backgroundpdf.sha &&
this.getFileURL(lecturedoc.backgroundpdf.sha, 'application/pdf')) ||
null,
usedipynbs:
lecturedoc.usedipynbs?.map?.((el) => {
return {
name: el.name,
filename: el.filename,
/* note: el.note, */
mimetype: el.mimetype,
id: el.id,
sha: el.sha.buffer.toString('hex'),
applets: el.applets?.map?.((applet) => ({
appid: applet.appid,
appname: applet.appname
})),
url: this.getFileURL(el.sha.buffer, el.mimetype)
}
}) || []
}

// ok now I have the picture, but I also have to generate the urls
} catch (err) {
console.log('error in getUsedPicts pictures', err)
Expand All @@ -77,17 +84,25 @@ export class CommonConnection {

async sendBoardsToSocket(lectureuuid, socket) {
// we have to send first information about pictures

const usedpict = await this.getUsedPicts({ lectureuuid: lectureuuid })
// TODO use one mongo transaction
const {
usedpict = undefined,
bgpdf = null,
usedipynbs = undefined
} = await this.getUsedAssets({
lectureuuid: lectureuuid
})
if (usedpict) {
socket.emit('pictureinfo', usedpict)
}
const bgpdf = await this.getBgpdf({ lectureuuid: lectureuuid })
if (bgpdf) {
socket.emit('bgpdfinfo', { bgpdfurl: bgpdf })
} else {
socket.emit('bgpdfinfo', { none: true })
}
if (usedipynbs) {
socket.emit('ipynbinfo', { ipynbs: usedipynbs })
}

try {
const res = await this.redis.sMembers(
Expand Down
Loading

0 comments on commit c3de46f

Please sign in to comment.