and though bugs are the bane of my existence, rest assured the wretched thing will get the best of care here

You need to sign in or sign up before continuing.
...
 
Commits (3)
...@@ -7,5 +7,6 @@ ...@@ -7,5 +7,6 @@
"trailingComma": "none", "trailingComma": "none",
"printWidth": 120, "printWidth": 120,
"arrowParens": "avoid", "arrowParens": "avoid",
"vueIndentScriptAndStyle": false "vueIndentScriptAndStyle": false,
"endOfLine": "lf"
} }
This diff is collapsed.
...@@ -19,19 +19,42 @@ import router from '@/router' ...@@ -19,19 +19,42 @@ import router from '@/router'
import store from '@/store' import store from '@/store'
import { socket } from '@/utils/socket' import { socket } from '@/utils/socket'
import { get } from '@/utils/api' import { fetchApi } from '@/utils/api'
import { toast } from '@/utils/toasts' import { toast } from '@/utils/toasts'
import { isValidURL } from '@/utils/utils' import { isValidURL } from '@/utils/utils'
import { sendAddToQueue } from '@/utils/downloads' import { sendAddToQueue } from '@/utils/downloads'
/* ===== App initialization ===== */ /* ===== App initialization ===== */
function startApp() { async function startApp() {
new Vue({ new Vue({
store, store,
router, router,
i18n, i18n,
render: h => h(App) render: h => h(App)
}).$mount('#app') }).$mount('#app')
const connectResponse = await (await fetch('connect')).json()
store.dispatch('setAppInfo', connectResponse.update)
if (connectResponse.autologin) {
console.info('Autologin successful')
let arl = localStorage.getItem('arl')
const accountNum = localStorage.getItem('accountNum')
if (arl) {
arl = arl.trim()
let result
if (accountNum !== 0) {
result = fetchApi('login', { arl, force: true, child: accountNum || 0 })
} else {
result = fetchApi('login', { arl })
}
result.then(loggedIn)
}
}
} }
function initClient() { function initClient() {
...@@ -53,7 +76,7 @@ document.addEventListener('paste', pasteEvent => { ...@@ -53,7 +76,7 @@ document.addEventListener('paste', pasteEvent => {
if (router.currentRoute.name === 'Link Analyzer') { if (router.currentRoute.name === 'Link Analyzer') {
socket.emit('analyzeLink', pastedText) socket.emit('analyzeLink', pastedText)
} else { } else {
if (pastedText.indexOf("\n") != -1) pastedText = pastedText.replace(/\n/g, ';'); if (pastedText.indexOf('\n') != -1) pastedText = pastedText.replace(/\n/g, ';')
sendAddToQueue(pastedText) sendAddToQueue(pastedText)
} }
} else { } else {
...@@ -83,11 +106,11 @@ function setClientModeKeyBindings() { ...@@ -83,11 +106,11 @@ function setClientModeKeyBindings() {
/* ===== Socketio listeners ===== */ /* ===== Socketio listeners ===== */
// Debug messages for socketio // Debug messages for socketio
socket.on('message', function(msg) { socket.on('message', function (msg) {
console.log(msg) console.log(msg)
}) })
function loggedIn(data){ function loggedIn(data) {
const { status, user } = data const { status, user } = data
switch (status) { switch (status) {
...@@ -122,27 +145,6 @@ function loggedIn(data){ ...@@ -122,27 +145,6 @@ function loggedIn(data){
} }
} }
fetch('connect').then(response => response.json()).then(data => {
store.dispatch('setAppInfo', data.update )
if (data.autologin) {
console.log("Autologin")
let arl = localStorage.getItem('arl')
let accountNum = localStorage.getItem('accountNum')
if (arl) {
arl = arl.trim()
let result
if (accountNum != 0) {
result = get('login', {arl: arl, force:true, child:accountNum || 0})
} else {
result = get('login', {arl})
}
result.then(loggedIn)
}
}
})
/* /*
socket.on('logging_in', function() { socket.on('logging_in', function() {
toast(i18n.t('toasts.loggingIn'), 'loading', false, 'login-toast') toast(i18n.t('toasts.loggingIn'), 'loading', false, 'login-toast')
...@@ -159,39 +161,39 @@ socket.on('logged_out', function() { ...@@ -159,39 +161,39 @@ socket.on('logged_out', function() {
}) })
*/ */
socket.on('restoringQueue', function() { socket.on('restoringQueue', function () {
toast(i18n.t('toasts.restoringQueue'), 'loading', false, 'restoring_queue') toast(i18n.t('toasts.restoringQueue'), 'loading', false, 'restoring_queue')
}) })
socket.on('cancellingCurrentItem', function(uuid) { socket.on('cancellingCurrentItem', function (uuid) {
toast(i18n.t('toasts.cancellingCurrentItem'), 'loading', false, 'cancelling_' + uuid) toast(i18n.t('toasts.cancellingCurrentItem'), 'loading', false, 'cancelling_' + uuid)
}) })
socket.on('currentItemCancelled', function(uuid) { socket.on('currentItemCancelled', function (uuid) {
toast(i18n.t('toasts.currentItemCancelled'), 'done', true, 'cancelling_' + uuid) toast(i18n.t('toasts.currentItemCancelled'), 'done', true, 'cancelling_' + uuid)
}) })
socket.on('startAddingArtist', function(data) { socket.on('startAddingArtist', function (data) {
toast(i18n.t('toasts.startAddingArtist', { artist: data.name }), 'loading', false, 'artist_' + data.id) toast(i18n.t('toasts.startAddingArtist', { artist: data.name }), 'loading', false, 'artist_' + data.id)
}) })
socket.on('finishAddingArtist', function(data) { socket.on('finishAddingArtist', function (data) {
toast(i18n.t('toasts.finishAddingArtist', { artist: data.name }), 'done', true, 'artist_' + data.id) toast(i18n.t('toasts.finishAddingArtist', { artist: data.name }), 'done', true, 'artist_' + data.id)
}) })
socket.on('startConvertingSpotifyPlaylist', function(id) { socket.on('startConvertingSpotifyPlaylist', function (id) {
toast(i18n.t('toasts.startConvertingSpotifyPlaylist'), 'loading', false, 'spotifyplaylist_' + id) toast(i18n.t('toasts.startConvertingSpotifyPlaylist'), 'loading', false, 'spotifyplaylist_' + id)
}) })
socket.on('finishConvertingSpotifyPlaylist', function(id) { socket.on('finishConvertingSpotifyPlaylist', function (id) {
toast(i18n.t('toasts.finishConvertingSpotifyPlaylist'), 'done', true, 'spotifyplaylist_' + id) toast(i18n.t('toasts.finishConvertingSpotifyPlaylist'), 'done', true, 'spotifyplaylist_' + id)
}) })
socket.on('errorMessage', function(error) { socket.on('errorMessage', function (error) {
toast(error, 'error') toast(error, 'error')
}) })
socket.on('queueError', function(queueItem) { socket.on('queueError', function (queueItem) {
if (queueItem.errid) { if (queueItem.errid) {
toast(queueItem.link + ' - ' + i18n.t(`errors.ids.${queueItem.errid}`), 'error') toast(queueItem.link + ' - ' + i18n.t(`errors.ids.${queueItem.errid}`), 'error')
} else { } else {
...@@ -199,18 +201,18 @@ socket.on('queueError', function(queueItem) { ...@@ -199,18 +201,18 @@ socket.on('queueError', function(queueItem) {
} }
}) })
socket.on('alreadyInQueue', function(data) { socket.on('alreadyInQueue', function (data) {
toast(i18n.t('toasts.alreadyInQueue', { item: data.title }), 'playlist_add_check') toast(i18n.t('toasts.alreadyInQueue', { item: data.title }), 'playlist_add_check')
}) })
socket.on('loginNeededToDownload', function(data) { socket.on('loginNeededToDownload', function (data) {
toast(i18n.t('toasts.loginNeededToDownload'), 'report') toast(i18n.t('toasts.loginNeededToDownload'), 'report')
}) })
socket.on('startGeneratingItems', function(data) { socket.on('startGeneratingItems', function (data) {
toast(i18n.t('toasts.startGeneratingItems', { n: data.total }), 'loading', false, 'batch_' + data.uuid) toast(i18n.t('toasts.startGeneratingItems', { n: data.total }), 'loading', false, 'batch_' + data.uuid)
}) })
socket.on('finishGeneratingItems', function(data) { socket.on('finishGeneratingItems', function (data) {
toast(i18n.t('toasts.finishGeneratingItems', { n: data.total }), 'done', true, 'batch_' + data.uuid) toast(i18n.t('toasts.finishGeneratingItems', { n: data.total }), 'done', true, 'batch_' + data.uuid)
}) })
import { ref } from '@vue/composition-api' import { ref } from '@vue/composition-api'
import { get } from '@/utils/api' import { fetchApi } from '@/utils/api'
const searchResult = ref({}) const searchResult = ref({})
function performMainSearch(searchTerm) { function performMainSearch(searchTerm) {
get('mainSearch', { term: searchTerm }) fetchApi('mainSearch', { term: searchTerm }).then(data => {
.then(data => {
searchResult.value = data searchResult.value = data
}) })
} }
......
import { ref } from '@vue/composition-api' import { ref } from '@vue/composition-api'
import { get } from '@/utils/api' import { fetchApi } from '@/utils/api'
const result = ref({}) const result = ref({})
function performSearch({ term, type, start = 0, nb = 30 }) { function performSearch({ term, type, start = 0, nb = 30 }) {
get('search', { fetchApi('search', {
term, term,
type, type,
start, start,
......
export const get = function(key, data){ export function fetchApi(key, data) {
let url = `/api/${key}` const url = new URL(`${window.location.origin}/api/${key}`)
if (data){
let query = Object.keys(data) Object.keys(data).forEach(key => {
.map(k => encodeURIComponent(k) + '=' + encodeURIComponent(data[k])) url.searchParams.append(key, data[key])
.join('&') })
url += '?'+query
} return fetch(url.href).then(response => response.json())
return fetch(url).then(response => response.json())
} }
import { get } from '@/utils/api' import { fetchApi } from '@/utils/api'
/** /**
* @param {string} url * @param {string} url
...@@ -7,7 +7,7 @@ import { get } from '@/utils/api' ...@@ -7,7 +7,7 @@ import { get } from '@/utils/api'
export function sendAddToQueue(url, bitrate = null) { export function sendAddToQueue(url, bitrate = null) {
if (!url) throw new Error('No URL given to sendAddToQueue function!') if (!url) throw new Error('No URL given to sendAddToQueue function!')
get('addToQueue', { url, bitrate }) fetchApi('addToQueue', { url, bitrate })
} }
export function aggregateDownloadLinks(releases) { export function aggregateDownloadLinks(releases) {
......
import store from '@/store' let wasEventListenerAdded = false
class CustomSocket extends WebSocket { class CustomSocket extends WebSocket {
constructor(args) { constructor(args) {
super(args) super(args)
} }
emit(key, data) { emit(key, data) {
if (this.readyState != WebSocket.OPEN) return false if (this.readyState !== WebSocket.OPEN) return false
this.send(JSON.stringify({key:key, data:data}))
this.send(JSON.stringify({ key, data }))
} }
on(key, cb) {
if (!wasEventListenerAdded) {
wasEventListenerAdded = true
this.addEventListener('message', event => {
const messageData = JSON.parse(event.data)
on(key, callback) { if (messageData.key === key) {
this.addEventListener('message', function(event){ cb(messageData.data)
let data = JSON.parse(event.data) }
console.log(data)
if (data.key == key) callback(data.data)
}) })
} }
}
off() {
console.log('off!')
// this.removeEventListener('message')
}
} }
export const socket = new CustomSocket('ws://' + location.host + '/') export const socket = new CustomSocket('ws://' + location.host + '/')