Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(node): allow negative file ids #716

Merged
merged 1 commit into from
Aug 3, 2023
Merged
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
18 changes: 11 additions & 7 deletions __tests__/files/node.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,17 @@ describe('FileId attribute', () => {
expect(file.fileid).toBe(1234)
})

// Mostly used when a node is unavailable
test('FileId negative fallback', () => {
const file = new File({
source: 'https://cloud.domain.com/remote.php/dav/picture.jpg',
mime: 'image/jpeg',
owner: 'emma',
id: -1234,
})
expect(file.fileid).toBe(-1234)
})

test('FileId attributes fallback', () => {
const file = new Folder({
source: 'https://cloud.domain.com/remote.php/dav/files/emma/Photos/',
Expand All @@ -73,13 +84,6 @@ describe('Sanity checks', () => {
owner: 'emma',
id: '1234' as unknown as number,
})).toThrowError('Invalid id type of value')

expect(() => new File({
source: 'https://cloud.domain.com/remote.php/dav/files/emma/Photos/picture.jpg',
mime: 'image/jpeg',
owner: 'emma',
id: -1234,
})).toThrowError('Invalid id type of value')
})

test('Invalid source', () => {
Expand Down
2 changes: 1 addition & 1 deletion lib/files/nodeData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import { join } from 'path'
import { Permission } from '../permissions'

export interface Attribute { [key: string]: any }

Check warning on line 26 in lib/files/nodeData.ts

View workflow job for this annotation

GitHub Actions / eslint

Unexpected any. Specify a different type

export interface NodeData {
/** Unique ID */
Expand Down Expand Up @@ -81,7 +81,7 @@
* @param davService Pattern to check if source is DAV ressource
*/
export const validateData = (data: NodeData, davService: RegExp) => {
if (data.id && (typeof data.id !== 'number' || data.id < 0)) {
if (data.id && typeof data.id !== 'number') {
throw new Error('Invalid id type of value')
}

Expand Down Expand Up @@ -151,7 +151,7 @@
}

if (data.root && isDavRessource(data.source, davService)) {
const service = data.source.match(davService)![0]

Check warning on line 154 in lib/files/nodeData.ts

View workflow job for this annotation

GitHub Actions / eslint

Forbidden non-null assertion
if (!data.source.includes(join(service, data.root))) {
throw new Error('The root must be relative to the service. e.g /files/emma')
}
Expand Down
Loading