From f1755b9af19356fdc8b9267623b9af1abdf8c4b9 Mon Sep 17 00:00:00 2001 From: Ferdinand Thiessen Date: Thu, 14 Nov 2024 23:10:50 +0100 Subject: [PATCH] fix: Typo in method name `isDavResource` instead of `isDavRessource` Depreacte the old variant and make it an alias of the correct name, so we can remove it in the next major version. Signed-off-by: Ferdinand Thiessen --- __tests__/dav/dav.spec.ts | 6 +++--- __tests__/dav/public-shares.spec.ts | 2 +- __tests__/files/file.spec.ts | 6 +++--- __tests__/files/folder.spec.ts | 6 +++--- __tests__/files/node.spec.ts | 14 +++++++------- lib/files/node.ts | 29 ++++++++++++++++++----------- lib/files/nodeData.ts | 8 ++++---- 7 files changed, 39 insertions(+), 32 deletions(-) diff --git a/__tests__/dav/dav.spec.ts b/__tests__/dav/dav.spec.ts index ffd6dd04..321afe1b 100644 --- a/__tests__/dav/dav.spec.ts +++ b/__tests__/dav/dav.spec.ts @@ -108,7 +108,7 @@ describe('resultToNode', () => { remoteResult.props = { ...remoteResult.props, ...{ 'owner-id': 'user1' } } as FileStat['props'] const node = resultToNode(remoteResult, '/root', 'http://example.com/remote.php/dav') - expect(node.isDavRessource).toBe(true) + expect(node.isDavResource).toBe(true) expect(node.owner).toBe('user1') }) @@ -119,7 +119,7 @@ describe('resultToNode', () => { remoteResult.props = { ...remoteResult.props, ...{ 'owner-id': 123456789 } } as FileStat['props'] const node = resultToNode(remoteResult, '/root', 'http://example.com/remote.php/dav') - expect(node.isDavRessource).toBe(true) + expect(node.isDavResource).toBe(true) expect(node.owner).toBe('123456789') }) @@ -129,7 +129,7 @@ describe('resultToNode', () => { const remoteResult = { ...result, filename: '/root/New folder/Neue Textdatei.md' } const node = resultToNode(remoteResult, '/root', 'http://example.com/remote.php/dav') - expect(node.isDavRessource).toBe(true) + expect(node.isDavResource).toBe(true) expect(node.owner).toBe('user1') }) diff --git a/__tests__/dav/public-shares.spec.ts b/__tests__/dav/public-shares.spec.ts index 6625de1e..959f1afd 100644 --- a/__tests__/dav/public-shares.spec.ts +++ b/__tests__/dav/public-shares.spec.ts @@ -95,7 +95,7 @@ describe('on public shares', () => { const remoteResult = { ...result, filename: '/root/New folder/Neue Textdatei.md' } const node = await resultToNode(remoteResult, '/root', 'http://example.com/remote.php/dav') - expect(node.isDavRessource).toBe(true) + expect(node.isDavResource).toBe(true) expect(node.owner).toBe('anonymous') }) }) diff --git a/__tests__/files/file.spec.ts b/__tests__/files/file.spec.ts index 8afb5569..3e355e5f 100644 --- a/__tests__/files/file.spec.ts +++ b/__tests__/files/file.spec.ts @@ -39,7 +39,7 @@ describe('File creation', () => { expect(file.dirname).toBe('/') expect(file.root).toBe('/files/emma/Photos') expect(file.path).toBe('/picture.jpg') - expect(file.isDavRessource).toBe(true) + expect(file.isDavResource).toBe(true) expect(file.permissions).toBe(Permission.NONE) expect(file.status).toBe(NodeStatus.NEW) }) @@ -67,7 +67,7 @@ describe('File creation', () => { expect(file.dirname).toBe('/Photos') expect(file.root).toBe('/files/emma') expect(file.path).toBe('/Photos/picture.jpg') - expect(file.isDavRessource).toBe(true) + expect(file.isDavResource).toBe(true) expect(file.permissions).toBe(Permission.NONE) }) @@ -92,7 +92,7 @@ describe('File creation', () => { expect(file.extension).toBe('.jpg') expect(file.dirname).toBe('/Photos') expect(file.root).toBeNull() - expect(file.isDavRessource).toBe(false) + expect(file.isDavResource).toBe(false) expect(file.permissions).toBe(Permission.READ) }) }) diff --git a/__tests__/files/folder.spec.ts b/__tests__/files/folder.spec.ts index 7393ef5a..4832fc84 100644 --- a/__tests__/files/folder.spec.ts +++ b/__tests__/files/folder.spec.ts @@ -29,7 +29,7 @@ describe('Folder creation', () => { expect(folder.extension).toBeNull() expect(folder.dirname).toBe('/') expect(folder.root).toBe('/files/emma') - expect(folder.isDavRessource).toBe(true) + expect(folder.isDavResource).toBe(true) expect(folder.permissions).toBe(Permission.NONE) }) @@ -54,7 +54,7 @@ describe('Folder creation', () => { expect(folder.extension).toBeNull() expect(folder.dirname).toBe('/Photos') expect(folder.root).toBe('/files/emma') - expect(folder.isDavRessource).toBe(true) + expect(folder.isDavResource).toBe(true) expect(folder.permissions).toBe(Permission.NONE) }) @@ -78,7 +78,7 @@ describe('Folder creation', () => { expect(folder.extension).toBeNull() expect(folder.dirname).toBe('/') expect(folder.root).toBeNull() - expect(folder.isDavRessource).toBe(false) + expect(folder.isDavResource).toBe(false) expect(folder.permissions).toBe(Permission.READ) }) }) diff --git a/__tests__/files/node.spec.ts b/__tests__/files/node.spec.ts index 5bd61dce..36a79a02 100644 --- a/__tests__/files/node.spec.ts +++ b/__tests__/files/node.spec.ts @@ -405,28 +405,28 @@ describe('Dav service detection', () => { mime: 'image/jpeg', owner: 'emma', }) - expect(file1.isDavRessource).toBe(true) + expect(file1.isDavResource).toBe(true) const file2 = new File({ source: 'https://cloud.domain.com/remote.php/webdav/files/emma/Photos/picture.jpg', mime: 'image/jpeg', owner: 'emma', }) - expect(file2.isDavRessource).toBe(true) + expect(file2.isDavResource).toBe(true) const file3 = new File({ source: 'https://cloud.domain.com/public.php/dav/files/emma/Photos/picture.jpg', mime: 'image/jpeg', owner: 'emma', }) - expect(file3.isDavRessource).toBe(true) + expect(file3.isDavResource).toBe(true) const file4 = new File({ source: 'https://cloud.domain.com/public.php/webdav/files/emma/Photos/picture.jpg', mime: 'image/jpeg', owner: 'emma', }) - expect(file4.isDavRessource).toBe(true) + expect(file4.isDavResource).toBe(true) }) test('Custom dav service', () => { @@ -435,14 +435,14 @@ describe('Dav service detection', () => { mime: 'image/jpeg', owner: 'emma', }, /test\.php\/dav/) - expect(file1.isDavRessource).toBe(true) + expect(file1.isDavResource).toBe(true) const file2 = new File({ source: 'https://cloud.domain.com/remote.php/dav/files/emma/Photos/picture.jpg', mime: 'image/jpeg', owner: 'emma', }, /test\.php\/dav/) - expect(file2.isDavRessource).toBe(false) + expect(file2.isDavResource).toBe(false) }) }) @@ -551,7 +551,7 @@ describe('Root and paths detection', () => { mime: 'image/jpeg', owner: 'emma', }) - expect(file.isDavRessource).toBe(false) + expect(file.isDavResource).toBe(false) expect(file.root).toBe(null) expect(file.dirname).toBe('/files/images') expect(file.path).toBe('/files/images/emma.jpeg') diff --git a/lib/files/node.ts b/lib/files/node.ts index 6978c111..15392302 100644 --- a/lib/files/node.ts +++ b/lib/files/node.ts @@ -7,7 +7,7 @@ import { encodePath } from '@nextcloud/paths' import { Permission } from '../permissions' import { FileType } from './fileType' -import { Attribute, NodeData, isDavRessource, validateData } from './nodeData' +import { Attribute, isDavResource, NodeData, validateData } from './nodeData' import logger from '../utils/logger' export enum NodeStatus { @@ -143,7 +143,7 @@ export abstract class Node { get dirname(): string { if (this.root) { let source = this.source - if (this.isDavRessource) { + if (this.isDavResource) { // ensure we only work on the real path in case root is not distinct source = source.split(this._knownDavService).pop()! } @@ -222,8 +222,8 @@ export abstract class Node { * Get the file permissions */ get permissions(): Permission { - // If this is not a dav ressource, we can only read it - if (this.owner === null && !this.isDavRessource) { + // If this is not a dav resource, we can only read it + if (this.owner === null && !this.isDavResource) { return Permission.READ } @@ -246,18 +246,25 @@ export abstract class Node { * There is no setter as the owner is not meant to be changed */ get owner(): string|null { - // Remote ressources have no owner - if (!this.isDavRessource) { + // Remote resources have no owner + if (!this.isDavResource) { return null } return this._data.owner } /** - * Is this a dav-related ressource ? + * Is this a dav-related resource ? + */ + get isDavResource(): boolean { + return isDavResource(this.source, this._knownDavService) + } + + /** + * @deprecated use `isDavResource` instead - will be removed in next major version. */ get isDavRessource(): boolean { - return isDavRessource(this.source, this._knownDavService) + return this.isDavResource } /** @@ -271,7 +278,7 @@ export abstract class Node { } // Use the source to get the root from the dav service - if (this.isDavRessource) { + if (this.isDavResource) { const root = dirname(this.source) return root.split(this._knownDavService).pop() || null } @@ -285,7 +292,7 @@ export abstract class Node { get path(): string { if (this.root) { let source = this.source - if (this.isDavRessource) { + if (this.isDavResource) { // ensure we only work on the real path in case root is not distinct source = source.split(this._knownDavService).pop()! } @@ -339,7 +346,7 @@ export abstract class Node { this._data.source = destination // Check if the displayname and the (old) basename were the same - // meaning no special displayname was set but just a fallback to the basename by Nextclouds WebDAV server + // meaning no special displayname was set but just a fallback to the basename by Nextcloud's WebDAV server if (this.displayname === oldBasename && this.basename !== oldBasename) { // We have to assume that the displayname was not set but just a copy of the basename diff --git a/lib/files/nodeData.ts b/lib/files/nodeData.ts index 9099784c..c387ba20 100644 --- a/lib/files/nodeData.ts +++ b/lib/files/nodeData.ts @@ -15,7 +15,7 @@ export interface NodeData { id?: number /** - * URL to the ressource. + * URL to the resource. * e.g. https://cloud.domain.com/remote.php/dav/files/emma/Photos/picture.jpg * or https://domain.com/Photos/picture.jpg */ @@ -60,9 +60,9 @@ export interface NodeData { * Check if a node source is from a specific DAV service * * @param source The source to check - * @param davService Pattern to check if source is DAV ressource + * @param davService Pattern to check if source is DAV resource */ -export const isDavRessource = function(source: string, davService: RegExp): boolean { +export const isDavResource = function(source: string, davService: RegExp): boolean { return source.match(davService) !== null } @@ -146,7 +146,7 @@ export const validateData = (data: NodeData, davService: RegExp) => { throw new Error('Root must be part of the source') } - if (data.root && isDavRessource(data.source, davService)) { + if (data.root && isDavResource(data.source, davService)) { const service = data.source.match(davService)![0] if (!data.source.includes(join(service, data.root))) { throw new Error('The root must be relative to the service. e.g /files/emma')