diff --git a/source/server/integration.test.ts b/source/server/integration.test.ts index d1f952fd..241ee623 100644 --- a/source/server/integration.test.ts +++ b/source/server/integration.test.ts @@ -117,6 +117,7 @@ describe("Web Server Integration", function(){ .set("Content-Type", "application/si-dpo-3d.document+json") .send(c) .expect(204); + let {text} = await this.agent.get("/scenes/foo/foo.svx.json") .expect(200) .expect("Content-Type", "application/si-dpo-3d.document+json"); diff --git a/source/server/migrations/004-node-ids.sql b/source/server/migrations/004-node-ids.sql index 9d618838..ab2a1c71 100644 --- a/source/server/migrations/004-node-ids.sql +++ b/source/server/migrations/004-node-ids.sql @@ -14,7 +14,7 @@ WITH src AS ( json_group_array( json_set( json_extract(data,'$.nodes[' || key || ']'), - '$.id', hex(randomBlob(6)) + '$.id', lower(hex(randomBlob(6))) ) ) as data FROM src, json_each(src.nodes) diff --git a/source/server/routes/scenes/put/document.test.ts b/source/server/routes/scenes/put/document.test.ts index d00bc2c6..8783a216 100644 --- a/source/server/routes/scenes/put/document.test.ts +++ b/source/server/routes/scenes/put/document.test.ts @@ -20,7 +20,7 @@ describe("PUT /scenes/:scene/scene.svx.json", function(){ let titleSlug :string, scene_id :number, sampleDoc :any; this.beforeAll(async function(){ - let locals = await createIntegrationContext(this); + let locals = await createIntegrationContext(this, {enable_document_merge: true}); vfs = locals.vfs; userManager = locals.userManager; user = await userManager.addUser("bob", "12345678"); diff --git a/source/server/routes/scenes/put/document.ts b/source/server/routes/scenes/put/document.ts index c7786c31..ae70ca09 100644 --- a/source/server/routes/scenes/put/document.ts +++ b/source/server/routes/scenes/put/document.ts @@ -2,32 +2,31 @@ import {inspect} from "util"; import path from "path"; import { Request, Response } from "express"; -import { getUserId, getVfs } from "../../../utils/locals.js"; +import { getLocals, getUserId, getVfs } from "../../../utils/locals.js"; import { BadRequestError } from "../../../utils/errors.js"; import * as merge from "../../../utils/merge/index.js"; - /** * Special handler for svx files to disallow the upload of invalid JSON. * @todo Should check against the official json schema using ajv * If the user provides a reference document ID and the document has been updated since, a diff is performed to try to merge the changes. */ export default async function handlePutDocument(req :Request, res :Response){ + const {config} = getLocals(req); const uid = getUserId(req); const {scene} = req.params; const newDoc = req.body; const refId = newDoc?.asset?.id; + if(typeof refId !== "undefined") delete newDoc.asset.id; //Don't write this to DB if(typeof newDoc !== "object"|| !Object.keys(newDoc).length) throw new BadRequestError(`Invalid json document`); - if(!refId){ + if(!refId || !config.enable_document_merge){ await getVfs(req).writeDoc(JSON.stringify(newDoc), scene, uid); return res.status(204).send(); } - delete newDoc.asset.id; //Don't write this to DB - await getVfs(req).isolate(async (tr)=>{ // perform a diff of the document with the reference one const {id: scene_id} = await tr.getScene(scene); diff --git a/source/server/utils/config.ts b/source/server/utils/config.ts index 4f18eb69..3c112c14 100644 --- a/source/server/utils/config.ts +++ b/source/server/utils/config.ts @@ -20,6 +20,10 @@ const values = { hot_reload:[false, toBool], smart_host: ["smtp://localhost", toString], verbose: [false, toBool], + + /// FEATURE FLAGS /// + enable_document_merge: [false, toBool], + } as const;