mirror of
https://codeberg.org/Hyperpipe/Hyperpipe
synced 2025-06-29 13:28:02 +02:00
Changes:
- POST requests for feeds - Export subscriptions - Replaced xml-js - Thumbnails for songs in local playlist - Closes #107
This commit is contained in:
parent
e01a6b71dc
commit
35ec1b6a3a
14 changed files with 502 additions and 545 deletions
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
62
src/scripts/xml.js
Normal 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, '"e;');
|
||||
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(/&/g, '&')
|
||||
.replace(/&/g, '&')
|
||||
.replace(/>/g, '>')
|
||||
.replace(/</g, '<');
|
||||
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;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue