Skip to content

Commit

Permalink
feat: save main.crdt file
Browse files Browse the repository at this point in the history
  • Loading branch information
meelrossi committed Aug 9, 2023
1 parent f7b8a22 commit 054ecb7
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
37 changes: 36 additions & 1 deletion src/Project/Project.router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -137,6 +137,28 @@ export class ProjectRouter extends Router {
),
server.handleRequest(this.uploadFiles)
)

this.router.put(
'/projects/:id/crdt',
withAuthentication,

Check failure

Code scanning / CodeQL

Missing rate limiting High

This route handler performs
authorization
, but is not rate-limited.
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,

Check failure

Code scanning / CodeQL

Missing rate limiting High

This route handler performs
authorization
, but is not rate-limited.
withProjectExists,
withProjectAuthorization,
this.getCrdt
)
}

async getProjects(req: AuthRequest) {
Expand Down Expand Up @@ -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
)
}
}
1 change: 1 addition & 0 deletions src/S3/crdt.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const CRDT_FILENAME = 'main.crdt'
1 change: 1 addition & 0 deletions src/S3/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export * from './s3'
export * from './manifest'
export * from './crdt'
export * from './pool'
export * from './uploads'
export * from './S3Project'
Expand Down

0 comments on commit 054ecb7

Please sign in to comment.