Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions js/editor-rich.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/editor-rich.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions js/editor.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/editor.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions js/files-modal.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion js/files-modal.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions js/text-files.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/text-files.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions js/text-public.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/text-public.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions js/text-text.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/text-text.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions js/text-viewer.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/text-viewer.js.map

Large diffs are not rendered by default.

10 changes: 9 additions & 1 deletion lib/Service/ApiService.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,18 @@ public function create($fileId = null, $filePath = null, $token = null, $guestNa
}

$session = $this->sessionService->initSession($document->getId(), $guestName);
try {
$baseFile = $this->documentService->getBaseFile($document->getId());
$content = $baseFile->getContent();
} catch (NotFoundException $e) {
$this->logger->logException($e, ['level' => ILogger::INFO]);
$content = null;
}
return new DataResponse([
'document' => $document,
'session' => $session,
'readOnly' => $readOnly
'readOnly' => $readOnly,
'content' => $content
]);
}

Expand Down
21 changes: 7 additions & 14 deletions src/components/EditorWrapper.vue
Original file line number Diff line number Diff line change
Expand Up @@ -463,20 +463,13 @@ export default {
this.readOnly = true
this.tiptap.setOptions({ editable: !this.readOnly })
})
if (this.initialSession === null) {
this.syncService.open({
fileId: this.fileId,
filePath: this.relativePath,
}).catch((e) => {
this.hasConnectionIssue = true
})
} else {
this.syncService.open({
initialSession: this.initialSession,
}).catch((e) => {
this.hasConnectionIssue = true
})
}
this.syncService.open({
fileId: this.fileId,
filePath: this.relativePath,
initialSession: this.initialSession,
}).catch((e) => {
this.hasConnectionIssue = true
})
this.forceRecreate = false
},

Expand Down
44 changes: 19 additions & 25 deletions src/services/SyncService.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,37 +97,21 @@ class SyncService {
}

async open({ fileId, filePath, initialSession }) {
let connectionData = null
if (typeof initialSession === 'undefined') {
try {
const response = await this._openDocument({ fileId, filePath })
connectionData = response.data
} catch (error) {
if (!error.response || error.code === 'ECONNABORTED') {
this.emit('error', ERROR_TYPE.CONNECTION_FAILED, {})
} else {
this.emit('error', ERROR_TYPE.LOAD_ERROR, error.response.status)
}
throw error
}
} else {
connectionData = initialSession
}

const connectionData = initialSession
|| await this._openDocument({ fileId, filePath })
this.document = connectionData.document
this.document.readOnly = connectionData.readOnly
this.session = connectionData.session

this.emit('opened', {
document: this.document,
session: this.session,
})
return this._fetchDocument().then(({ data }) => {
this.emit('loaded', {
document: this.document,
session: this.session,
documentSource: '' + data,
})
const content = connectionData.content
|| await this._fetchDocument()
this.emit('loaded', {
document: this.document,
session: this.session,
documentSource: '' + content,
})
}

Expand All @@ -143,6 +127,14 @@ class SyncService {
guestName: this.options.guestName,
forceRecreate: this.options.forceRecreate,
})
.then(response => response.data, error => {
if (!error.response || error.code === 'ECONNABORTED') {
this.emit('error', ERROR_TYPE.CONNECTION_FAILED, {})
} else {
this.emit('error', ERROR_TYPE.LOAD_ERROR, error.response.status)
}
throw error
})
}

_fetchDocument() {
Expand All @@ -153,9 +145,11 @@ class SyncService {
sessionToken: this.session.token,
token: this.options.shareToken,
}, {
// Axios normally tries to parse string responses as json.
// Just return the plain content here.
transformResponse: [(data) => data],
}
)
).then(response => response.data)
}

updateSession(guestName) {
Expand Down