Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Load public share link file creation again #548

Merged
merged 2 commits into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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.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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better use @nextcloud/router for generateUrl ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

src/helpers/url.js could also use that fix.

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 @@
render: h => h(Office, { props: { fileName: document.getElementById('filename').value } }),
}).$mount('#imgframe')
}

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