Skip to content

Commit

Permalink
Update tinyURL to use new API
Browse files Browse the repository at this point in the history
  • Loading branch information
jrobinso committed May 9, 2024
1 parent f2cf856 commit c2e556d
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 33 deletions.
29 changes: 14 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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: "...",
Expand All @@ -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:
{
Expand All @@ -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
Expand Down
13 changes: 7 additions & 6 deletions igvwebConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,

Expand Down
8 changes: 3 additions & 5 deletions js/shareHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {
Expand Down
45 changes: 39 additions & 6 deletions js/urlShortener.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down

0 comments on commit c2e556d

Please sign in to comment.