Skip to content

Commit

Permalink
fix: Use document id in url
Browse files Browse the repository at this point in the history
Signed-off-by: Julius Härtl <jus@bitgrid.net>
  • Loading branch information
juliusknorr committed Nov 28, 2023
1 parent ba90d68 commit 47fc551
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 42 deletions.
24 changes: 12 additions & 12 deletions appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,30 +43,30 @@
['name' => 'Attachment#getMediaFileMetadata', 'url' => '/mediaMetadata', 'verb' => 'GET'],

/** @see Controller\SessionController::create() */
['name' => 'Session#create', 'url' => '/session/create', 'verb' => 'PUT'],
['name' => 'Session#create', 'url' => '/session/{documentId}/create', 'verb' => 'PUT'],
/** @see Controller\SessionController::save() */
['name' => 'Session#save', 'url' => '/session/save', 'verb' => 'POST'],
['name' => 'Session#save', 'url' => '/session/{documentId}/save', 'verb' => 'POST'],
/** @see Controller\SessionController::sync() */
['name' => 'Session#sync', 'url' => '/session/sync', 'verb' => 'POST'],
['name' => 'Session#sync', 'url' => '/session/{documentId}/sync', 'verb' => 'POST'],
/** @see Controller\SessionController::push() */
['name' => 'Session#push', 'url' => '/session/push', 'verb' => 'POST'],
['name' => 'Session#push', 'url' => '/session/{documentId}/push', 'verb' => 'POST'],
/** @see Controller\SessionController::close() */
['name' => 'Session#close', 'url' => '/session/close', 'verb' => 'POST'],
['name' => 'Session#close', 'url' => '/session/{documentId}/close', 'verb' => 'POST'],
/** @see Controller\SessionController::mention() */
['name' => 'Session#mention', 'url' => '/session/mention', 'verb' => 'PUT'],
['name' => 'Session#mention', 'url' => '/session/{documentId}/mention', 'verb' => 'PUT'],

/** @see Controller\PublicSessionController::create() */
['name' => 'PublicSession#create', 'url' => '/public/session/create', 'verb' => 'PUT'],
['name' => 'PublicSession#create', 'url' => '/public/session/{documentId}/create', 'verb' => 'PUT'],
/** @see Controller\PublicSessionController::updateSession() */
['name' => 'PublicSession#updateSession', 'url' => '/public/session', 'verb' => 'POST'],
['name' => 'PublicSession#updateSession', 'url' => '/public/session/{documentId}/session', 'verb' => 'POST'],
/** @see Controller\PublicSessionController::save() */
['name' => 'PublicSession#save', 'url' => '/public/session/save', 'verb' => 'POST'],
['name' => 'PublicSession#save', 'url' => '/public/session/{documentId}/save', 'verb' => 'POST'],
/** @see Controller\PublicSessionController::sync() */
['name' => 'PublicSession#sync', 'url' => '/public/session/sync', 'verb' => 'POST'],
['name' => 'PublicSession#sync', 'url' => '/public/session/{documentId}/sync', 'verb' => 'POST'],
/** @see Controller\PublicSessionController::push() */
['name' => 'PublicSession#push', 'url' => '/public/session/push', 'verb' => 'POST'],
['name' => 'PublicSession#push', 'url' => '/public/session/{documentId}/push', 'verb' => 'POST'],
/** @see Controller\PublicSessionController::close() */
['name' => 'PublicSession#close', 'url' => '/public/session/close', 'verb' => 'POST'],
['name' => 'PublicSession#close', 'url' => '/public/session/{documentId}/close', 'verb' => 'POST'],

