Change default instance

Now using https://peertube.social thanks to Nutomic
This commit is contained in:
Ealhad 2018-08-27 20:13:29 +02:00
parent 62656b2658
commit 863e33f3b9
5 changed files with 16 additions and 4 deletions

View File

@ -15,3 +15,6 @@ Get it on [[https://addons.mozilla.org/en-US/firefox/addon/peertubeify][Firefox]
* License * License
PeerTubeify is released under the GNU GPL version 3. See COPYING. 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

View File

@ -17,10 +17,12 @@
import * as _ from 'lodash/fp'; import * as _ from 'lodash/fp';
import * as browser from 'webextension-polyfill'; 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 buildSearchURL = (instance: string, query: string): string => `https://${instance}/api/v1/search/videos?search=${encodeURIComponent(query)}`;
const search = query => new Promise(async (resolve, reject) => { 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)) fetch(buildSearchURL(instance, query))
.then(res => res.json()) .then(res => res.json())

3
src/constants.ts Normal file
View File

@ -0,0 +1,3 @@
export const constants = {
defaultInstance: 'peertube.social'
};

View File

@ -17,6 +17,8 @@
import * as _ from 'lodash/fp'; import * as _ from 'lodash/fp';
import * as browser from 'webextension-polyfill'; import * as browser from 'webextension-polyfill';
import { constants } from './constants';
function id(id: string): Element { return document.getElementById(id); } function id(id: string): Element { return document.getElementById(id); }
const searchInstanceInput = () => id('search-instance') as HTMLInputElement; const searchInstanceInput = () => id('search-instance') as HTMLInputElement;
@ -25,7 +27,7 @@ const openInOriginalInstanceInput = () => id('open-in-original-instance') as HTM
function saveOptions(e) { function saveOptions(e) {
e.preventDefault(); e.preventDefault();
browser.storage.local.set({ browser.storage.local.set({
searchInstance: _.defaultTo('framatube.org', stripProtocol(searchInstanceInput().value)), searchInstance: _.defaultTo(constants.defaultInstance, stripProtocol(searchInstanceInput().value)),
openInOriginalInstance: _.defaultTo(true, openInOriginalInstanceInput().checked), openInOriginalInstance: _.defaultTo(true, openInOriginalInstanceInput().checked),
}); });
} }
@ -34,7 +36,7 @@ const stripProtocol = _.replace(/^https?:\/\//, '');
function restoreOptions() { function restoreOptions() {
browser.storage.local.get().then(result => { 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); openInOriginalInstanceInput().checked = _.defaultTo(true, result.openInOriginalInstance as boolean);
}) })
} }

View File

@ -17,6 +17,8 @@
import * as _ from 'lodash/fp'; import * as _ from 'lodash/fp';
import * as browser from 'webextension-polyfill'; import * as browser from 'webextension-polyfill';
import { constants } from './constants';
const watchURL = (host, uuid) => `https://${host}/videos/watch/${uuid}`; const watchURL = (host, uuid) => `https://${host}/videos/watch/${uuid}`;
const thumbnailURL = (host, path) => `https://${host}${path}`; const thumbnailURL = (host, path) => `https://${host}${path}`;
@ -30,7 +32,7 @@ function peertubeify(query: string) {
const options = await browser.storage.local.get(); const options = await browser.storage.local.get();
const openInOriginalInstance = _.getOr(true, 'openInOriginalInstance', options); 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 url = watchURL(openInOriginalInstance ? video.account.host : searchInstance, video.uuid);
const link = videoLink(url, video); const link = videoLink(url, video);