Skip to content
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
19 changes: 19 additions & 0 deletions __tests__/dav/dav.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,25 @@ describe('davResultToNode', () => {
const node = davResultToNode(remoteResult)
expect(node.status).toBe(NodeStatus.FAILED)
})

test('Ignore invalid times', () => {
vi.spyOn(auth, 'getCurrentUser').mockReturnValue({ uid: 'user1', displayName: 'User 1', isAdmin: false })

// Invalid dates
const remoteResult = { ...result }
remoteResult.lastmod = 'invalid'
remoteResult.props!.creationdate = 'invalid'
const node = davResultToNode(remoteResult)
expect(node.mtime).toBeUndefined()
expect(node.crtime).toBeUndefined()

// Zero dates
remoteResult.lastmod = 'Thu, 01 Jan 1970 00:00:00 GMT'
remoteResult.props!.creationdate = 'Thu, 01 Jan 1970 00:00:00 GMT'
const node2 = davResultToNode(remoteResult)
expect(node2.mtime).toBeUndefined()
expect(node2.crtime).toBeUndefined()
})
})

describe('DAV requests', () => {
Expand Down
7 changes: 6 additions & 1 deletion lib/dav/dav.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { getSharingToken, isPublicShare } from '@nextcloud/sharing/public'
* Nextcloud DAV result response
*/
interface ResponseProps extends DAVResultResponseProps {
creationdate: string
permissions: string
mime: string
fileid: number
Expand Down Expand Up @@ -174,10 +175,14 @@ export const davResultToNode = function(node: FileStat, filesRoot = davRootPath,
const owner = String(props?.['owner-id'] || userId)
const id = props.fileid || 0

const mtime = new Date(Date.parse(node.lastmod))
const crtime = new Date(Date.parse(props.creationdate))

const nodeData: NodeData = {
id,
source: `${remoteURL}${node.filename}`,
mtime: new Date(Date.parse(node.lastmod)),
mtime: !isNaN(mtime.getTime()) && mtime.getTime() !== 0 ? mtime : undefined,
crtime: !isNaN(crtime.getTime()) && crtime.getTime() !== 0 ? crtime : undefined,
mime: node.mime || 'application/octet-stream',
// Manually cast to work around for https://github.com/perry-mitchell/webdav-client/pull/380
displayname: props.displayname !== undefined ? String(props.displayname) : undefined,
Expand Down
Loading