- POST requests for feeds
- Export subscriptions
- Replaced xml-js
- Thumbnails for songs in local playlist
- Closes #107
This commit is contained in:
Shiny Nematoda 2023-02-09 11:37:06 +00:00 committed by vrifox
parent e01a6b71dc
commit 35ec1b6a3a
No known key found for this signature in database
GPG key ID: D40098E5B60B2197
14 changed files with 502 additions and 545 deletions

View file

@ -1,6 +1,4 @@
import { Buffer } from 'buffer/';
window.Buffer = Buffer;
import { json2xml } from 'xml-js';
import { useXML } from './xml.js';
export function useDash(streams, len) {
const sets = [],
@ -119,6 +117,5 @@ export function useDash(streams, len) {
],
};
console.log(json2xml(gen));
return json2xml(gen);
return useXML(gen);
}

View file

@ -6,15 +6,13 @@ export const HYPERPIPE_INSTANCE = 'hyperpipeapi.onrender.com';
export function getPipedQuery() {
const papi = new URLSearchParams(location.search).get('pipedapi');
if (!papi) {
return '';
}
if (!papi) return '';
return '?pipedapi=' + useSanitize(papi);
}
export async function getJson(url) {
const res = await fetch(url)
export async function getJson(url, opts) {
const res = await fetch(url, opts)
.then(res => res.json())
.catch(err => {
console.error(err);
@ -36,13 +34,13 @@ export async function getJson(url) {
}
}
export async function getJsonPiped(path) {
export async function getJsonPiped(path, opts) {
const root =
new URLSearchParams(location.search).get('pipedapi') ||
useStore().getItem('pipedapi') ||
PIPED_INSTANCE;
return await getJson('https://' + root + path);
return await getJson('https://' + root + path, opts);
}
export async function getJsonHyp(path) {
@ -51,7 +49,7 @@ export async function getJsonHyp(path) {
return await getJson('https://' + root + path);
}
export async function getJsonAuth(path, opts) {
export async function getJsonAuth(path, opts = opts) {
const root = useStore().getItem('authapi') || PIPED_INSTANCE;
return await fetch('https://' + root + path, opts)

View file

@ -37,7 +37,7 @@ export function useStore() {
export function useMetadata(url, urls, data) {
if ('mediaSession' in navigator) {
const now = urls.filter(u => u.url === url)[0];
const now = urls.find(u => u.url === url);
let artwork = [],
album = undefined;
@ -51,7 +51,7 @@ export function useMetadata(url, urls, data) {
src: t.url,
type: 'image/webp',
}));
} else artwork = [{ src: data.art, type: 'image/webp' }];
} else if (data.art) artwork = [{ src: data.art, type: 'image/webp' }];
console.log(album, artwork);
}

62
src/scripts/xml.js Normal file
View file

@ -0,0 +1,62 @@
function useAttr(json) {
let attrs = '';
for (const attr in json) {
if (json[attr] != null) {
attrs += ' ';
attrs += attr;
attrs += '="';
attrs += ('' + json[attr]).replace(/"/g, '&quote;');
attrs += '"';
}
}
return attrs;
}
function useElems(json) {
let elems = '';
json.forEach(elem => {
switch (elem.type) {
case 'element':
elems += '<';
elems += elem.name;
elems += useAttr(elem.attributes);
if (elem?.elements?.length > 0) {
elems += '>';
elems += useElems(elem.elements);
elems += '</';
elems += elem.name;
elems += '>';
} else elems += '/>';
break;
case 'text':
elems += ('' + elem.text)
.replace(/&amp;/g, '&')
.replace(/&/g, '&amp;')
.replace(/>/g, '&gt;')
.replace(/</g, '&lt;');
break;
}
});
return elems;
}
export function useXML(json) {
json = JSON.parse(JSON.stringify(json));
let base = '';
base += '<?xml';
base += useAttr(json.declaration.attributes);
base += '?>';
base += useElems(json.elements);
console.log(base);
return base;
}