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

...
 
Commits (3)
......@@ -7,5 +7,6 @@
"trailingComma": "none",
"printWidth": 120,
"arrowParens": "avoid",
"vueIndentScriptAndStyle": false
}
\ No newline at end of file
"vueIndentScriptAndStyle": false,
"endOfLine": "lf"
}
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -19,19 +19,42 @@ import router from '@/router'
import store from '@/store'
import { socket } from '@/utils/socket'
import { get } from '@/utils/api'
import { fetchApi } from '@/utils/api'
import { toast } from '@/utils/toasts'
import { isValidURL } from '@/utils/utils'
import { sendAddToQueue } from '@/utils/downloads'
/* ===== App initialization ===== */
function startApp() {
async function startApp() {
new Vue({
store,
router,
i18n,
render: h => h(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() {
......@@ -53,7 +76,7 @@ document.addEventListener('paste', pasteEvent => {
if (router.currentRoute.name === 'Link Analyzer') {
socket.emit('analyzeLink', pastedText)
} else {
if (pastedText.indexOf("\n") != -1) pastedText = pastedText.replace(/\n/g, ';');
if (pastedText.indexOf('\n') != -1) pastedText = pastedText.replace(/\n/g, ';')
sendAddToQueue(pastedText)
}
} else {
......@@ -83,11 +106,11 @@ function setClientModeKeyBindings() {
/* ===== Socketio listeners ===== */
// Debug messages for socketio
socket.on('message', function(msg) {
socket.on('message', function (msg) {
console.log(msg)
})
function loggedIn(data){
function loggedIn(data) {
const { status, user } = data
switch (status) {
......@@ -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() {
toast(i18n.t('toasts.loggingIn'), 'loading', false, 'login-toast')
......@@ -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')
})
socket.on('cancellingCurrentItem', function(uuid) {
socket.on('cancellingCurrentItem', function (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)
})
socket.on('startAddingArtist', function(data) {
socket.on('startAddingArtist', function (data) {
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)
})
socket.on('startConvertingSpotifyPlaylist', function(id) {
socket.on('startConvertingSpotifyPlaylist', function (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)
})
socket.on('errorMessage', function(error) {
socket.on('errorMessage', function (error) {
toast(error, 'error')
})
socket.on('queueError', function(queueItem) {
socket.on('queueError', function (queueItem) {
if (queueItem.errid) {
toast(queueItem.link + ' - ' + i18n.t(`errors.ids.${queueItem.errid}`), 'error')
} else {
......@@ -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')
})
socket.on('loginNeededToDownload', function(data) {
socket.on('loginNeededToDownload', function (data) {
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)
})
socket.on('finishGeneratingItems', function(data) {
socket.on('finishGeneratingItems', function (data) {
toast(i18n.t('toasts.finishGeneratingItems', { n: data.total }), 'done', true, 'batch_' + data.uuid)
})
import { ref } from '@vue/composition-api'
import { get } from '@/utils/api'
import { fetchApi } from '@/utils/api'
const searchResult = ref({})
function performMainSearch(searchTerm) {
get('mainSearch', { term: searchTerm })
.then(data => {
fetchApi('mainSearch', { term: searchTerm }).then(data => {
searchResult.value = data
})
}
......
import { ref } from '@vue/composition-api'
import { get } from '@/utils/api'
import { fetchApi } from '@/utils/api'
const result = ref({})
function performSearch({ term, type, start = 0, nb = 30 }) {
get('search', {
fetchApi('search', {
term,
type,
start,
......
export const get = function(key, data){
let url = `/api/${key}`
if (data){
let query = Object.keys(data)
.map(k => encodeURIComponent(k) + '=' + encodeURIComponent(data[k]))
.join('&')
url += '?'+query
}
return fetch(url).then(response => response.json())
export function fetchApi(key, data) {
const url = new URL(`${window.location.origin}/api/${key}`)
Object.keys(data).forEach(key => {
url.searchParams.append(key, data[key])
})
return fetch(url.href).then(response => response.json())
}
import { get } from '@/utils/api'
import { fetchApi } from '@/utils/api'
/**
* @param {string} url
......@@ -7,7 +7,7 @@ import { get } from '@/utils/api'
export function sendAddToQueue(url, bitrate = null) {
if (!url) throw new Error('No URL given to sendAddToQueue function!')
get('addToQueue', { url, bitrate })
fetchApi('addToQueue', { url, bitrate })
}
export function aggregateDownloadLinks(releases) {
......
import store from '@/store'
let wasEventListenerAdded = false
class CustomSocket extends WebSocket {
constructor(args) {
super(args)
}
constructor(args) {
super(args)
}
emit(key, data) {
if (this.readyState != WebSocket.OPEN) return false
this.send(JSON.stringify({key:key, data:data}))
if (this.readyState !== WebSocket.OPEN) return false
this.send(JSON.stringify({ key, data }))
}
on(key, cb) {
if (!wasEventListenerAdded) {
wasEventListenerAdded = true
on(key, callback) {
this.addEventListener('message', function(event){
let data = JSON.parse(event.data)
console.log(data)
if (data.key == key) callback(data.data)
})
this.addEventListener('message', event => {
const messageData = JSON.parse(event.data)
if (messageData.key === key) {
cb(messageData.data)
}
})
}
}
off() {
console.log('off!')
// this.removeEventListener('message')
}
}
......