diff --git a/src/Project/Project.router.ts b/src/Project/Project.router.ts index 2ec19d29..77be977d 100644 --- a/src/Project/Project.router.ts +++ b/src/Project/Project.router.ts @@ -11,7 +11,7 @@ import { withModelExists, withModelAuthorization, } from '../middleware' -import { S3Project, getBucketURL, getUploader } from '../S3' +import { S3Project, getBucketURL, getUploader, CRDT_FILENAME } from '../S3' import { withAuthentication, AuthRequest } from '../middleware/authentication' import { Ownable } from '../Ownable' import { Project } from './Project.model' @@ -137,6 +137,28 @@ export class ProjectRouter extends Router { ), server.handleRequest(this.uploadFiles) ) + + this.router.put( + '/projects/:id/crdt', + withAuthentication, + withProjectExists, + withProjectAuthorization, + getUploader({ + getFileKey: async (_file, req) => { + const id = server.extractFromReq(req, 'id') + return new S3Project(id).getFileKey(CRDT_FILENAME) + }, + }).any(), + server.handleRequest(this.upsertCrdt) + ) + + this.router.get( + '/projects/:id/crdt', + withAuthentication, + withProjectExists, + withProjectAuthorization, + this.getCrdt + ) } async getProjects(req: AuthRequest) { @@ -258,4 +280,17 @@ export class ProjectRouter extends Router { return true } + + async upsertCrdt(_req: AuthRequest) { + return true + } + + async getCrdt(req: Request, res: Response) { + const id = server.extractFromReq(req, 'id') + + return res.redirect( + `${getBucketURL()}/${(new S3Project(id)).getFileKey(CRDT_FILENAME)}`, + 301 + ) + } } diff --git a/src/S3/crdt.ts b/src/S3/crdt.ts new file mode 100644 index 00000000..230a50bf --- /dev/null +++ b/src/S3/crdt.ts @@ -0,0 +1 @@ +export const CRDT_FILENAME = 'main.crdt' diff --git a/src/S3/index.ts b/src/S3/index.ts index 62d6b768..fb6ce4ef 100644 --- a/src/S3/index.ts +++ b/src/S3/index.ts @@ -1,5 +1,6 @@ export * from './s3' export * from './manifest' +export * from './crdt' export * from './pool' export * from './uploads' export * from './S3Project'