mirror of https://github.com/VueTubeApp/VueTube
feat: added constant variables for URLs in constants.js
This commit is contained in:
parent
f18bfa8234
commit
3fc69e7c33
|
@ -3,6 +3,7 @@
|
|||
|
||||
import { Http } from '@capacitor-community/http';
|
||||
import { getBetweenStrings } from './utils';
|
||||
import constants from '../static/constants';
|
||||
|
||||
class Innertube {
|
||||
constructor(ErrorCallback) {
|
||||
|
@ -12,7 +13,7 @@ class Innertube {
|
|||
}
|
||||
|
||||
async init() {
|
||||
const html = await Http.get({ url: 'https://www.youtube.com', params: { hl: "en" } }).catch((error) => error);
|
||||
const html = await Http.get({ url: constants.URLS.YT_URL, params: { hl: "en" } }).catch((error) => error);
|
||||
if (html instanceof Error) this.ErrorCallback(html.message, true);
|
||||
try {
|
||||
const data = JSON.parse(getBetweenStrings(html.data, 'ytcfg.set(', ');'));
|
||||
|
@ -53,7 +54,7 @@ class Innertube {
|
|||
console.log(data)
|
||||
|
||||
const response = await Http.post({
|
||||
url: `https://www.youtube.com/youtubei/v1/browse?key=${this.key}`,
|
||||
url: `${constants.URLS.YT_BASE_API}/browse?key=${this.key}`,
|
||||
data: data,
|
||||
headers: { "Content-Type": "application/json" }
|
||||
}).catch((error) => error);
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
//--- Modules/Imports ---//
|
||||
import { Http } from '@capacitor-community/http';
|
||||
import constants from '../static/constants';
|
||||
|
||||
const module = {
|
||||
|
||||
|
@ -8,7 +9,7 @@ const module = {
|
|||
|
||||
Http.request({
|
||||
method: 'GET',
|
||||
url: "https://api.github.com/repos/Frontesque/VueTube/commits",
|
||||
url: `${constants.URLS.VT_GITHUB}/commits`,
|
||||
params: {}
|
||||
})
|
||||
.then((res) => {
|
||||
|
@ -22,7 +23,7 @@ const module = {
|
|||
|
||||
getRuns(item, callback) {
|
||||
|
||||
let url = `https://api.github.com/repos/Frontesque/VueTube/commits/${item.sha}/check-runs`;
|
||||
let url = `${constants.URLS.VT_GITHUB}/commits/${item.sha}/check-runs`;
|
||||
|
||||
Http.request({
|
||||
method: 'GET',
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
//--- Modules/Imports ---//
|
||||
import { Http } from '@capacitor-community/http';
|
||||
import Innertube from './innertube'
|
||||
import constants from '../static/constants';
|
||||
|
||||
//--- Logger Function ---//
|
||||
function logger(func, data, isError = false) {
|
||||
|
@ -48,7 +49,7 @@ function youtubeParse(html, callback) {
|
|||
function youtubeSearch(text, callback) {
|
||||
Http.request({
|
||||
method: 'GET',
|
||||
url: 'https://youtube.com/results',
|
||||
url: `${constants.URLS.YT_URL}/results`,
|
||||
params: { q: text, hl: "en" }
|
||||
})
|
||||
.then((res) => {
|
||||
|
@ -77,7 +78,7 @@ const searchModule = {
|
|||
autoComplete(text, callback) {
|
||||
Http.request({
|
||||
method: 'GET',
|
||||
url: 'https://suggestqueries-clients6.youtube.com/complete/search',
|
||||
url: `${constants.URLS.YT_SUGGESTIONS}/search`,
|
||||
params: { client: 'youtube', q: text }
|
||||
})
|
||||
.then((res) => {
|
||||
|
@ -119,13 +120,6 @@ const searchModule = {
|
|||
|
||||
},
|
||||
|
||||
async recommend() {
|
||||
const recommendAPI = await Innertube.create((message, isError) => {
|
||||
logger("recommendation", message, isError)
|
||||
});
|
||||
return await recommendAPI.getRecommendations();
|
||||
},
|
||||
|
||||
getVideo(id) {
|
||||
return id;
|
||||
}
|
||||
|
@ -134,11 +128,17 @@ const searchModule = {
|
|||
|
||||
//--- Recommendations --//
|
||||
const recommendationModule = {
|
||||
|
||||
async recommend() {
|
||||
const recommendAPI = await Innertube.create((message, isError) => {
|
||||
logger("recommendation", message, isError)
|
||||
});
|
||||
return await recommendAPI.getRecommendations();
|
||||
},
|
||||
}
|
||||
|
||||
//--- Start ---//
|
||||
export default ({ app }, inject) => {
|
||||
inject('youtube', searchModule, recommendationModule)
|
||||
inject('youtube', searchModule)
|
||||
inject('youtube', recommendationModule)
|
||||
}
|
||||
logger("Initialize", "Program Started");
|
|
@ -0,0 +1,11 @@
|
|||
// To centeralize certain values and URLs as for easier debugging and refactoring
|
||||
|
||||
module.exports = {
|
||||
URLS: {
|
||||
YT_URL: 'https://www.youtube.com',
|
||||
YT_MUSIC_URL: 'https://music.youtube.com',
|
||||
YT_BASE_API: 'https://www.youtube.com/youtubei/v1',
|
||||
YT_SUGGESTIONS: "https://suggestqueries.google.com/complete",
|
||||
VT_GITHUB: "https://api.github.com/repos/Frontesque/VueTube",
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue