2023-01-27 03:22:44 -08:00
|
|
|
import type {
|
2022-05-27 08:15:12 -07:00
|
|
|
ICredentialDataDecryptedObject,
|
|
|
|
ICredentialTestRequest,
|
2019-06-23 03:35:23 -07:00
|
|
|
ICredentialType,
|
2022-05-27 08:15:12 -07:00
|
|
|
IHttpRequestOptions,
|
2021-06-12 09:39:55 -07:00
|
|
|
INodeProperties,
|
2019-06-23 03:35:23 -07:00
|
|
|
} from 'n8n-workflow';
|
|
|
|
|
|
|
|
export class NextCloudApi implements ICredentialType {
|
|
|
|
name = 'nextCloudApi';
|
2022-12-02 12:54:28 -08:00
|
|
|
|
2019-06-23 03:35:23 -07:00
|
|
|
displayName = 'NextCloud API';
|
2022-12-02 12:54:28 -08:00
|
|
|
|
2020-08-17 05:42:09 -07:00
|
|
|
documentationUrl = 'nextCloud';
|
2022-12-02 12:54:28 -08:00
|
|
|
|
2021-06-12 09:39:55 -07:00
|
|
|
properties: INodeProperties[] = [
|
2019-06-23 03:35:23 -07:00
|
|
|
{
|
|
|
|
displayName: 'Web DAV URL',
|
|
|
|
name: 'webDavUrl',
|
2021-06-12 09:39:55 -07:00
|
|
|
type: 'string',
|
2020-07-22 14:52:40 -07:00
|
|
|
placeholder: 'https://nextcloud.example.com/remote.php/webdav',
|
2019-06-23 03:35:23 -07:00
|
|
|
default: '',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
displayName: 'User',
|
|
|
|
name: 'user',
|
2021-06-12 09:39:55 -07:00
|
|
|
type: 'string',
|
2019-06-23 03:35:23 -07:00
|
|
|
default: '',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
displayName: 'Password',
|
|
|
|
name: 'password',
|
2021-06-12 09:39:55 -07:00
|
|
|
type: 'string',
|
2022-11-01 09:41:45 -07:00
|
|
|
typeOptions: { password: true },
|
2019-06-23 03:35:23 -07:00
|
|
|
default: '',
|
|
|
|
},
|
|
|
|
];
|
2022-12-02 12:54:28 -08:00
|
|
|
|
2022-07-24 08:36:17 -07:00
|
|
|
async authenticate(
|
|
|
|
credentials: ICredentialDataDecryptedObject,
|
|
|
|
requestOptions: IHttpRequestOptions,
|
|
|
|
): Promise<IHttpRequestOptions> {
|
2022-05-27 08:15:12 -07:00
|
|
|
requestOptions.auth = {
|
|
|
|
username: credentials.user as string,
|
|
|
|
password: credentials.password as string,
|
|
|
|
};
|
|
|
|
return requestOptions;
|
|
|
|
}
|
2022-12-02 12:54:28 -08:00
|
|
|
|
2022-05-27 08:15:12 -07:00
|
|
|
test: ICredentialTestRequest = {
|
|
|
|
request: {
|
2022-07-24 08:36:17 -07:00
|
|
|
baseURL: "={{$credentials.webDavUrl.replace('/remote.php/webdav', '')}}",
|
2022-05-27 08:15:12 -07:00
|
|
|
url: '/ocs/v1.php/cloud/capabilities',
|
2022-07-24 08:36:17 -07:00
|
|
|
headers: { 'OCS-APIRequest': true },
|
2022-05-27 08:15:12 -07:00
|
|
|
},
|
|
|
|
};
|
2019-06-23 03:35:23 -07:00
|
|
|
}
|