diff --git a/README.md b/README.md index fed1d8f..f98e721 100644 --- a/README.md +++ b/README.md @@ -99,7 +99,7 @@ instructions on obtaining a clientId. OAuth requests from igv.js will include t * https://www.googleapis.com/auth/devstorage.read_only - _if accessing protected Google Cloud Storage files_ * https://www.googleapis.com/auth/drive.readonly - _if accessing files stored on Google Drive_ -* **Enabling shortening of shared URLs.** The property `urlShortener` (_optional_) is an object or function defining a URL shortener to shorten links created by the **Share** button. The value of this property can be replaced with a function, taking a single argument (the long URL) and returning the shortened URL, or an Object. +* **Enabling shortening of shared URLs.** The property `urlShortener` (_optional_) is an object or function defining a URL shortener to shorten links created by the **Share** button. The [tinyURL](https://tinyurl.com/app/) service can be configured by entering an api token in the field of the default configuration. Other providers can be supported by setting the ```urlShortener``` property to an async function taking a single argument (the long URL) and returning the shortened URL. ### Where to find the configuration files @@ -115,6 +115,7 @@ var igvwebConfig = { genomes: "resources/genomes.json", trackRegistryFile: "resources/tracks/trackRegistry.json", + sessionRegistryFile: "resources/sessions/sessionRegistry.json", // Supply a drobpox api key to enable the Dropbox file picker in the load menus. This is optional //dropboxAPIKey: "...", @@ -124,10 +125,16 @@ var igvwebConfig = { // apiKey: "...", // Provide a URL shorterner function or object. This is optional. If not supplied - // sharable URLs will not be shortened . - urlShortener: { - provider: "tinyURL" - }, + // sharable URLs will not be shortened. If using tinyURL uncomment and supply an api token + + // urlShortener: { + /// provider: "tinyURL", + // api_token: "..." + //}, + + enableCircularView: true, + + restoreLastGenome: true, igvConfig: { @@ -137,19 +144,11 @@ var igvwebConfig = { queryParametersSupported: true, showChromosomeWidget: true, showSVGButton: false, - tracks: [ - // TODO -- add default tracks here. See github.com/igvteam/igv.js/wiki for details. - // For example: - // { - // name: "CTCF - string url", - // type: "wig", - // format: "bigwig", - // url: "https://www.encodeproject.org/files/ENCFF563PAW/@@download/ENCFF563PAW.bigWig" - // } - ] + tracks: [] } } + ``` ### Track Registry diff --git a/igvwebConfig.js b/igvwebConfig.js index c6b575f..53e102b 100644 --- a/igvwebConfig.js +++ b/igvwebConfig.js @@ -6,16 +6,17 @@ var igvwebConfig = { // Supply a drobpox api key to enable the Dropbox file picker in the load menus. This is optional //dropboxAPIKey: "...", - - // Supply a Google client id to enable the Google file picker in the load menus. This is optional + + // Supply a Google client id to enable the Google file picker in the load menus. This is optional //clientId: "...", // apiKey: "...", // Provide a URL shorterner function or object. This is optional. If not supplied - // sharable URLs will not be shortened . - urlShortener: { - provider: "tinyURL" - }, + // sharable URLs will not be shortened. If using tinyURL supply an api token + //urlShortener: { + // provider: "tinyURL", + // api_token: "..." + //}, enableCircularView: true, diff --git a/js/shareHelper.js b/js/shareHelper.js index 0be8e68..b5faa94 100644 --- a/js/shareHelper.js +++ b/js/shareHelper.js @@ -21,7 +21,7 @@ * */ import AlertSingleton from "./widgets/alertSingleton.js" -import {bitlyShortener, googleShortener, tinyURLShortener} from "./urlShortener.js"; +import {bitlyShortener, tinyURLShortener} from "./urlShortener.js"; import Globals from "./globals.js"; let urlShortener; @@ -33,13 +33,11 @@ export function setURLShortener(obj) { fn = obj; } else if (obj.provider) { - if ("tinyURL" === obj.provider) { + if ("tinyURL" === obj.provider && (obj.apiKey || obj.api_token)) { fn = tinyURLShortener(obj); } else if ("bitly" === obj.provider && obj.apiKey) { fn = bitlyShortener(obj.apiKey); - } else if ("google" === obj.provider && obj.apiKey) { - fn = googleShortener(obj.apiKey); - } else { + } else { AlertSingleton.present(new Error(`Unknown URL shortener provider: ${obj.provider}`)); } } else { diff --git a/js/urlShortener.js b/js/urlShortener.js index 822547d..55bf4dc 100644 --- a/js/urlShortener.js +++ b/js/urlShortener.js @@ -37,17 +37,50 @@ function googleShortener(apiKey) { } } -function tinyURLShortener({endpoint}) { - endpoint = endpoint || "https://2et6uxfezb.execute-api.us-east-1.amazonaws.com/dev/tinyurl/" +// function tinyURLShortener({endpoint}) { +// endpoint = endpoint || "https://2et6uxfezb.execute-api.us-east-1.amazonaws.com/dev/tinyurl/" +// return async function (url) { +// const enc = encodeURIComponent(url) +// const response = await fetch(`${endpoint}${enc}`) +// if (response.ok) { +// const shortened = await response.text() +// if (shortened.startsWith("<")) { +// return url +// } else { +// return shortened +// } +// } else { +// throw new Error(response.statusText) +// } +// } +// } + +function tinyURLShortener({endpoint, apiKey, api_token}) { + endpoint = endpoint || "https://api.tinyurl.com/create" + const token = apiKey || api_token return async function (url) { - const enc = encodeURIComponent(url) - const response = await fetch(`${endpoint}${enc}`) + const response = await fetch(`${endpoint}?api_token=${token}`, { + method: 'post', + mode: "cors", // no-cors, *cors, same-origin + cache: "no-cache", // *default, no-cache, reload, force-cache, only-if-cached + headers: { + "accept": "application/json", + "Content-Type": "application/json", + // 'Content-Type': 'application/x-www-form-urlencoded', + }, + body: JSON.stringify({url: url}), // body data type must match "Content-Type" header + }) if (response.ok) { - return response.text() + const json = await response.json() + if (json.errors.length > 0) { + throw Error(json.errors[0]) + } else { + return json.data["tiny_url"] + } } else { throw new Error(response.statusText) } } } -export {bitlyShortener, googleShortener, tinyURLShortener} +export {bitlyShortener, tinyURLShortener} diff --git a/package.json b/package.json index ad39bfe..fe3af8b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "igv-webapp", - "version": "1.14.0", + "version": "2.0.0", "description": "igv web app", "keywords": [], "author": "Douglass Turner and Jim Robinson",