Fetch config.json from public

This commit is contained in:
Andrea Fazzi 2021-11-09 10:07:21 +01:00
parent 3dff670430
commit c8d499d790
5 changed files with 145 additions and 73 deletions

View file

@ -910,19 +910,15 @@ var app = (function () {
}
}
const config = {
endpoint: "https://yt-dls-api.andreafazzi.eu"
};
/* src/Task.svelte generated by Svelte v3.42.4 */
const { Error: Error_1 } = globals;
const file$2 = "src/Task.svelte";
// (60:0) {:catch error}
// (59:0) {:catch error}
function create_catch_block(ctx) {
let p;
let t_value = /*error*/ ctx[8].message + "";
let t_value = /*error*/ ctx[9].message + "";
let t;
const block = {
@ -930,7 +926,7 @@ var app = (function () {
p = element("p");
t = text(t_value);
set_style(p, "color", "red");
add_location(p, file$2, 60, 2, 1616);
add_location(p, file$2, 59, 2, 1575);
},
m: function mount(target, anchor) {
insert_dev(target, p, anchor);
@ -946,14 +942,14 @@ var app = (function () {
block,
id: create_catch_block.name,
type: "catch",
source: "(60:0) {:catch error}",
source: "(59:0) {:catch error}",
ctx
});
return block;
}
// (48:0) {:then video_info}
// (47:0) {:then video_info}
function create_then_block(ctx) {
let a;
let div2;
@ -993,22 +989,22 @@ var app = (function () {
t5 = text(/*url*/ ctx[0]);
t6 = space();
img = element("img");
add_location(h5, file$2, 50, 49, 1225);
add_location(h5, file$2, 49, 49, 1184);
attr_dev(div0, "class", "pb-2 flex-grow-1 bd-highlight");
add_location(div0, file$2, 50, 6, 1182);
add_location(small0, file$2, 51, 42, 1301);
add_location(div0, file$2, 49, 6, 1141);
add_location(small0, file$2, 50, 42, 1260);
attr_dev(div1, "class", "pb-2 px-2 bd-highlight");
add_location(div1, file$2, 51, 6, 1265);
add_location(div1, file$2, 50, 6, 1224);
attr_dev(div2, "class", "d-flex bd-highlight");
add_location(div2, file$2, 49, 4, 1142);
add_location(small1, file$2, 56, 7, 1523);
add_location(p, file$2, 56, 4, 1520);
add_location(div2, file$2, 48, 4, 1101);
add_location(small1, file$2, 55, 7, 1482);
add_location(p, file$2, 55, 4, 1479);
if (!src_url_equal(img.src, img_src_value = /*video_info*/ ctx[3].Thumbnails[0].URL)) attr_dev(img, "src", img_src_value);
add_location(img, file$2, 57, 4, 1552);
add_location(img, file$2, 56, 4, 1511);
attr_dev(a, "href", /*download_path*/ ctx[2]);
attr_dev(a, "class", "list-group-item list-group-item-action");
attr_dev(a, "aria-current", "true");
add_location(a, file$2, 48, 2, 1046);
add_location(a, file$2, 47, 2, 1005);
},
m: function mount(target, anchor) {
insert_dev(target, a, anchor);
@ -1058,14 +1054,14 @@ var app = (function () {
block,
id: create_then_block.name,
type: "then",
source: "(48:0) {:then video_info}",
source: "(47:0) {:then video_info}",
ctx
});
return block;
}
// (53:6) {#if status.Status}
// (52:6) {#if status.Status}
function create_if_block$1(ctx) {
let div;
let span;
@ -1079,9 +1075,9 @@ var app = (function () {
span = element("span");
t = text(t_value);
attr_dev(span, "class", span_class_value = /*statusBadge*/ ctx[4][/*status*/ ctx[1].Status].class);
add_location(span, file$2, 53, 37, 1399);
add_location(span, file$2, 52, 37, 1358);
attr_dev(div, "class", "pb-2 px-2 bd-highlight");
add_location(div, file$2, 53, 1, 1363);
add_location(div, file$2, 52, 1, 1322);
},
m: function mount(target, anchor) {
insert_dev(target, div, anchor);
@ -1104,14 +1100,14 @@ var app = (function () {
block,
id: create_if_block$1.name,
type: "if",
source: "(53:6) {#if status.Status}",
source: "(52:6) {#if status.Status}",
ctx
});
return block;
}
// (46:24) <p>waiting...</p> {:then video_info}
// (45:24) <p>waiting...</p> {:then video_info}
function create_pending_block(ctx) {
let p;
@ -1119,7 +1115,7 @@ var app = (function () {
c: function create() {
p = element("p");
p.textContent = "waiting...";
add_location(p, file$2, 46, 2, 1007);
add_location(p, file$2, 45, 2, 966);
},
m: function mount(target, anchor) {
insert_dev(target, p, anchor);
@ -1134,7 +1130,7 @@ var app = (function () {
block,
id: create_pending_block.name,
type: "pending",
source: "(46:24) <p>waiting...</p> {:then video_info}",
source: "(45:24) <p>waiting...</p> {:then video_info}",
ctx
});
@ -1153,7 +1149,7 @@ var app = (function () {
then: create_then_block,
catch: create_catch_block,
value: 3,
error: 8
error: 9
};
handle_promise(/*startDownload*/ ctx[5](), info);
@ -1201,6 +1197,7 @@ var app = (function () {
let { $$slots: slots = {}, $$scope } = $$props;
validate_slots('Task', slots, []);
let { url } = $$props;
let { endpoint } = $$props;
let video_info = {};
let status = {};
@ -1222,7 +1219,7 @@ var app = (function () {
let download_path = "#";
async function startDownload() {
const res = await fetch(`${config.endpoint}/download?url=${url}`);
const res = await fetch(`${endpoint}/download?url=${url}`);
$$invalidate(3, video_info = await res.json());
if (res.ok) {
@ -1233,12 +1230,12 @@ var app = (function () {
}
async function getStatus() {
const res = await fetch(`${config.endpoint}/status?url=${url}`);
const res = await fetch(`${endpoint}/status?url=${url}`);
$$invalidate(1, status = await res.json());
if (res.ok) {
if (status.Id) {
$$invalidate(2, download_path = `${config.endpoint}/data/${status.Id}`);
$$invalidate(2, download_path = `${endpoint}/data/${status.Id}`);
}
return status;
@ -1254,7 +1251,7 @@ var app = (function () {
1000
);
const writable_props = ['url'];
const writable_props = ['url', 'endpoint'];
Object.keys($$props).forEach(key => {
if (!~writable_props.indexOf(key) && key.slice(0, 2) !== '$$' && key !== 'slot') console.warn(`<Task> was created with unknown prop '${key}'`);
@ -1262,11 +1259,12 @@ var app = (function () {
$$self.$$set = $$props => {
if ('url' in $$props) $$invalidate(0, url = $$props.url);
if ('endpoint' in $$props) $$invalidate(6, endpoint = $$props.endpoint);
};
$$self.$capture_state = () => ({
config,
url,
endpoint,
video_info,
status,
statusBadge,
@ -1278,6 +1276,7 @@ var app = (function () {
$$self.$inject_state = $$props => {
if ('url' in $$props) $$invalidate(0, url = $$props.url);
if ('endpoint' in $$props) $$invalidate(6, endpoint = $$props.endpoint);
if ('video_info' in $$props) $$invalidate(3, video_info = $$props.video_info);
if ('status' in $$props) $$invalidate(1, status = $$props.status);
if ('statusBadge' in $$props) $$invalidate(4, statusBadge = $$props.statusBadge);
@ -1288,13 +1287,13 @@ var app = (function () {
$$self.$inject_state($$props.$$inject);
}
return [url, status, download_path, video_info, statusBadge, startDownload];
return [url, status, download_path, video_info, statusBadge, startDownload, endpoint];
}
class Task extends SvelteComponentDev {
constructor(options) {
super(options);
init(this, options, instance$2, create_fragment$2, safe_not_equal, { url: 0 });
init(this, options, instance$2, create_fragment$2, safe_not_equal, { url: 0, endpoint: 6 });
dispatch_dev("SvelteRegisterComponent", {
component: this,
@ -1309,6 +1308,10 @@ var app = (function () {
if (/*url*/ ctx[0] === undefined && !('url' in props)) {
console.warn("<Task> was created without expected prop 'url'");
}
if (/*endpoint*/ ctx[6] === undefined && !('endpoint' in props)) {
console.warn("<Task> was created without expected prop 'endpoint'");
}
}
get url() {
@ -1318,6 +1321,14 @@ var app = (function () {
set url(value) {
throw new Error_1("<Task>: Props cannot be set directly on the component instance unless compiling with 'accessors: true' or '<svelte:options accessors/>'");
}
get endpoint() {
throw new Error_1("<Task>: Props cannot be read directly from the component instance unless compiling with 'accessors: true' or '<svelte:options accessors/>'");
}
set endpoint(value) {
throw new Error_1("<Task>: Props cannot be set directly on the component instance unless compiling with 'accessors: true' or '<svelte:options accessors/>'");
}
}
/* src/TaskManager.svelte generated by Svelte v3.42.4 */
@ -1325,20 +1336,20 @@ var app = (function () {
function get_each_context(ctx, list, i) {
const child_ctx = ctx.slice();
child_ctx[1] = list[i];
child_ctx[2] = list[i];
return child_ctx;
}
// (6:0) {#if $tasks.length > 0}
// (8:0) {#if $tasks.length > 0}
function create_if_block(ctx) {
let div;
let ul;
let each_blocks = [];
let each_1_lookup = new Map();
let current;
let each_value = /*$tasks*/ ctx[0];
let each_value = /*$tasks*/ ctx[1];
validate_each_argument(each_value);
const get_key = ctx => /*task*/ ctx[1].url;
const get_key = ctx => /*task*/ ctx[2].url;
validate_each_keys(ctx, each_value, get_each_context, get_key);
for (let i = 0; i < each_value.length; i += 1) {
@ -1357,9 +1368,9 @@ var app = (function () {
}
attr_dev(ul, "class", "list-group");
add_location(ul, file$1, 7, 2, 140);
add_location(ul, file$1, 9, 2, 164);
attr_dev(div, "class", "mt-4");
add_location(div, file$1, 6, 0, 119);
add_location(div, file$1, 8, 0, 143);
},
m: function mount(target, anchor) {
insert_dev(target, div, anchor);
@ -1372,8 +1383,8 @@ var app = (function () {
current = true;
},
p: function update(ctx, dirty) {
if (dirty & /*$tasks*/ 1) {
each_value = /*$tasks*/ ctx[0];
if (dirty & /*$tasks, endpoint*/ 3) {
each_value = /*$tasks*/ ctx[1];
validate_each_argument(each_value);
group_outros();
validate_each_keys(ctx, each_value, get_each_context, get_key);
@ -1410,21 +1421,24 @@ var app = (function () {
block,
id: create_if_block.name,
type: "if",
source: "(6:0) {#if $tasks.length > 0}",
source: "(8:0) {#if $tasks.length > 0}",
ctx
});
return block;
}
// (9:4) {#each $tasks as task (task.url)}
// (11:4) {#each $tasks as task (task.url)}
function create_each_block(key_1, ctx) {
let first;
let task;
let current;
task = new Task({
props: { url: /*task*/ ctx[1].url },
props: {
url: /*task*/ ctx[2].url,
endpoint: /*endpoint*/ ctx[0]
},
$$inline: true
});
@ -1444,7 +1458,8 @@ var app = (function () {
p: function update(new_ctx, dirty) {
ctx = new_ctx;
const task_changes = {};
if (dirty & /*$tasks*/ 1) task_changes.url = /*task*/ ctx[1].url;
if (dirty & /*$tasks*/ 2) task_changes.url = /*task*/ ctx[2].url;
if (dirty & /*endpoint*/ 1) task_changes.endpoint = /*endpoint*/ ctx[0];
task.$set(task_changes);
},
i: function intro(local) {
@ -1466,7 +1481,7 @@ var app = (function () {
block,
id: create_each_block.name,
type: "each",
source: "(9:4) {#each $tasks as task (task.url)}",
source: "(11:4) {#each $tasks as task (task.url)}",
ctx
});
@ -1476,7 +1491,7 @@ var app = (function () {
function create_fragment$1(ctx) {
let if_block_anchor;
let current;
let if_block = /*$tasks*/ ctx[0].length > 0 && create_if_block(ctx);
let if_block = /*$tasks*/ ctx[1].length > 0 && create_if_block(ctx);
const block = {
c: function create() {
@ -1492,11 +1507,11 @@ var app = (function () {
current = true;
},
p: function update(ctx, [dirty]) {
if (/*$tasks*/ ctx[0].length > 0) {
if (/*$tasks*/ ctx[1].length > 0) {
if (if_block) {
if_block.p(ctx, dirty);
if (dirty & /*$tasks*/ 1) {
if (dirty & /*$tasks*/ 2) {
transition_in(if_block, 1);
}
} else {
@ -1544,23 +1559,37 @@ var app = (function () {
function instance$1($$self, $$props, $$invalidate) {
let $tasks;
validate_store(tasks, 'tasks');
component_subscribe($$self, tasks, $$value => $$invalidate(0, $tasks = $$value));
component_subscribe($$self, tasks, $$value => $$invalidate(1, $tasks = $$value));
let { $$slots: slots = {}, $$scope } = $$props;
validate_slots('TaskManager', slots, []);
const writable_props = [];
let { endpoint } = $$props;
const writable_props = ['endpoint'];
Object.keys($$props).forEach(key => {
if (!~writable_props.indexOf(key) && key.slice(0, 2) !== '$$' && key !== 'slot') console.warn(`<TaskManager> was created with unknown prop '${key}'`);
});
$$self.$capture_state = () => ({ tasks, Task, $tasks });
return [$tasks];
$$self.$$set = $$props => {
if ('endpoint' in $$props) $$invalidate(0, endpoint = $$props.endpoint);
};
$$self.$capture_state = () => ({ tasks, Task, endpoint, $tasks });
$$self.$inject_state = $$props => {
if ('endpoint' in $$props) $$invalidate(0, endpoint = $$props.endpoint);
};
if ($$props && "$$inject" in $$props) {
$$self.$inject_state($$props.$$inject);
}
return [endpoint, $tasks];
}
class TaskManager extends SvelteComponentDev {
constructor(options) {
super(options);
init(this, options, instance$1, create_fragment$1, safe_not_equal, {});
init(this, options, instance$1, create_fragment$1, safe_not_equal, { endpoint: 0 });
dispatch_dev("SvelteRegisterComponent", {
component: this,
@ -1568,6 +1597,21 @@ var app = (function () {
options,
id: create_fragment$1.name
});
const { ctx } = this.$$;
const props = options.props || {};
if (/*endpoint*/ ctx[0] === undefined && !('endpoint' in props)) {
console.warn("<TaskManager> was created without expected prop 'endpoint'");
}
}
get endpoint() {
throw new Error("<TaskManager>: Props cannot be read directly from the component instance unless compiling with 'accessors: true' or '<svelte:options accessors/>'");
}
set endpoint(value) {
throw new Error("<TaskManager>: Props cannot be set directly on the component instance unless compiling with 'accessors: true' or '<svelte:options accessors/>'");
}
}
@ -1585,7 +1629,11 @@ var app = (function () {
let taskmanager;
let current;
url = new Url({ $$inline: true });
taskmanager = new TaskManager({ $$inline: true });
taskmanager = new TaskManager({
props: { endpoint: /*config*/ ctx[0].endpoint },
$$inline: true
});
const block = {
c: function create() {
@ -1596,14 +1644,15 @@ var app = (function () {
create_component(url.$$.fragment);
t1 = space();
create_component(taskmanager.$$.fragment);
attr_dev(img, "alt", "yt-dls logo");
attr_dev(img, "width", "200px");
attr_dev(img, "class", "rounded mx-auto d-block p-3");
if (!src_url_equal(img.src, img_src_value = "newpipe_logo.svg")) attr_dev(img, "src", img_src_value);
add_location(img, file, 6, 2, 130);
add_location(img, file, 13, 2, 246);
attr_dev(div0, "class", "container");
add_location(div0, file, 7, 2, 212);
add_location(div0, file, 14, 2, 346);
attr_dev(div1, "class", "container");
add_location(div1, file, 5, 0, 104);
add_location(div1, file, 12, 0, 220);
},
l: function claim(nodes) {
throw new Error("options.hydrate only works if the component was compiled with the `hydratable: true` option");
@ -1618,7 +1667,11 @@ var app = (function () {
mount_component(taskmanager, div0, null);
current = true;
},
p: noop,
p: function update(ctx, [dirty]) {
const taskmanager_changes = {};
if (dirty & /*config*/ 1) taskmanager_changes.endpoint = /*config*/ ctx[0].endpoint;
taskmanager.$set(taskmanager_changes);
},
i: function intro(local) {
if (current) return;
transition_in(url.$$.fragment, local);
@ -1651,14 +1704,25 @@ var app = (function () {
function instance($$self, $$props, $$invalidate) {
let { $$slots: slots = {}, $$scope } = $$props;
validate_slots('App', slots, []);
let config = {};
fetch('/config.json').then(response => response.json()).then(data => $$invalidate(0, config = data));
const writable_props = [];
Object.keys($$props).forEach(key => {
if (!~writable_props.indexOf(key) && key.slice(0, 2) !== '$$' && key !== 'slot') console.warn(`<App> was created with unknown prop '${key}'`);
});
$$self.$capture_state = () => ({ Url, TaskManager });
return [];
$$self.$capture_state = () => ({ Url, TaskManager, config });
$$self.$inject_state = $$props => {
if ('config' in $$props) $$invalidate(0, config = $$props.config);
};
if ($$props && "$$inject" in $$props) {
$$self.$inject_state($$props.$$inject);
}
return [config];
}
class App extends SvelteComponentDev {

File diff suppressed because one or more lines are too long

View file

@ -1,12 +1,19 @@
<script>
import Url from './Url.svelte';
import TaskManager from './TaskManager.svelte';
let config = {}
fetch('/config.json')
.then(response => response.json())
.then(data => config = data);
</script>
<div class="container">
<img width="200px" class="rounded mx-auto d-block p-3" src="newpipe_logo.svg"/>
<img alt="yt-dls logo" width="200px" class="rounded mx-auto d-block p-3" src="newpipe_logo.svg"/>
<div class="container">
<Url/>
<TaskManager/>
<TaskManager endpoint={config.endpoint}/>
</div>
</div>

View file

@ -1,8 +1,7 @@
<script>
import { config } from './config.js';
export let url;
export let endpoint;
let video_info = {};
let status = {};
let statusBadge = {
@ -11,9 +10,9 @@
3: {"class": "badge bg-error", "text": "Error"}
};
let download_path = "#";
async function startDownload() {
const res = await fetch(`${config.endpoint}/download?url=${url}`);
const res = await fetch(`${endpoint}/download?url=${url}`);
video_info = await res.json();
if (res.ok) {
@ -25,12 +24,12 @@
}
async function getStatus() {
const res = await fetch(`${config.endpoint}/status?url=${url}`);
const res = await fetch(`${endpoint}/status?url=${url}`);
status = await res.json();
if (res.ok) {
if (status.Id) {
download_path = `${config.endpoint}/data/${status.Id}`;
download_path = `${endpoint}/data/${status.Id}`;
}
return status;
} else {

View file

@ -1,13 +1,15 @@
<script>
import { tasks } from './stores.js';
import Task from './Task.svelte';
export let endpoint;
</script>
{#if $tasks.length > 0}
<div class="mt-4">
<ul class="list-group">
{#each $tasks as task (task.url)}
<Task url={task.url}/>
<Task url={task.url} endpoint={endpoint}/>
{/each}
</ul>
</div>