1
0
mirror of https://github.com/mxpv/podsync.git synced 2024-05-11 05:55:04 +00:00

110 lines
2.7 KiB
JavaScript
Raw Normal View History

2017-10-23 16:13:16 -07:00
var app = new Vue({
el: '#app',
2017-07-22 22:20:37 -07:00
2017-10-23 16:13:16 -07:00
data: {
link: '',
format: 'video',
quality: 'high',
count: 50,
2017-07-22 22:20:37 -07:00
2017-10-23 16:13:16 -07:00
showModal: false,
feedLink: '',
2017-07-22 22:20:37 -07:00
2017-10-23 16:36:26 -07:00
featureLevel: 0,
userId: '',
2017-10-23 16:13:16 -07:00
},
2017-07-22 22:20:37 -07:00
2017-10-23 16:13:16 -07:00
methods: {
submit: function() {
var vm = this;
if (vm.link === '') {
2017-07-22 22:20:37 -07:00
return;
}
2017-10-23 16:13:16 -07:00
axios.post('/api/create', {
url: this.link,
format: this.format,
quality: this.quality,
page_size: this.count,
}).then(function(response) {
vm.feedLink = vm.formatLink(response.data.id);
vm.showModal = true;
vm.link = '';
}).catch(vm.httpError);
},
httpError: function(error) {
try {
this.showError(error.response.data.error);
} catch (e) {
console.error(e);
this.showError(error.message);
}
},
2017-07-22 22:20:37 -07:00
2017-10-23 16:13:16 -07:00
showError: function(msg) {
alert(msg);
},
2017-07-22 22:20:37 -07:00
2017-10-23 16:13:16 -07:00
formatLink: function(id) {
if (location.port === '80' || location.port === '443') {
return location.protocol + '//' + location.hostname + '/' + id;
} else {
return location.protocol + '//' + location.host + '/' + id;
}
},
2017-07-22 22:20:37 -07:00
2017-10-23 16:13:16 -07:00
copyLink: function() {
if (!this.showModal || !this.canCopy) {
return
}
2017-07-22 22:20:37 -07:00
2017-10-23 16:13:16 -07:00
this.$refs.output.select();
2017-07-22 22:20:37 -07:00
2017-10-23 16:13:16 -07:00
if (!document.execCommand('copy')) {
self.showError('Can\'t copy... Something went wrong...');
}
2017-07-22 22:20:37 -07:00
}
2017-10-23 16:13:16 -07:00
},
computed: {
locked: function() {
return this.featureLevel === 0;
},
isMobile: function() {
return /iPhone|iPad|iPod|Android/i.test(navigator.userAgent);
},
canCopy: function() {
try {
return document.queryCommandSupported('copy') && !this.isMobile;
} catch (e) {
return false;
}
2017-11-10 17:13:01 -08:00
},
allow600pages: function() {
return !this.locked && this.featureLevel >= 2;
2017-07-22 22:20:37 -07:00
}
2017-10-23 16:13:16 -07:00
},
mounted: function() {
var vm = this;
window.addEventListener('keydown', function(event) {
// ESC handler
if (event.keyCode === 27 && vm.showModal) {
vm.showModal = false;
}
});
2018-12-09 11:35:50 -08:00
axios.get('/api/user').then(function (response) {
vm.userId = response.data.user_id;
vm.featureLevel = response.data.feature_level;
}).catch(function() {
vm.userId = ''
vm.featureLevel = 0;
})
2017-07-22 22:20:37 -07:00
}
});