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
91 changes: 0 additions & 91 deletions .github/workflows/lint-prettier.yml

This file was deleted.

11 changes: 0 additions & 11 deletions .prettierignore

This file was deleted.

8 changes: 8 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*!
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: CC0-1.0
*/

import { recommendedLibrary } from '@nextcloud/eslint-config'

export default [...recommendedLibrary]
2 changes: 1 addition & 1 deletion lib/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ test('ShareType', () => {
for (const type of Object.values(ShareType)) {
if (typeof type === 'string') {
// This should be the key of the enum, so we should be able to get the value
// eslint-disable-next-line @typescript-eslint/no-explicit-any

expect((ShareType as any)[type]).toBeTypeOf('number')
} else {
expect(type).toBeTypeOf('number')
Expand Down
1 change: 1 addition & 0 deletions lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export enum ShareType {
FederatedGroup = 14,
/**
* Third party share types
*
* @since 25.0.0
*/
ScienceMesh = 15,
Expand Down
56 changes: 28 additions & 28 deletions lib/publicShare.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,34 +9,6 @@ import { beforeEach, describe, expect, test, vi } from 'vitest'
const initialState = vi.hoisted(() => ({ loadState: vi.fn() }))
vi.mock('@nextcloud/initial-state', () => initialState)

const mockPublicShare = () => {
initialState.loadState.mockImplementation((app, key) => {
if (key === 'isPublic') {
return true
} else if (key === 'sharingToken') {
return 'modern-token'
}
throw new Error('Unexpected loadState')
})
}

const mockLegacyPublicShare = () => {
initialState.loadState.mockImplementationOnce(() => null)

const input = document.createElement('input')
input.id = 'isPublic'
input.name = 'isPublic'
input.type = 'hidden'
input.value = '1'
document.body.appendChild(input)

const token = document.createElement('input')
token.id = 'sharingToken'
token.type = 'hidden'
token.value = 'legacy-token'
document.body.appendChild(token)
}

describe('isPublicShare', () => {
beforeEach(() => {
vi.resetModules()
Expand Down Expand Up @@ -120,3 +92,31 @@ describe('getSharingToken', () => {
expect(await getSharingToken()).toBe('legacy-token')
})
})

function mockPublicShare() {
initialState.loadState.mockImplementation((app, key) => {
if (key === 'isPublic') {
return true
} else if (key === 'sharingToken') {
return 'modern-token'
}
throw new Error('Unexpected loadState')
})
}

function mockLegacyPublicShare() {
initialState.loadState.mockImplementationOnce(() => null)

const input = document.createElement('input')
input.id = 'isPublic'
input.name = 'isPublic'
input.type = 'hidden'
input.value = '1'
document.body.appendChild(input)

const token = document.createElement('input')
token.id = 'sharingToken'
token.type = 'hidden'
token.value = 'legacy-token'
document.body.appendChild(token)
}
15 changes: 7 additions & 8 deletions lib/publicShare.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
/**
/*!
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: GPL-3.0-or-later
*
*/

/**
* @module public
*/

import { loadState } from '@nextcloud/initial-state'

/**
Expand All @@ -13,9 +16,7 @@ export function isPublicShare(): boolean {
// check both the new initial state version and fallback to legacy input
return (
loadState<boolean | null>('files_sharing', 'isPublic', null)
?? document.querySelector(
'input#isPublic[type="hidden"][name="isPublic"][value="1"]',
) !== null
?? document.querySelector('input#isPublic[type="hidden"][name="isPublic"][value="1"]') !== null
)
}

Expand All @@ -25,9 +26,7 @@ export function isPublicShare(): boolean {
export function getSharingToken(): string | null {
return (
loadState<string | null>('files_sharing', 'sharingToken', null)
?? document.querySelector<HTMLInputElement>(
'input#sharingToken[type="hidden"]',
)?.value
?? document.querySelector<HTMLInputElement>('input#sharingToken[type="hidden"]')?.value
?? null
)
}
Loading