Commit ac984496 authored by Alejandro Celaya's avatar Alejandro Celaya Committed by Alejandro Celaya

Migrate annotation-sharing to TypeScript

parent 6baca3e7
/** import type { Annotation } from '../../types/api';
* @typedef {import('../../types/api').Annotation} Annotation import type { SidebarSettings } from '../../types/config';
* @typedef {import('../../types/config').SidebarSettings} SidebarSettings
*/
import { serviceConfig } from '../config/service-config'; import { serviceConfig } from '../config/service-config';
/** /**
...@@ -16,11 +14,8 @@ import { serviceConfig } from '../config/service-config'; ...@@ -16,11 +14,8 @@ import { serviceConfig } from '../config/service-config';
* *
* Note that `html` links are not provided by the service for third-party * Note that `html` links are not provided by the service for third-party
* annotations. * annotations.
*
* @param {Annotation} annotation
* @return {string|null}
*/ */
export function annotationSharingLink(annotation) { export function annotationSharingLink(annotation: Annotation): string | null {
if (isShareableURI(annotation.uri)) { if (isShareableURI(annotation.uri)) {
return annotation.links?.incontext ?? annotation.links?.html ?? null; return annotation.links?.incontext ?? annotation.links?.html ?? null;
} else { } else {
...@@ -32,12 +27,11 @@ export function annotationSharingLink(annotation) { ...@@ -32,12 +27,11 @@ export function annotationSharingLink(annotation) {
* Generate a URI for sharing: a bouncer link built to share annotations in * Generate a URI for sharing: a bouncer link built to share annotations in
* a specific group (groupID) on a specific document (documentURI). If the * a specific group (groupID) on a specific document (documentURI). If the
* `documentURI` provided is not a web-accessible URL, no link is generated. * `documentURI` provided is not a web-accessible URL, no link is generated.
*
* @param {string} documentURI
* @param {string} groupID
* @return {string|null}
*/ */
export function pageSharingLink(documentURI, groupID) { export function pageSharingLink(
documentURI: string,
groupID: string
): string | null {
if (!isShareableURI(documentURI)) { if (!isShareableURI(documentURI)) {
return null; return null;
} }
...@@ -50,26 +44,16 @@ export function pageSharingLink(documentURI, groupID) { ...@@ -50,26 +44,16 @@ export function pageSharingLink(documentURI, groupID) {
* Are annotations made against `uri` meaningfully shareable? The * Are annotations made against `uri` meaningfully shareable? The
* target URI needs to be available on the web, which here is determined by * target URI needs to be available on the web, which here is determined by
* a protocol of `http` or `https`. * a protocol of `http` or `https`.
*
* @param {string} uri
* @return {boolean}
*/ */
export function isShareableURI(uri) { export function isShareableURI(uri: string): boolean {
return /^http(s?):/i.test(uri); return /^http(s?):/i.test(uri);
} }
/** /**
* Is the sharing of annotations enabled? Check for any defined `serviceConfig`, * Is the sharing of annotations enabled? Check for any defined `serviceConfig`,
* but default to `true` if none found. * but default to `true` if none found.
*
* @param {SidebarSettings} settings
* @return {boolean}
*/ */
export function sharingEnabled(settings) { export function sharingEnabled(settings: SidebarSettings): boolean {
const service = serviceConfig(settings); const service = serviceConfig(settings);
return service?.enableShareLinks !== false;
if (service?.enableShareLinks === false) {
return false;
}
return true;
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment