Skip to content

Commit dab309a

Browse files
authored
Merge pull request #26 from CedricProfessionnel/avaToDevDependencie
Fix collaboration server
2 parents ad71792 + f5d26a6 commit dab309a

File tree

6 files changed

+17
-14
lines changed

6 files changed

+17
-14
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
node_modules
22
*.db
33
.idea
4-
launch.json
4+
launch.json
5+
.vscode

releaserc.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ module.exports = {
1010
{
1111
assets: ["package.json"],
1212
message:
13-
"chore(release): ${nextRelease.version} [skip ci]
14-
15-
${nextRelease.notes}",
13+
"chore(release): ${nextRelease.version} [skip ci] ${nextRelease.notes}",
1614
},
1715
],
1816
],

src/router.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ const welcome = (req, res) =>
1818
const notfound = (req, res) => micro.send(res, 404)
1919

2020
module.exports = router(
21-
post("/api/session", postSessionEndpoint),
22-
options("/api/session", postSessionEndpoint),
2321
get("/api/session/:session_id/download", downloadEndpoint),
2422
get("/api/session/:session_id/diffs", getDiffsEndpoint),
2523
options("/api/session/:session_id/diffs", getDiffsEndpoint),
@@ -28,6 +26,8 @@ module.exports = router(
2826
get("/api/session/:session_id", getSessionEndpoint),
2927
patch("/api/session/:session_id", patchSessionEndpoint),
3028
options("/api/session/:session_id", patchSessionEndpoint),
29+
post("/api/session", postSessionEndpoint),
30+
options("/api/session", postSessionEndpoint),
3131
get("/", welcome),
3232
get("/*", notfound)
3333
)

src/utils/apply-add-sample-patch.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
module.exports = async ({ db, patch, sessionId, workingSummaryObject }) => {
22
const numSamples = workingSummaryObject.summary.samples.length
33
db.prepare(
4-
"INSERT INTO sample_state (sample_index, session_short_id, content) VALUES (?, ?, ?)"
5-
).run(numSamples, sessionId, JSON.stringify(patch.value))
4+
"INSERT INTO sample_state (sample_index, sample_ref_id, session_short_id, content) VALUES (?, ?, ?, ?)"
5+
).run(numSamples, patch.value._id, sessionId, JSON.stringify(patch.value))
66

77
const sample = db
88
.prepare(

src/utils/apply-patch.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ module.exports = async ({ db, patch: patches, sessionId, userName = null }) => {
1616
for (const patch of patches) {
1717
if (patch.path.startsWith("/samples/") && patch.op === "add") {
1818
await applyAddSamplePatch({ db, patch, sessionId, workingSummaryObject })
19-
} else if (patch.path.startsWith("/samples/")) {
19+
} else if (
20+
patch.path.startsWith("/sample/") ||
21+
patch.path.startsWith("/samples/")
22+
) {
2023
await applySamplePatch({ db, patch, sessionId, workingSummaryObject })
2124
} else {
2225
await applySummaryPatch({ db, patch, sessionId, workingSummaryObject })

src/utils/apply-sample-patch.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
const fjp = require("fast-json-patch")
2-
const samplePathRe = /\/samples\/([^/]+)(.*)/
2+
const samplePathRe = "\\/(sample|samples)\\/([^/]+)(.*)"
33
const applyRemoveSample = require("./apply-remove-sample")
44
const getSampleIndexAndId = require("./get-sample-index-and-id")
55

66
module.exports = async ({ db, patch, sessionId, workingSummaryObject }) => {
77
// Get relevant sample existing data
88
const m = patch.path.match(samplePathRe)
9-
if (!m[1]) throw new Error(`Invalid sample patch to path "${patch.path}"`)
9+
if (!m[2]) throw new Error(`Invalid sample patch to path "${patch.path}"`)
1010

11-
let { sampleIndex, sampleId } = getSampleIndexAndId(sessionId, m[1])
12-
let sampleChangePath = m[2]
11+
let { sampleIndex, sampleId } = getSampleIndexAndId(sessionId, m[2])
12+
let sampleChangePath = m[3]
1313

1414
if (patch.op === "replace" && !sampleChangePath) {
1515
sampleChangePath = ""
@@ -42,9 +42,10 @@ module.exports = async ({ db, patch, sessionId, workingSummaryObject }) => {
4242
// Update sample in database with new content and new version
4343

4444
db.prepare(
45-
"UPDATE sample_state SET sample_version=?, content=? WHERE session_short_id=? AND sample_ref_id=?"
45+
"UPDATE sample_state SET sample_version=?, sample_ref_id=?, content=? WHERE session_short_id=? AND sample_ref_id=?"
4646
).run(
4747
sample.sample_version + 1,
48+
newSampleContent._id,
4849
JSON.stringify(newSampleContent),
4950
sessionId,
5051
sampleId

0 commit comments

Comments
 (0)