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
41 changes: 41 additions & 0 deletions docs/api/cozy-client/interfaces/models.note.FetchURLOptions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
[cozy-client](../README.md) / [models](../modules/models.md) / [note](../modules/models.note.md) / FetchURLOptions

# Interface: FetchURLOptions<>

[models](../modules/models.md).[note](../modules/models.note.md).FetchURLOptions

## Properties

### driveId

• **driveId**: `string`

Shared drive ID used to fetch the URL

*Defined in*

[packages/cozy-client/src/models/note.js:7](https://github.com/linagora/cozy-client/blob/master/packages/cozy-client/src/models/note.js#L7)

***

### pathname

• **pathname**: `string`

Pathname to use in the URL

*Defined in*

[packages/cozy-client/src/models/note.js:6](https://github.com/linagora/cozy-client/blob/master/packages/cozy-client/src/models/note.js#L6)

***

### returnUrl

• **returnUrl**: `string`

Return URL to add in query string

*Defined in*

[packages/cozy-client/src/models/note.js:8](https://github.com/linagora/cozy-client/blob/master/packages/cozy-client/src/models/note.js#L8)
16 changes: 9 additions & 7 deletions docs/api/cozy-client/modules/models.note.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@

[models](models.md).note

## Interfaces

* [FetchURLOptions](../interfaces/models.note.FetchURLOptions.md)

## Functions

### fetchURL

▸ **fetchURL**(`client`, `file`, `options?`): `Promise`<`string`>
▸ **fetchURL**(`client`, `file`, `[options]?`): `Promise`<`string`>

Fetch and build an URL to open a note.

Expand All @@ -18,9 +22,7 @@ Fetch and build an URL to open a note.
| :------ | :------ | :------ |
| `client` | `any` | CozyClient instance |
| `file` | `any` | io.cozy.file object |
| `options` | `Object` | Options |
| `options.driveId` | `string` | - |
| `options.pathname` | `string` | - |
| `[options]` | [`FetchURLOptions`](../interfaces/models.note.FetchURLOptions.md) | Options |

*Returns*

Expand All @@ -30,7 +32,7 @@ url

*Defined in*

[packages/cozy-client/src/models/note.js:34](https://github.com/linagora/cozy-client/blob/master/packages/cozy-client/src/models/note.js#L34)
[packages/cozy-client/src/models/note.js:39](https://github.com/linagora/cozy-client/blob/master/packages/cozy-client/src/models/note.js#L39)

***

Expand All @@ -52,7 +54,7 @@ url

*Defined in*

[packages/cozy-client/src/models/note.js:9](https://github.com/linagora/cozy-client/blob/master/packages/cozy-client/src/models/note.js#L9)
[packages/cozy-client/src/models/note.js:16](https://github.com/linagora/cozy-client/blob/master/packages/cozy-client/src/models/note.js#L16)

***

Expand All @@ -73,4 +75,4 @@ url

*Defined in*

[packages/cozy-client/src/models/note.js:18](https://github.com/linagora/cozy-client/blob/master/packages/cozy-client/src/models/note.js#L18)
[packages/cozy-client/src/models/note.js:25](https://github.com/linagora/cozy-client/blob/master/packages/cozy-client/src/models/note.js#L25)
33 changes: 25 additions & 8 deletions packages/cozy-client/src/models/note.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import { generateWebLink } from '../helpers'
import logger from '../logger'

/**
* @typedef {Object} FetchURLOptions
* @property {string} [pathname] - Pathname to use in the URL
* @property {string} [driveId] - Shared drive ID used to fetch the URL
* @property {string} [returnUrl] - Return URL to add in query string
*/

/**
*
* @param {string} notesAppUrl URL to the Notes App (https://notes.foo.mycozy.cloud)
Expand All @@ -26,33 +33,43 @@ export const generateUrlForNote = (notesAppUrl, file) => {
*
* @param {object} client CozyClient instance
* @param {object} file io.cozy.file object
* @param {object} options Options
* @param {string} [options.pathname] Pathname to use in the URL
* @param {string} [options.driveId] Shared drive ID used to fetched the URL
* @param {FetchURLOptions} [options] Options
* @returns {Promise<string>} url
*/
export const fetchURL = async (client, file, options = {}) => {
export const fetchURL = async (
client,
file,
{ pathname, driveId, returnUrl } = {}
) => {
const {
data: { note_id, subdomain, protocol, instance, sharecode, public_name }
} = await client
.getStackClient()
.collection('io.cozy.notes', { driveId: options.driveId })
.collection('io.cozy.notes', { driveId })
.fetchURL({ _id: file.id })
if (sharecode) {
const searchParams = [['id', note_id]]
searchParams.push(['sharecode', sharecode])
if (public_name) searchParams.push(['username', public_name])

if (public_name) {
searchParams.push(['username', public_name])
}

if (returnUrl) {
searchParams.push(['returnUrl', returnUrl])
}

return generateWebLink({
cozyUrl: `${protocol}://${instance}`,
searchParams,
pathname: options.pathname ?? '/public/',
pathname: pathname ?? '/public/',
slug: 'notes',
subDomainType: subdomain
})
} else {
return generateWebLink({
cozyUrl: `${protocol}://${instance}`,
pathname: options.pathname ?? '',
pathname: pathname ?? '',
slug: 'notes',
subDomainType: subdomain,
hash: `/n/${note_id}`
Expand Down
19 changes: 15 additions & 4 deletions packages/cozy-client/types/models/note.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
export function generatePrivateUrl(notesAppUrl: string, file: object, options?: {}): string;
export function generateUrlForNote(notesAppUrl: any, file: any): string;
export function fetchURL(client: object, file: object, options?: {
pathname: string;
driveId: string;
}): Promise<string>;
export function fetchURL(client: object, file: object, { pathname, driveId, returnUrl }?: FetchURLOptions): Promise<string>;
export type FetchURLOptions = {
/**
* - Pathname to use in the URL
*/
pathname?: string;
/**
* - Shared drive ID used to fetch the URL
*/
driveId?: string;
/**
* - Return URL to add in query string
*/
returnUrl?: string;
};
Loading