Skip to content

Commit

Permalink
fix: Load public share link file creation again
Browse files Browse the repository at this point in the history
Signed-off-by: Julius Härtl <[email protected]>
  • Loading branch information
juliusknorr committed Apr 16, 2024
1 parent 60358d1 commit 31e1404
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 6 deletions.
8 changes: 3 additions & 5 deletions lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,10 @@
use OC\Files\Type\Detection;
use OC\Security\CSP\ContentSecurityPolicy;
use OCA\Federation\TrustedServers;
use OCA\Files\Event\LoadAdditionalScriptsEvent;
use OCA\Files_Sharing\Listener\LoadAdditionalListener;
use OCA\Files_Sharing\Event\BeforeTemplateRenderedEvent;
use OCA\Officeonline\Capabilities;
use OCA\Officeonline\Hooks\WopiLockHooks;
use OCA\Officeonline\Listener\FilesScriptListener;
use OCA\Officeonline\Listener\SharingLoadAdditionalScriptsListener;
use OCA\Officeonline\Listener\LoadViewerListener;
use OCA\Officeonline\Middleware\WOPIMiddleware;
use OCA\Officeonline\PermissionManager;
Expand Down Expand Up @@ -63,8 +62,7 @@ public function __construct(array $urlParams = []) {
public function register(IRegistrationContext $context): void {
$context->registerCapability(Capabilities::class);
$context->registerMiddleWare(WOPIMiddleware::class);
$context->registerEventListener(LoadAdditionalScriptsEvent::class, FilesScriptListener::class);
$context->registerEventListener(LoadAdditionalListener::class, FilesScriptListener::class);
$context->registerEventListener(BeforeTemplateRenderedEvent::class, SharingLoadAdditionalScriptsListener::class);
$context->registerEventListener(LoadViewer::class, LoadViewerListener::class);
}

Expand Down
2 changes: 1 addition & 1 deletion src/document.js
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ const documentsMain = {
}, 45000)
})

$('#loleafletframe').load(function() {
$('#loleafletframe').on('load', function() {
const ViewerToLool = [
'Action_FollowUser',
'Host_VersionRestore',
Expand Down
75 changes: 75 additions & 0 deletions src/files.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import Types from './helpers/types'
import axios from '@nextcloud/axios'
import { getCapabilities } from '@nextcloud/capabilities'
import './viewer.js'
import Vue from 'vue'
Expand All @@ -16,6 +18,77 @@ Vue.prototype.n = window.n
Vue.prototype.OC = window.OC
Vue.prototype.OCA = window.OCA

const NewFilePlugin = {
attach: function(newFileMenu) {
const self = this
const document = Types.getFileType('document')
const spreadsheet = Types.getFileType('spreadsheet')
const presentation = Types.getFileType('presentation')

newFileMenu.addMenuEntry({
id: 'add-' + document.extension,
displayName: t('officeonline', 'New Document'),
templateName: t('officeonline', 'New Document') + '.' + document.extension,
iconClass: 'icon-filetype-document',
fileType: 'x-office-document',
actionHandler: function(filename) {
self._createDocument(document.mime, filename)
},
})

newFileMenu.addMenuEntry({
id: 'add-' + spreadsheet.extension,
displayName: t('officeonline', 'New Spreadsheet'),
templateName: t('officeonline', 'New Spreadsheet') + '.' + spreadsheet.extension,
iconClass: 'icon-filetype-spreadsheet',
fileType: 'x-office-spreadsheet',
actionHandler: function(filename) {
self._createDocument(spreadsheet.mime, filename)
},
})

newFileMenu.addMenuEntry({
id: 'add-' + presentation.extension,
displayName: t('officeonline', 'New Presentation'),
templateName: t('officeonline', 'New Presentation') + '.' + presentation.extension,
iconClass: 'icon-filetype-presentation',
fileType: 'x-office-presentation',
actionHandler: function(filename) {
self._createDocument(presentation.mime, filename)
},
})
},

_createDocument: function(mimetype, filename) {
const dir = document.getElementById('dir') ? document.getElementById('dir').value : window.FileList.getCurrentDirectory()
try {
OCA.Files.Files.isFileNameValid(filename)
} catch (e) {
window.OC.dialogs.alert(e, t('core', 'Could not create file'))
return
}
filename = FileList.getUniqueName(filename)
const path = dir + '/' + filename

const isPublic = document.getElementById('isPublic') ? document.getElementById('isPublic').value === '1' : false
if (isPublic) {
return window.FileList.createFile(filename).then(function() {
OCA.Viewer.open({ path })
})
}

axios.post(OC.generateUrl('apps/officeonline/ajax/documents/create'), { mimetype, filename, dir }).then(({ data }) => {

Check warning on line 80 in src/files.js

View workflow job for this annotation

GitHub Actions / NPM lint

The property or function OC.generateUrl was deprecated in Nextcloud 19.0.0

Check warning on line 80 in src/files.js

View workflow job for this annotation

GitHub Actions / NPM build

The property or function OC.generateUrl was deprecated in Nextcloud 19.0.0
console.debug(data)
if (data && data.status === 'success') {
window.FileList.add(data.data, { animate: true, scrollTo: true })
window.OCA.Viewer.open({ path })
} else {
window.OC.dialogs.alert(data.data.message, t('core', 'Could not create file'))
}
})
},
}

document.addEventListener('DOMContentLoaded', () => {
// PUBLIC SHARE LINK HANDLING
const isPublic = document.getElementById('isPublic') ? document.getElementById('isPublic').value === '1' : false
Expand All @@ -29,4 +102,6 @@ document.addEventListener('DOMContentLoaded', () => {
render: h => h(Office, { props: { fileName: document.getElementById('filename').value } }),
}).$mount('#imgframe')
}

OC.Plugins.register('OCA.Files.NewFileMenu', NewFilePlugin)
})

0 comments on commit 31e1404

Please sign in to comment.