Skip to content

Commit 1141d81

Browse files
committed
Add initial jupyterlite support
1 parent 530d4ff commit 1141d81

File tree

3 files changed

+90
-64
lines changed

3 files changed

+90
-64
lines changed

package-lock.json

Lines changed: 35 additions & 24 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
@@ -41,7 +41,7 @@
4141
],
4242
"dependencies": {
4343
"@fails-components/config": "^1.3.0",
44-
"@fails-components/security": "^1.3.2",
44+
"@fails-components/security": "^1.4.1",
4545
"@socket.io/redis-adapter": "^7.1.0",
4646
"bson": "^4.7.0",
4747
"cidr-matcher": "^2.1.1",

src/commonhandler.js

Lines changed: 54 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -24,51 +24,58 @@ import { serialize as BSONserialize } from 'bson'
2424
import { createHash, webcrypto as crypto } from 'crypto'
2525

2626
export class CommonConnection {
27-
async getBgpdf(notepadscreenid) {
27+
async getUsedAssets(notepadscreenid) {
2828
let lecturedoc = {}
2929
try {
3030
const lecturescol = this.mongo.collection('lectures')
3131
lecturedoc = await lecturescol.findOne(
3232
{ uuid: notepadscreenid.lectureuuid },
3333
{
34-
projection: { _id: 0, backgroundpdfuse: 1, backgroundpdf: 1 }
34+
projection: {
35+
_id: 0,
36+
usedpictures: 1,
37+
backgroundpdfuse: 1,
38+
backgroundpdf: 1,
39+
usedipynbs: 1
40+
}
3541
}
3642
)
37-
// console.log("lecturedoc",lecturedoc);
38-
if (
39-
!lecturedoc.backgroundpdfuse ||
40-
!lecturedoc.backgroundpdf ||
41-
!lecturedoc.backgroundpdf.sha
42-
)
43-
return null
44-
return this.getFileURL(lecturedoc.backgroundpdf.sha, 'application/pdf')
45-
} catch (err) {
46-
console.log('error in getBgpdf pictures', err)
47-
}
48-
}
4943

50-
async getUsedPicts(notepadscreenid) {
51-
let lecturedoc = {}
52-
try {
53-
const lecturescol = this.mongo.collection('lectures')
54-
lecturedoc = await lecturescol.findOne(
55-
{ uuid: notepadscreenid.lectureuuid },
56-
{
57-
projection: { _id: 0, usedpictures: 1 }
58-
}
59-
)
60-
// console.log("lecturedoc",lecturedoc);
61-
if (!lecturedoc.usedpictures) return []
62-
63-
return lecturedoc.usedpictures.map((el) => {
64-
return {
65-
name: el.name,
66-
mimetype: el.mimetype,
67-
sha: el.sha.buffer.toString('hex'),
68-
url: this.getFileURL(el.sha.buffer, el.mimetype),
69-
urlthumb: this.getFileURL(el.tsha.buffer, el.mimetype)
70-
}
71-
})
44+
return {
45+
usedpict:
46+
lecturedoc.usedpictures?.map?.((el) => {
47+
return {
48+
name: el.name,
49+
mimetype: el.mimetype,
50+
sha: el.sha.buffer.toString('hex'),
51+
url: this.getFileURL(el.sha.buffer, el.mimetype),
52+
urlthumb: this.getFileURL(el.tsha.buffer, el.mimetype)
53+
}
54+
}) || [],
55+
bgpdf:
56+
(lecturedoc.backgroundpdfuse &&
57+
lecturedoc.backgroundpdf &&
58+
lecturedoc.backgroundpdf.sha &&
59+
this.getFileURL(lecturedoc.backgroundpdf.sha, 'application/pdf')) ||
60+
null,
61+
usedipynbs:
62+
lecturedoc.usedipynbs?.map?.((el) => {
63+
return {
64+
name: el.name,
65+
filename: el.filename,
66+
/* note: el.note, */
67+
mimetype: el.mimetype,
68+
id: el.id,
69+
sha: el.sha.buffer.toString('hex'),
70+
applets: el.applets?.map?.((applet) => ({
71+
appid: applet.appid,
72+
appname: applet.appname
73+
})),
74+
url: this.getFileURL(el.sha.buffer, el.mimetype)
75+
}
76+
}) || []
77+
}
78+
7279
// ok now I have the picture, but I also have to generate the urls
7380
} catch (err) {
7481
console.log('error in getUsedPicts pictures', err)
@@ -77,17 +84,25 @@ export class CommonConnection {
7784

7885
async sendBoardsToSocket(lectureuuid, socket) {
7986
// we have to send first information about pictures
80-
81-
const usedpict = await this.getUsedPicts({ lectureuuid: lectureuuid })
87+
// TODO use one mongo transaction
88+
const {
89+
usedpict = undefined,
90+
bgpdf = null,
91+
usedipynbs = undefined
92+
} = await this.getUsedAssets({
93+
lectureuuid: lectureuuid
94+
})
8295
if (usedpict) {
8396
socket.emit('pictureinfo', usedpict)
8497
}
85-
const bgpdf = await this.getBgpdf({ lectureuuid: lectureuuid })
8698
if (bgpdf) {
8799
socket.emit('bgpdfinfo', { bgpdfurl: bgpdf })
88100
} else {
89101
socket.emit('bgpdfinfo', { none: true })
90102
}
103+
if (usedipynbs) {
104+
socket.emit('ipynbinfo', { ipynbs: usedipynbs })
105+
}
91106

92107
try {
93108
const res = await this.redis.sMembers(

0 commit comments

Comments
 (0)