Skip to content
Open
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nextcloud-webdav-client",
"version": "1.0.0",
"version": "1.1.0",
"description": "Wrapper for nextcloud webdav",
"main": "build/src/index.js",
"types": "build/src/index.d.ts",
Expand Down
51 changes: 35 additions & 16 deletions src/dav/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import axios, {
import { FileProps } from './fileProps'
import { Tag } from './tag'
import { MultiStatusResponse } from './multiStatusResponse'
import { Project } from './project'

export class Client {
constructor(readonly connection: AxiosInstance) {}
Expand Down Expand Up @@ -121,6 +122,40 @@ export class Client {
}
}

createTag = async (name: string): Promise<Tag> => {
const response = await this.connection({
method: 'POST',
url: '/systemtags',
data: {
userVisible: true,
userAssignable: true,
canAssign: true,
name,
},
})
const url = response.headers['content-location']
const id = this._parseIdFromLocation(url)
return new Tag(id, name)
}

createProject = async (
username: string,
name: string,
foreignId: string,
): Promise<Project> => {
const response = await this.connection({
method: 'POST',
url: `/projects/${username}`,
data: {
name,
'foreign-id': foreignId,
},
})
const data = response.data
const url = response.headers['content-location']
return new Project(data.id, data.name, foreignId, url)
}

private _props = async (
path: string,
names: string[],
Expand All @@ -145,22 +180,6 @@ export class Client {
return this._parseMultiStatus(rawResponse.data)
}

createTag = async (name: string): Promise<Tag> => {
const response = await this.connection({
method: 'POST',
url: '/systemtags',
data: {
userVisible: true,
userAssignable: true,
canAssign: true,
name,
},
})
const url = response.headers['content-location']
const id = this._parseIdFromLocation(url)
return new Tag(id, name)
}

private _parseIdFromLocation = (url: string): string => {
const queryPos = url.indexOf('?')
if (queryPos > 0) {
Expand Down
8 changes: 8 additions & 0 deletions src/dav/project.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export class Project {
constructor(
readonly id: string,
readonly name: string,
readonly foreignID: string,
readonly url: string,
) {}
}
31 changes: 31 additions & 0 deletions src/examples/create-project.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { Client, FileProps, Tag } from '../index'
import { AxiosRequestConfig } from 'axios'
import { Project } from 'src/dav/project'

const username = 'username'
const token =
'1gtlgCsANyXdTUFLgmWZINwKnqHPZYEZZQNr4ARUouONSjrFfdVGqWB1AEuuz9jtOcq3u7fD'

const projectname = 'project-1'
const baseURL = 'http://localhost/remote.php/dav/'

const config: AxiosRequestConfig = {
baseURL,
headers: { Authorization: `Bearer ${token}` },
}

const run = async () => {
try {
const dav: Client = Client.create(config)
const project: Project = await dav.createProject(
username,
projectname,
'foreign-id',
)
console.log(project.id)
} catch (error) {
console.log(error)
}
}

run().then()