Skip to content

Commit bf0d730

Browse files
committed
feat(overview): add templates service using NC Files API
Signed-off-by: James Manuel <moodyjmz@users.noreply.github.com>
1 parent 221afaf commit bf0d730

1 file changed

Lines changed: 38 additions & 0 deletions

File tree

src/services/templates.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/**
2+
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
3+
* SPDX-License-Identifier: AGPL-3.0-or-later
4+
*/
5+
6+
// Mirrors apps/files/src/services/Templates.js — uses NC core Files API, not richdocuments OCS.
7+
8+
import axios from '@nextcloud/axios'
9+
import { generateOcsUrl } from '@nextcloud/router'
10+
11+
/**
12+
* Fetch all template creators registered with the NC Files API.
13+
* Returns an array of TemplateFileCreator objects, each with:
14+
* app, label, extension, mimetypes[], templates[]
15+
*
16+
* @return {Promise<object[]>}
17+
*/
18+
export async function getTemplates() {
19+
const response = await axios.get(generateOcsUrl('apps/files/api/v1/templates'))
20+
return response.data.ocs.data
21+
}
22+
23+
/**
24+
* Create a new file from a template via the NC Files API.
25+
*
26+
* @param {string} filePath Destination path for the new file
27+
* @param {string} templatePath Source template path
28+
* @param {string} templateType Template type e.g. 'user'
29+
* @return {Promise<object>}
30+
*/
31+
export async function createFromTemplate(filePath, templatePath, templateType) {
32+
const response = await axios.post(generateOcsUrl('apps/files/api/v1/templates/create'), {
33+
filePath,
34+
templatePath,
35+
templateType,
36+
})
37+
return response.data.ocs.data
38+
}

0 commit comments

Comments
 (0)