/** @see Controller\SettingsController::updateConfig() */
['name' => 'Settings#updateConfig', 'url' => '/settings', 'verb' => 'POST'],
Expand Down
12 changes: 6 additions & 6 deletions cypress/e2e/api/SyncServiceProvider.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ describe('Sync service provider', function() {
it('recovers from a dropped message', function() {
const sourceMap = this.source.getMap()
const targetMap = this.target.getMap()
cy.intercept({ method: 'POST', url: '**/apps/text/session/push' })
cy.intercept({ method: 'POST', url: '**/apps/text/session/*/push' })
.as('push')
cy.intercept({ method: 'POST', url: '**/apps/text/session/sync' })
cy.intercept({ method: 'POST', url: '**/apps/text/session/*/sync' })
.as('sync')
cy.wait('@push')
cy.then(() => {
Expand All @@ -95,7 +95,7 @@ describe('Sync service provider', function() {
})
cy.intercept({
method: 'POST',
url: '**/apps/text/session/push',
url: '**/apps/text/session/*/push',
}, req => {
if (req.body.steps) {
req.reply({ forceNetworkError: true })
Expand All @@ -114,7 +114,7 @@ describe('Sync service provider', function() {
})
cy.intercept({
method: 'POST',
url: '**/apps/text/session/push',
url: '**/apps/text/session/*/push',
}, req => {
if (req.body.steps) {
req.alias = 'alive'
Expand Down Expand Up @@ -143,9 +143,9 @@ describe('Sync service provider', function() {
it.skip('is not too chatty', function() {
const sourceMap = this.source.getMap()
const targetMap = this.target.getMap()
cy.intercept({ method: 'POST', url: '**/apps/text/session/push' })
cy.intercept({ method: 'POST', url: '**/apps/text/session/*/push' })
.as('push')
cy.intercept({ method: 'POST', url: '**/apps/text/session/sync' })
cy.intercept({ method: 'POST', url: '**/apps/text/session/*/sync' })
.as('sync')
cy.wait('@push')
cy.then(() => {
Expand Down
18 changes: 9 additions & 9 deletions cypress/e2e/directediting.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ describe('direct editing', function() {
})

it('Open an existing file, edit it', () => {
cy.intercept({ method: 'POST', url: '**/session/close' }).as('closeRequest')
cy.intercept({ method: 'POST', url: '**/session/push' }).as('push')
cy.intercept({ method: 'POST', url: '**/session/sync' }).as('sync')
cy.intercept({ method: 'POST', url: '**/session/*/close' }).as('closeRequest')
cy.intercept({ method: 'POST', url: '**/session/*/push' }).as('push')
cy.intercept({ method: 'POST', url: '**/session/*/sync' }).as('sync')

createDirectEditingLink(user, 'empty.md')
.then((token) => {
Expand All @@ -90,9 +90,9 @@ describe('direct editing', function() {
})

it('Create a file, edit it', () => {
cy.intercept({ method: 'POST', url: '**/session/close' }).as('closeRequest')
cy.intercept({ method: 'POST', url: '**/session/push' }).as('push')
cy.intercept({ method: 'POST', url: '**/session/sync' }).as('sync')
cy.intercept({ method: 'POST', url: '**/session/*/close' }).as('closeRequest')
cy.intercept({ method: 'POST', url: '**/session/*/push' }).as('push')
cy.intercept({ method: 'POST', url: '**/session/*/sync' }).as('sync')

createDirectEditingLinkForNewFile(user, 'newfile.md')
.then((token) => {
Expand All @@ -119,9 +119,9 @@ describe('direct editing', function() {
})

it('Open an existing plain text file, edit it', () => {
cy.intercept({ method: 'POST', url: '**/session/close' }).as('closeRequest')
cy.intercept({ method: 'POST', url: '**/session/push' }).as('push')
cy.intercept({ method: 'POST', url: '**/session/sync' }).as('sync')
cy.intercept({ method: 'POST', url: '**/session/*/close' }).as('closeRequest')
cy.intercept({ method: 'POST', url: '**/session/*/push' }).as('push')
cy.intercept({ method: 'POST', url: '**/session/*/sync' }).as('sync')

createDirectEditingLink(user, 'empty.txt')
.then((token) => {
Expand Down
2 changes: 1 addition & 1 deletion cypress/e2e/nodes/FrontMatter.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ describe('Front matter support', function() {
expect(pre.length === 1)
})
cy.closeFile()
cy.intercept({ method: 'POST', url: '**/apps/text/session/sync' }).as('sync')
cy.intercept({ method: 'POST', url: '**/apps/text/session/*/sync' }).as('sync')
cy.openFile('frontmatter.md')
cy.wait('@sync')
cy.wait('@sync')
Expand Down
2 changes: 1 addition & 1 deletion cypress/e2e/share.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ describe('Open test.md in viewer', function() {
})

it('makes use of the file id', function() {
cy.intercept({ method: 'PUT', url: '**/apps/text/public/session/create' })
cy.intercept({ method: 'PUT', url: '**/apps/text/public/session/*/create' })
.as('create')
cy.shareFile('/test2.md', { edit: true })
.then((token) => {
Expand Down
12 changes: 6 additions & 6 deletions cypress/e2e/sync.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ describe('Sync', () => {
cy.login(user)
cy.uploadTestFile('test.md')
cy.visit('/apps/files')
cy.intercept({ method: 'POST', url: '**/apps/text/session/sync' }).as('sync')
cy.intercept({ method: 'POST', url: '**/apps/text/session/save' }).as('save')
cy.intercept({ method: 'POST', url: '**/apps/text/session/*/sync' }).as('sync')
cy.intercept({ method: 'POST', url: '**/apps/text/session/*/save' }).as('save')
cy.openTestFile()
cy.getContent().find('h2').should('contain', 'Hello world')
cy.getContent().type('{moveToEnd}* Saving the doc saves the doc state{enter}')
Expand Down Expand Up @@ -63,7 +63,7 @@ describe('Sync', () => {

it('recovers from a short lost connection', () => {
let reconnect = false
cy.intercept('**/apps/text/session/*', (req) => {
cy.intercept('**/apps/text/session/*/*', (req) => {
if (reconnect) {
req.continue()
req.alias = 'alive'
Expand All @@ -79,7 +79,7 @@ describe('Sync', () => {
reconnect = true
})
cy.wait('@alive', { timeout: 30000 })
cy.intercept({ method: 'POST', url: '**/apps/text/session/sync' })
cy.intercept({ method: 'POST', url: '**/apps/text/session/*/sync' })
.as('syncAfterRecovery')
cy.wait('@syncAfterRecovery', { timeout: 30000 })
cy.get('#editor-container .document-status', { timeout: 30000 })
Expand All @@ -97,7 +97,7 @@ describe('Sync', () => {

it('recovers from a lost and closed connection', () => {
let reconnect = false
cy.intercept('**/apps/text/session/*', (req) => {
cy.intercept('**/apps/text/session/*/*', (req) => {
if (req.url.includes('close') || req.url.includes('create') || reconnect) {
req.continue()
req.alias = 'syncAfterRecovery'
Expand Down Expand Up @@ -128,7 +128,7 @@ describe('Sync', () => {

it('passes the doc content from one session to the next', () => {
cy.closeFile()
cy.intercept({ method: 'PUT', url: '**/apps/text/session/create' })
cy.intercept({ method: 'PUT', url: '**/apps/text/session/*/create' })
.as('create')
cy.openTestFile()
cy.wait('@create', { timeout: 10000 })
Expand Down
2 changes: 1 addition & 1 deletion cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ Cypress.Commands.add('openFileInShare', fileName => {
})

Cypress.Commands.add('closeFile', (params = {}) => {
cy.intercept({ method: 'POST', url: '**/apps/text/session/close' })
cy.intercept({ method: 'POST', url: '**/apps/text/session/*/close' })
.as('close')
cy.get('#viewer .modal-header button.header-close').click(params)
cy.get('#viewer .modal-header').should('not.exist')
Expand Down
12 changes: 6 additions & 6 deletions src/services/SessionApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class SessionApi {
}

open({ fileId }) {
return axios.put(this.#url('session/create'), {
return axios.put(this.#url(`session/${fileId}/create`), {
fileId,
filePath: this.#options.filePath,
token: this.#options.shareToken,
Expand Down Expand Up @@ -109,15 +109,15 @@ export class Connection {
}

sync({ version }) {
return this.#post(this.#url('session/sync'), {
return this.#post(this.#url(`session/${this.#document.id}/sync`), {
...this.#defaultParams,
filePath: this.#options.filePath,
version,
})
}

save({ version, autosaveContent, documentState, force, manualSave }) {
return this.#post(this.#url('session/save'), {
return this.#post(this.#url(`session/${this.#document.id}/save`), {
...this.#defaultParams,
filePath: this.#options.filePath,
version,
Expand All @@ -129,7 +129,7 @@ export class Connection {
}

push({ steps, version, awareness }) {
return this.#post(this.#url('session/push'), {
return this.#post(this.#url(`session/${this.#document.id}/push`), {
...this.#defaultParams,
filePath: this.#options.filePath,
steps,
Expand All @@ -140,7 +140,7 @@ export class Connection {

// TODO: maybe return a new connection here so connections have immutable state
update(guestName) {
return this.#post(this.#url('session'), {
return this.#post(this.#url(`session/${this.#document.id}/session`), {
...this.#defaultParams,
guestName,
}).then(({ data }) => {
Expand Down Expand Up @@ -173,7 +173,7 @@ export class Connection {
}

close() {
const promise = this.#post(this.#url('session/close'), this.#defaultParams)
const promise = this.#post(this.#url(`session/${this.#document.id}/close`), this.#defaultParams)
this.closed = true
return promise
}
Expand Down

0 comments on commit 47fc551

Please sign in to comment.