/// import { RequestInit, Response } from "node-fetch"; import NCError from "./ncError"; import NCFile from "./ncFile"; import NCFolder from "./ncFolder"; import { IProxy, IRequestContext } from "./ncHttpClient"; import NCTag from "./ncTag"; import RequestResponseLogEntry from "./requestResponseLogEntry"; export { NCClient, NCError, NCFolder, NCFile, NCTag, }; export interface IBasicAuth { "username": string; "password": string; } export declare class FakeServer { fakeResponses: RequestResponseLogEntry[]; constructor(fakeResponses: RequestResponseLogEntry[]); getFakeHttpResponse(url: string, requestInit: RequestInit, expectedHttpStatusCode: number[], context: IRequestContext): Promise; } export declare class NextcloudServer { url: string; basicAuth: IBasicAuth; proxy?: IProxy; logRequestResponse: boolean; constructor(url: string, basicAuth: IBasicAuth, proxy?: IProxy, logRequestResponse?: boolean); } export default class NCClient { static webDavUrlPath: string; /** * returns the nextcloud credentials that is defined in the * "user-provided" service section of the VCAP_SERVICES environment * @param instanceName the name of the nextcloud user provided service instance * @returns credentials from the VCAP_SERVICES environment (user provided service) */ static getCredentialsFromEnv(): NextcloudServer; /** * returns the nextcloud credentials that is defined in the * "user-provided" service section of the VCAP_SERVICES environment * @param instanceName the name of the nextcloud user provided service instance * @returns credentials from the VCAP_SERVICES environment (user provided service) */ static getCredentialsFromVcapServicesEnv(instanceName: string): NextcloudServer; private nextcloudOrigin; private nextcloudAuthHeader; private nextcloudRequestToken; private webDAVUrl; private proxy?; private fakeServer?; private logRequestResponse; private httpClient?; constructor(server: NextcloudServer | FakeServer); /** * returns the used and free quota of the nextcloud account */ getQuota(): Promise<{ used: number; available: string | number; }>; /** * creates a new tag, if not already existing * this function will fail with http 403 if the user does not have admin privileges * @param tagName the name of the tag * @returns tagId */ createTag(tagName: string): Promise; /** * returns a tag identified by the name or null if not found * @param tagName the name of the tag * @returns tag or null */ getTagByName(tagName: string): Promise; /** * returns a tag identified by the id or null if not found * @param tagId the id of the tag * @returns tag or null */ getTagById(tagId: number): Promise; /** * deletes the tag by id * this function will fail with http 403 if the user does not have admin privileges * @param tagId the id of the tag like "/remote.php/dav/systemtags/234" */ deleteTag(tagId: number): Promise; /** * deletes all visible assignable tags * @throws Error */ deleteAllTags(): Promise; /** * returns a list of tags * @returns array of tags */ getTags(): Promise; /** * returns the list of tag names and the tag ids * @param fileId the id of the file */ getTagsOfFile(fileId: number): Promise>; /** * removes the tag from the file * @param fileId the file id * @param tagId the tag id */ removeTagOfFile(fileId: number, tagId: number): Promise; /** * returns the id of the file or -1 of not found * @returns id of the file or -1 if not found */ getFileId(fileUrl: string): Promise; getFolderContents(folderName: string): Promise; /** * creates a folder and all parent folders in the path if they do not exist * @param folderName name of the folder /folder/subfolder/subfolder * @returns a folder object */ createFolder(folderName: string): Promise; /** * deletes a file * @param fileName name of folder "/f1/f2/f3/x.txt" */ deleteFile(fileName: string): Promise; /** * deletes a folder * @param folderName name of folder "/f1/f2/f3" */ deleteFolder(folderName: string): Promise; /** * get a folder object from a path string * @param folderName Name of the folder like "/company/branches/germany" * @returns null if the folder does not exist or an folder object */ getFolder(folderName: string): Promise; /** * get a array of folders from a folder path string * @param folderName Name of the folder like "/company/branches/germany" * @returns array of folder objects */ getSubFolders(folderName: string): Promise; /** * get files of a folder * @param folderName Name of the folder like "/company/branches/germany" * @returns array of file objects */ getFiles(folderName: string): Promise; /** * create a new file of overwrites an existing file * @param fileName the file name /folder1/folder2/filename.txt * @param data the buffer object */ createFile(fileName: string, data: Buffer): Promise; /** * returns a nextcloud file object * @param fileName the full file name /folder1/folder2/file.pdf */ getFile(fileName: string): Promise; /** * renames the file or moves it to an other location * @param sourceFileName source file name * @param targetFileName target file name */ moveFile(sourceFileName: string, targetFileName: string): Promise; /** * renames the folder or moves it to an other location * @param sourceFolderName source folder name * @param tarName target folder name */ moveFolder(sourceFolderName: string, tarName: string): Promise; /** * returns the content of a file * @param fileName name of the file /d1/file1.txt * @returns Buffer with file content */ getContent(fileName: string): Promise; /** * returns the link to a file for downloading * @param fileName name of the file /folder1/folder1.txt * @returns url */ getLink(fileName: string): string; getUILink(fileId: number): string; /** * adds a tag to a file or folder * if the tag does not exist, it is automatically created * if the tag is created, the user must have damin privileges * @param fileId the id of the file * @param tagName the name of the tag * @returns nothing * @throws Error */ addTagToFile(fileId: number, tagName: string): Promise; getActivities(): Promise; addCommentToFile(fileId: number, comment: string): Promise; /** * returns comments of a file / folder * @param fileId the id of the file / folder * @param top number of comments to return * @param skip the offset * @returns array of comment strings * @throws Exception */ getFileComments(fileId: number, top?: number, skip?: number): Promise; /** * asserts valid xml * asserts multistatus response * asserts that a href is available in the multistatus response * asserts propstats and prop * @param response the http response * @param href get only properties that match the href * @returns array of properties * @throws NCError */ private getPropertiesFromWebDAVMultistatusResponse; /** * nextcloud creates a csrf token and stores it in the html header attribute * data-requesttoken * this function is currently not used * @returns the csrf token / requesttoken */ private getCSRFToken; private getHttpResponse; /** * get contents array of a folder * @param folderName Name of the folder like "/company/branches/germany" * @param folderIndicator true if folders are requested otherwise files * @returns array of folder contents meta data */ private Contents; private sanitizeFolderName; private getTagIdFromHref; private createFolderInternal; private stat; private putFileContents; }