diff options
author | John Molakvoæ <skjnldsv@protonmail.com> | 2021-09-17 10:52:02 +0300 |
---|---|---|
committer | backportbot[bot] <backportbot[bot]@users.noreply.github.com> | 2021-09-17 23:22:54 +0300 |
commit | 265aedc6e54344e18b457070a4349b855801ca0e (patch) | |
tree | af8c8fc3e3e0c81f73f7a6da71f9f3b6c7e3c2cb /apps/files | |
parent | 8eb6dd8ed50995be794c0ea477e3baf65babbcae (diff) |
Fix file creation from template without ext
Signed-off-by: John Molakvoæ <skjnldsv@protonmail.com>
Diffstat (limited to 'apps/files')
-rw-r--r-- | apps/files/src/services/Templates.js | 16 | ||||
-rw-r--r-- | apps/files/src/views/TemplatePicker.vue | 16 |
2 files changed, 27 insertions, 5 deletions
diff --git a/apps/files/src/services/Templates.js b/apps/files/src/services/Templates.js index 53d1408bbb1..8376d660ec4 100644 --- a/apps/files/src/services/Templates.js +++ b/apps/files/src/services/Templates.js @@ -27,3 +27,19 @@ export const getTemplates = async function() { const response = await axios.get(generateOcsUrl('apps/files/api/v1', 2) + 'templates') return response.data.ocs.data } + +/** + * Create a new file from a specified template + * + * @param {string} filePath The new file destination path + * @param {string} templatePath The template source path + * @param {string} templateType The template type e.g 'user' + */ +export const createFromTemplate = async function(filePath, templatePath, templateType) { + const response = await axios.post(generateOcsUrl('apps/files/api/v1/templates/create'), { + filePath, + templatePath, + templateType, + }) + return response.data.ocs.data +} diff --git a/apps/files/src/views/TemplatePicker.vue b/apps/files/src/views/TemplatePicker.vue index d12bc9885a2..23341816236 100644 --- a/apps/files/src/views/TemplatePicker.vue +++ b/apps/files/src/views/TemplatePicker.vue @@ -66,14 +66,13 @@ </template> <script> -import { generateOcsUrl } from '@nextcloud/router' +import { normalize } from 'path' import { showError } from '@nextcloud/dialogs' -import axios from '@nextcloud/axios' import EmptyContent from '@nextcloud/vue/dist/Components/EmptyContent' import Modal from '@nextcloud/vue/dist/Components/Modal' import { getCurrentDirectory } from '../utils/davUtils' -import { getTemplates } from '../services/Templates' +import { createFromTemplate, getTemplates } from '../services/Templates' import TemplatePreview from '../components/TemplatePreview' const border = 2 @@ -113,7 +112,9 @@ export default { * @returns {string} */ nameWithoutExt() { - return this.name.indexOf('.') > -1 ? this.name.split('.').slice(0, -1).join('.') : this.name + return this.name.indexOf('.') > -1 + ? this.name.split('.').slice(0, -1).join('.') + : this.name }, emptyTemplate() { @@ -205,7 +206,12 @@ export default { templateType: this.selectedTemplate?.templateType, }) - const fileInfo = response.data.ocs.data + try { + const fileInfo = await createFromTemplate( + normalize(`${currentDirectory}/${this.name}`), + this.selectedTemplate?.filename, + this.selectedTemplate?.templateType, + ) this.logger.debug('Created new file', fileInfo) await fileList?.addAndFetchFileInfo(this.name) |