Added geoLocation code
This commit is contained in:
parent
d62e2ea036
commit
bf2737b947
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "freetube",
|
||||
"version": "0.9.0",
|
||||
"version": "0.9.1",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
|
@ -8552,7 +8552,7 @@
|
|||
},
|
||||
"humanize-plus": {
|
||||
"version": "1.8.2",
|
||||
"resolved": "https://registry.npmjs.org/humanize-plus/-/humanize-plus-1.8.2.tgz",
|
||||
"resolved": "http://registry.npmjs.org/humanize-plus/-/humanize-plus-1.8.2.tgz",
|
||||
"integrity": "sha1-pls0RZrWNnrbs3B6gqPJ+RYWcDA=",
|
||||
"dev": true
|
||||
},
|
||||
|
@ -13899,7 +13899,7 @@
|
|||
},
|
||||
"safe-regex": {
|
||||
"version": "1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/safe-regex/-/safe-regex-1.1.0.tgz",
|
||||
"resolved": "http://registry.npmjs.org/safe-regex/-/safe-regex-1.1.0.tgz",
|
||||
"integrity": "sha1-QKNmnzsHfR6UPURinhV91IAjvy4=",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
|
@ -15070,7 +15070,7 @@
|
|||
},
|
||||
"strip-eof": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/strip-eof/-/strip-eof-1.0.0.tgz",
|
||||
"resolved": "http://registry.npmjs.org/strip-eof/-/strip-eof-1.0.0.tgz",
|
||||
"integrity": "sha1-u0P/VZim6wXYm1n80SnJgzE2Br8=",
|
||||
"dev": true
|
||||
},
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import Vue from 'vue'
|
||||
import $ from 'jquery'
|
||||
import FS from 'fs'
|
||||
import { mapActions } from 'vuex'
|
||||
import FtCard from '../ft-card/ft-card.vue'
|
||||
import FtSelect from '../ft-select/ft-select.vue'
|
||||
|
@ -24,6 +25,8 @@ export default Vue.extend({
|
|||
instanceNames: [],
|
||||
instanceValues: [],
|
||||
currentLocale: '',
|
||||
currentGeoLocation: '',
|
||||
geoLocationArray: [],
|
||||
backendValues: [
|
||||
'invidious',
|
||||
'local'
|
||||
|
@ -535,6 +538,9 @@ export default Vue.extend({
|
|||
}
|
||||
},
|
||||
computed: {
|
||||
isDev: function () {
|
||||
return process.env.NODE_ENV === 'development'
|
||||
},
|
||||
invidiousInstance: function () {
|
||||
return this.$store.getters.getInvidiousInstance
|
||||
},
|
||||
|
@ -584,6 +590,12 @@ export default Vue.extend({
|
|||
|
||||
return names
|
||||
},
|
||||
geoLocationOptions: function () {
|
||||
return this.geoLocationArray.map((entry) => { return entry.code })
|
||||
},
|
||||
geoLocationNames: function () {
|
||||
return this.geoLocationArray.map((entry) => { return entry.name })
|
||||
},
|
||||
|
||||
backendNames: function () {
|
||||
return [
|
||||
|
@ -639,6 +651,8 @@ export default Vue.extend({
|
|||
this.updateInvidiousInstanceBounce = debounce(this.updateInvidiousInstance, 500)
|
||||
|
||||
this.currentLocale = this.$i18n.locale
|
||||
this.currentGeoLocation = this.$i18n.geoLocation
|
||||
this.updateGeoLocationNames(this.currentLocale)
|
||||
},
|
||||
beforeDestroy: function () {
|
||||
if (this.invidiousInstance === '') {
|
||||
|
@ -664,6 +678,26 @@ export default Vue.extend({
|
|||
this.$i18n.locale = locale
|
||||
this.currentLocale = locale
|
||||
localStorage.setItem('locale', locale)
|
||||
this.updateGeoLocationNames(locale)
|
||||
},
|
||||
|
||||
updateGeoLocation: function (location) {
|
||||
this.$i18n.geoLocation = location
|
||||
this.currentGeoLocation = location
|
||||
localStorage.setItem('geoLocation', location)
|
||||
},
|
||||
|
||||
updateGeoLocationNames: function (locale) {
|
||||
let fileData
|
||||
const fileLocation = this.isDev ? '.' : `${__dirname}`
|
||||
if (FS.existsSync(`${fileLocation}/static/geolocations/${locale}`)) {
|
||||
fileData = FS.readFileSync(`${fileLocation}/static/geolocations/${locale}/countries.json`)
|
||||
} else {
|
||||
fileData = FS.readFileSync(`${fileLocation}/static/geolocations/en-US/countries.json`)
|
||||
}
|
||||
const countries = JSON.parse(fileData).map((entry) => { return { id: entry.id, name: entry.name, code: entry.alpha2 } })
|
||||
countries.sort((a, b) => { return a.id - b.id })
|
||||
this.geoLocationArray = countries
|
||||
},
|
||||
|
||||
...mapActions([
|
||||
|
|
|
@ -85,6 +85,13 @@
|
|||
:select-values="localeOptions"
|
||||
@change="updateLocale"
|
||||
/>
|
||||
<ft-select
|
||||
:placeholder="$t('Settings.General Settings.Region for Trending')"
|
||||
:value="currentGeoLocation"
|
||||
:select-names="geoLocationNames"
|
||||
:select-values="geoLocationOptions"
|
||||
@change="updateGeoLocation"
|
||||
/>
|
||||
</div>
|
||||
<ft-flex-box class="generalSettingsFlexBox">
|
||||
<ft-input
|
||||
|
|
|
@ -65,8 +65,8 @@ export default Vue.extend({
|
|||
this.isLoading = true
|
||||
|
||||
console.log('getting local trending')
|
||||
|
||||
ytrend.scrape_trending_page().then((result) => {
|
||||
console.log(localStorage.geoLocation)
|
||||
ytrend.scrape_trending_page(localStorage.geoLocation.toUpperCase()).then((result) => {
|
||||
const returnData = result.filter((item) => {
|
||||
return item.type === 'video' || item.type === 'channel' || item.type === 'playlist'
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue