From 863e33f3b91b80999ab303dfb60655e2d9e82fd7 Mon Sep 17 00:00:00 2001 From: Ealhad Date: Mon, 27 Aug 2018 20:13:29 +0200 Subject: [PATCH] Change default instance Now using https://peertube.social thanks to Nutomic --- README.org | 3 +++ src/background.ts | 4 +++- src/constants.ts | 3 +++ src/options.ts | 6 ++++-- src/youtube.ts | 4 +++- 5 files changed, 16 insertions(+), 4 deletions(-) create mode 100644 src/constants.ts diff --git a/README.org b/README.org index 8592d28..2a44bf9 100644 --- a/README.org +++ b/README.org @@ -15,3 +15,6 @@ Get it on [[https://addons.mozilla.org/en-US/firefox/addon/peertubeify][Firefox] * License PeerTubeify is released under the GNU GPL version 3. See COPYING. + +* Thanks +- @Nutomic for hosting [[https://peertube.video][peertube.video]], the default instance used by PeerTubeify diff --git a/src/background.ts b/src/background.ts index 81179fb..213bf0b 100644 --- a/src/background.ts +++ b/src/background.ts @@ -17,10 +17,12 @@ import * as _ from 'lodash/fp'; import * as browser from 'webextension-polyfill'; +import { constants } from './constants'; + const buildSearchURL = (instance: string, query: string): string => `https://${instance}/api/v1/search/videos?search=${encodeURIComponent(query)}`; const search = query => new Promise(async (resolve, reject) => { - const instance = _.getOr('framatube.org', 'searchInstance', await browser.storage.local.get()).toString(); + const instance = _.getOr(constants.defaultInstance, 'searchInstance', await browser.storage.local.get()).toString(); fetch(buildSearchURL(instance, query)) .then(res => res.json()) diff --git a/src/constants.ts b/src/constants.ts new file mode 100644 index 0000000..5eee3b4 --- /dev/null +++ b/src/constants.ts @@ -0,0 +1,3 @@ +export const constants = { + defaultInstance: 'peertube.social' +}; diff --git a/src/options.ts b/src/options.ts index 4941277..8ce741a 100644 --- a/src/options.ts +++ b/src/options.ts @@ -17,6 +17,8 @@ import * as _ from 'lodash/fp'; import * as browser from 'webextension-polyfill'; +import { constants } from './constants'; + function id(id: string): Element { return document.getElementById(id); } const searchInstanceInput = () => id('search-instance') as HTMLInputElement; @@ -25,7 +27,7 @@ const openInOriginalInstanceInput = () => id('open-in-original-instance') as HTM function saveOptions(e) { e.preventDefault(); browser.storage.local.set({ - searchInstance: _.defaultTo('framatube.org', stripProtocol(searchInstanceInput().value)), + searchInstance: _.defaultTo(constants.defaultInstance, stripProtocol(searchInstanceInput().value)), openInOriginalInstance: _.defaultTo(true, openInOriginalInstanceInput().checked), }); } @@ -34,7 +36,7 @@ const stripProtocol = _.replace(/^https?:\/\//, ''); function restoreOptions() { browser.storage.local.get().then(result => { - searchInstanceInput().value = _.defaultTo('framatube.org', result.searchInstance as string); + searchInstanceInput().value = _.defaultTo(constants.defaultInstance, result.searchInstance as string); openInOriginalInstanceInput().checked = _.defaultTo(true, result.openInOriginalInstance as boolean); }) } diff --git a/src/youtube.ts b/src/youtube.ts index 10646d2..44cb76b 100644 --- a/src/youtube.ts +++ b/src/youtube.ts @@ -17,6 +17,8 @@ import * as _ from 'lodash/fp'; import * as browser from 'webextension-polyfill'; +import { constants } from './constants'; + const watchURL = (host, uuid) => `https://${host}/videos/watch/${uuid}`; const thumbnailURL = (host, path) => `https://${host}${path}`; @@ -30,7 +32,7 @@ function peertubeify(query: string) { const options = await browser.storage.local.get(); const openInOriginalInstance = _.getOr(true, 'openInOriginalInstance', options); - const searchInstance = _.getOr('framatube.org', 'searchInstance', options); + const searchInstance = _.getOr(constants.defaultInstance, 'searchInstance', options); const url = watchURL(openInOriginalInstance ? video.account.host : searchInstance, video.uuid); const link = videoLink(url, video);