Browse Source

Remove uses of console.log and use a configurable internal library that allows us to disable debug messages and such.

master
Zed A. Shaw 1 week ago
parent
commit
9a26d4ef39
  1. 11
      client/api.js
  2. 5
      client/assert.js
  3. 7
      client/bando/Bandolier.svelte
  4. 5
      client/bando/Djenterator.svelte
  5. 4
      client/bando/IconFinder.svelte
  6. 3
      client/bando/demos/Accordion.svelte
  7. 6
      client/bando/demos/Carousel.svelte
  8. 9
      client/bando/demos/DataTable.svelte
  9. 11
      client/bando/demos/FairPay.svelte
  10. 4
      client/bando/demos/Icon.svelte
  11. 4
      client/bando/demos/Tabs.svelte
  12. 7
      client/components/BTCPay.svelte
  13. 3
      client/components/Chat.svelte
  14. 15
      client/components/HLSVideo.svelte
  15. 9
      client/components/LoggedIn.svelte
  16. 4
      client/components/Login.svelte
  17. 3
      client/components/Modal.svelte
  18. 7
      client/components/Paypal.svelte
  19. 15
      client/components/Video.svelte
  20. 7
      client/components/WTVideo.svelte
  21. 5
      client/fsm.js
  22. 6
      client/helpers.js
  23. 41
      client/logging.js
  24. 2
      client/pages/Login.svelte
  25. 9
      client/pages/Purchase.svelte
  26. 3
      client/pages/Unsubscribe.svelte
  27. 3
      client/pages/admin/ReadUpdate.svelte
  28. 4
      client/pages/admin/Tests.svelte
  29. 27
      client/wt.js

11
client/api.js

@ -1,6 +1,7 @@
const MOCK_ROUTES = {};
import { user } from "./stores.js";
import { log } from "$/client/logging.js";
import Validator from 'Validator';
export const validate = (form, extra) => {
@ -50,7 +51,7 @@ export const raw_mock = (url, raw_method, body, unauthed_action) => {
}
if(error) {
console.error(error, MOCK_ROUTES);
log.error(error, MOCK_ROUTES);
return [500, {message: error}];
} else {
// this is the same as res.status below
@ -78,7 +79,7 @@ export const raw = async (url, method, body, unauthed_action) => {
const res = validate(body);
if(!can_submit(res)) {
console.log("Form invalid, won't HTTP submit.");
log.debug("Form invalid, won't HTTP submit.");
return [400, res];
} else {
clean_form(body);
@ -112,8 +113,8 @@ export const raw = async (url, method, body, unauthed_action) => {
return [res.status, JSON.parse(text)];
} catch(error) {
console.error(error, "Failed to parse reply body as JSON. Text is:", text, "error", error, "URL", url);
return [500, {"message": "Exception processing request. See console log."}];
log.error(error, "Failed to parse reply body as JSON. Text is:", text, "error", error, "URL", url);
return [500, {"message": "Exception processing request. See log.debug."}];
}
}
}
@ -144,7 +145,7 @@ export const logout_user = async () => {
});
let [status, data] = await get('/api/logout');
if(status !== 200) console.error("Invalid status from logout", status, data);
if(status !== 200) log.error("Invalid status from logout", status, data);
window.location.replace("/client/#/login");
}

5
client/assert.js

@ -1,3 +1,5 @@
import { log } from "./logging.js";
/* I can't believe I have to write this just so I can use the assert that should be standard in every javascript. */
class AssertionError extends Error {
@ -23,7 +25,8 @@ class AssertionError extends Error {
}
const assert = (test, message) => {
console.assert(test, message);
log.assert(test, message);
if(!test) {
throw new AssertionError(message);
}

7
client/bando/Bandolier.svelte

@ -6,6 +6,7 @@
import { onMount } from 'svelte';
import { fade } from "svelte/transition";
import api from '$/client/api.js';
import { log } from "$/client/logging.js";
// this is a unique string that you can grep for to make sure bando isn't in your build
const canary = '3a025dba-1a62-4169-ae9f-f7cd4104c4f4';
@ -51,14 +52,14 @@
socket_register = data.sockets;
errors = data.errors;
} else {
console.log("failed to get info", status);
log.debug("failed to get info", status);
}
[status, data] = await api.get('/api/devtools/djenterator');
if(status == 200) {
djenterators = data;
} else {
console.log("failed to load generators", status);
log.debug("failed to load generators", status);
}
}
@ -119,7 +120,7 @@
});
}
console.log("Canary is compiled into build as", canary);
log.debug("Canary is compiled into build as", canary);
onMount(() => rephresh());
</script>

5
client/bando/Djenterator.svelte

@ -2,6 +2,7 @@
import template from "lodash/template";
import { fade } from "svelte/transition";
import Icon from "$/client/components/Icon.svelte";
import { log } from "$/client/logging.js";
export let template_file = "";
@ -56,7 +57,7 @@
renderer._template = template_name;
render_template();
} catch(error) {
console.error(error);
log.error(error);
notice = `${error.message}`;
results = source;
}
@ -84,7 +85,7 @@
}
const canary = '3a025dba-1a62-4169-ae9f-f7cd4104c4f4';
console.log("Canary is compiled into build as", canary);
log.debug("Canary is compiled into build as", canary);
$: if(variable_json) render_template();

4
client/bando/IconFinder.svelte

@ -1,7 +1,9 @@
<script>
import Icon from "$/client/components/Icon.svelte";
import { onMount } from "svelte";
import { log } from "$/client/logging.js";
import api from "$/client/api.js";
let all_icons = [];
let inactive = false;
let icons = [];
@ -35,7 +37,7 @@
icons = data;
all_icons = icons;
} else {
console.error("Invalid response", status, data);
log.error("Invalid response", status, data);
}
});
</script>

3
client/bando/demos/Accordion.svelte

@ -3,6 +3,7 @@
import Calendar from "./Calendar.svelte";
import Cards from "./Cards.svelte";
import Login from "./Login.svelte";
import { log } from "$/client/logging.js";
export let panels = [
{title: "Calendar", active: true, icon: "calendar", component: Calendar},
@ -13,7 +14,7 @@
let selected = panels[0];
const tab_select = (event) => {
console.log("SELECTED TAB", event.detail);
log.debug("SELECTED TAB", event.detail);
}
</script>

6
client/bando/demos/Carousel.svelte

@ -1,9 +1,10 @@
<script>
import Carousel from "$/client/components/Carousel.svelte";
import IconImage from "$/client/components/IconImage.svelte";
import { log } from "$/client/logging.js";
export let panels = [
{caption: "Anchors Away", active: true, component: IconImage,
{caption: "Anchors Away", active: true, component: IconImage,
props: { name: "anchor", hue: "red", background_hue: "green" } },
{caption: "Money Money Money", active: false, component: IconImage,
props: { name: "dollar-sign", hue: "blue", background_hue: "purple", pattern: "triangles-sm" } },
@ -15,11 +16,10 @@
const tab_select = (event) => {
// this is where you can grab selection information
console.log("SELECTED TAB", event.detail);
log.debug("SELECTED TAB", event.detail);
}
</script>
<Carousel panels={ panels } on:select={ tab_select } bind:selected />
<h3>You're looking at the {selected.caption} panel which has a {selected.props.name} icon.</h3>

9
client/bando/demos/DataTable.svelte

@ -2,6 +2,7 @@
import DataTable from "$/client/components/DataTable.svelte";
import Icon from "$/client/components/Icon.svelte";
import { link } from 'svelte-spa-router';
import { log } from "$/client/logging.js";
let rows = [
{_url: "/", id: 1, name: "Zed", age: 100, eyes: "Blue", hair: "Bald"},
@ -32,21 +33,21 @@
let pagination = { currentPage: 1, lastPage: 1 }
const full_query = async (event) => {
console.log("QUERY", event.detail);
log.debug("QUERY", event.detail);
}
const search_query = async (event) => {
let search_text = event.detail;
console.log("SEARCH", search_text);
log.debug("SEARCH", search_text);
}
const clear_search = async (event) => {
console.log("CLEAR", event.detail);
log.debug("CLEAR", event.detail);
}
const cell_click = (event) => {
console.log("CELL", event.detail);
log.debug("CELL", event.detail);
}
</script>

11
client/bando/demos/FairPay.svelte

@ -10,6 +10,7 @@
import BTCPay from "$/client/components/BTCPay.svelte";
import Layout from "$/client/Layout.svelte";
import { fake_payments } from "$/client/config.js";
import { log } from "$/client/logging.js";
const quips = {
"0": "Awww, really? Alright then.",
@ -45,12 +46,12 @@
const payment_finished = (event) => {
const { system, status } = event.detail;
console.assert(status === "complete", "Payment status should be complete with finished event", system, event.detail);
log.assert(status === "complete", "Payment status should be complete with finished event", system, event.detail);
paid_in_full = true;
}
const payment_canceled = (event) => {
console.log("CANCELED", event);
log.debug("CANCELED", event);
}
const payment_error = () => {
@ -58,7 +59,7 @@
}
const payment_loading = (event) => {
console.log("LOADING", event);
log.debug("LOADING", event);
}
const pay_nothing = async () => {
@ -68,7 +69,7 @@
if(status === 200) {
paid_in_full = true;
} else {
console.error("status", status, "data", data);
log.error("status", status, "data", data);
payment_failed = true;
form._errors.main = data.message || data.error || "Payment Error.";
}
@ -81,7 +82,7 @@
if(status === 200 && data.paid === true) {
paid_in_full = true;
} else {
console.log("GET to /api/user/payments returned", status, data);
log.debug("GET to /api/user/payments returned", status, data);
}
}

4
client/bando/demos/Icon.svelte

@ -2,6 +2,8 @@
import Icon from "$/client/components/Icon.svelte";
import { onMount } from "svelte";
import api from "$/client/api.js";
import { log } from "$/client/logging.js";
let all_icons = [];
let inactive = false;
let icons = [];
@ -34,7 +36,7 @@
icons = data;
all_icons = icons;
} else {
console.error("Invalid response", status, data);
log.error("Invalid response", status, data);
}
});
</script>

4
client/bando/demos/Tabs.svelte

@ -3,6 +3,7 @@
import Calendar from "./Calendar.svelte";
import Cards from "./Cards.svelte";
import Login from "./Login.svelte";
import { log } from "$/client/logging.js";
export let panels = [
{title: "Calendar", active: true, icon: "calendar", component: Calendar},
@ -13,10 +14,9 @@
let selected = panels[0];
const tab_select = (event) => {
console.log("SELECTED TAB", event.detail);
log.debug("SELECTED TAB", event.detail);
}
</script>
<Tabs panels={ panels } on:select={ tab_select } bind:selected />

7
client/components/BTCPay.svelte

@ -14,6 +14,7 @@
const dispatch = createEventDispatcher();
import Spinner from './Spinner.svelte';
import { fake_payments, product, btcpay_url } from '$/client/config.js';
import { log } from "$/client/logging.js";
export let amount = product.price;
export let disabled = false;
@ -21,13 +22,13 @@
let internal_id = "";
const btcpay_enter = (what) => {
console.log("btcpay_enter", what);
log.debug("btcpay_enter", what);
loading_btc = false;
dispatch('loading', {});
}
const btcpay_leave = async (what) => {
console.log("btcpay_leave", what);
log.debug("btcpay_leave", what);
loading_btc = false;
const resp = await fetch('/api/payments/btcpay', {
method: 'POST',
@ -57,7 +58,7 @@
if(fake_payments) {
// do a fake thing just to work on the UI
console.log("fake_payments set, sending finished event");
log.debug("fake_payments set, sending finished event");
dispatch('finished', { system: 'btcpay', invoice_id: 'FAKE', sys_primary_id: 11234, status: 'complete'});
} else if(sys_primary_id) {
// already have an invoice going so just open it again

3
client/components/Chat.svelte

@ -4,6 +4,7 @@
import { fade } from 'svelte/transition';
import Login from './Login.svelte';
import Modal from './Modal.svelte';
import { log } from "$/client/logging.js";
let admin_top = {initials: '@',
admin: true,
@ -34,7 +35,7 @@
}
afterUpdate(() => {
console.log("USER", $user);
log.debug("USER", $user);
let msg_scroll = document.getElementById('messages');
msg_scroll.scrollTop = msg_scroll.scrollHeight;
});

15
client/components/HLSVideo.svelte

@ -5,6 +5,7 @@
import Icon from '$/client/components/Icon.svelte';
import FSM from '$/client/fsm.js';
import assert from "$/client/assert.js";
import { log } from "$/client/logging.js";
export let aspect_ratio = "16/9";
export let source = "";
@ -50,7 +51,7 @@
* return HLS_ERROR if there's a problem.
*/
const recover_hls = (state) => {
console.log("HLS error", video_config.hls_error_type, "in state", state);
log.debug("HLS error", video_config.hls_error_type, "in state", state);
switch(video_config.hls_error_type) {
case Hls.ErrorTypes.NETWORK_ERROR:
hls.startLoad();
@ -59,7 +60,7 @@
hls.recoverMediaError();
return state;
default:
console.log("HLS error is unknown type");
log.debug("HLS error is unknown type");
hls.destroy();
return "HLS_ERROR";
}
@ -95,16 +96,16 @@
hls = new Hls();
hls.attachMedia(video);
hls.on(Hls.Events.MEDIA_ATTACHED, () => {
console.log("HLS MEDIA_ATTACHED event start.");
log.debug("HLS MEDIA_ATTACHED event start.");
hls.loadSource(source);
hls.on(Hls.Events.MANIFEST_PARSED,
async (event, details) => {
console.log("HLS MANIFEST_PARSED event start.");
log.debug("HLS MANIFEST_PARSED event start.");
await fsm.do("video_ready")
});
hls.on(Hls.Events.ERROR, async (event, error) => {
console.log("HLS ERROR event start.", error.type);
log.debug("HLS ERROR event start.", error.type);
video_config.hls_error_type = error.type;
await fsm.do("hls_error");
});
@ -179,7 +180,7 @@
case "VIDEO_READY":
return recover_hls(state);
default:
console.log("HLS error on state", state, "Not handled");
log.debug("HLS error on state", state, "Not handled");
return "ERROR";
}
}
@ -211,7 +212,7 @@
}
destroy(state) {
console.log("FSM: Destroying video on state", state);
log.debug("FSM: Destroying video on state", state);
if(hls) hls.destroy();
if(video_tag) this.clean_video();

9
client/components/LoggedIn.svelte

@ -3,6 +3,7 @@
import api from '$/client/api.js';
import { onMount } from "svelte";
import { push } from 'svelte-spa-router';
import { log } from "$/client/logging.js";
/* Set this to a URL to send them if they aren't logged in. */
export let redirect = false;
@ -15,7 +16,7 @@
onMount(async () => {
// there is a bug in svelte stores where directly using $user.authenticated
// will result in undefined always even though console.log($user) says it's true/false
// will result in undefined always even though log.debug($user) says it's true/false
authenticated = $user.authenticated;
if(authenticated === undefined) {
@ -28,7 +29,7 @@
$user.authenticated = true;
} else {
$user.authenticated = false;
console.log("LoginRequired: /api/login returned", status, "json", data);
log.debug("LoginRequired: /api/login returned", status, "json", data);
}
if(needs_redirect) {
@ -36,10 +37,10 @@
push(redirect);
}
} else if(redirect && !$user.authenticated) {
console.log("User not authenticated and redirection", redirect);
log.debug("User not authenticated and redirection", redirect);
push(redirect);
} else {
console.log("User authentication state", $user);
log.debug("User authentication state", $user);
}
});
</script>

4
client/components/Login.svelte

@ -1,10 +1,10 @@
<script>
import Validator from 'Validator';
import FormField from "./FormField.svelte";
import { user } from '$/client/stores';
import { createEventDispatcher } from 'svelte';
import api from '$/client/api.js';
import { log } from "$/client/logging.js";
let form = {
email: "",
@ -34,7 +34,7 @@
});
if(status === 200) {
console.log("Calling complete auth from authenticate");
log.debug("Calling complete auth from authenticate");
await complete_auth(data);
} else {
form._errors.main = "Invalid Login. Try again.";

3
client/components/Modal.svelte

@ -1,5 +1,6 @@
<script>
import { createEventDispatcher } from 'svelte';
import { log } from "$/client/logging.js";
export let active=true;
export let full_screen = false;
@ -7,7 +8,7 @@
// this doesn't seem to work on chrome
const escape_pressed = (event) => {
console.log("Key pressed", event.key);
log.debug("Key pressed", event.key);
if(event.key === 'Escape' || event.which === 27) {
dispatch('close');
}

7
client/components/Paypal.svelte

@ -10,6 +10,7 @@
import Icon from './Icon.svelte';
import { product, fake_payments, paypal_public } from '$/client/config.js';
import api from "$/client/api.js";
import { log } from "$/client/logging.js";
export let credit_card = false;
export let amount = product.amount;
@ -35,13 +36,13 @@
const [status, data] = await api.post('/api/payments/paypal', payment);
if(status == 200) {
console.log("Paypal request returned.");
log.debug("Paypal request returned.");
// TODO: confirm no errors on reply and the returned data matches
payment.internal_id = data.internal_id;
dispatch('finished', payment);
} else {
console.log("ERROR RESPONSE", status, data);
log.debug("ERROR RESPONSE", status, data);
dispatch("error", {message: "Validation error.", payment});
}
} else {
@ -106,7 +107,7 @@
if(disabled) return;
if(fake_payments) {
console.log("fake_payments set to true, sending error");
log.debug("fake_payments set to true, sending error");
dispatch("error", { system: "paypal", sys_primary_id: 11333, status: "complete", invoice_id: "FAKE" });
} else if(!window.paypal) {
let disable_funding = ['credit', 'bancontact',

15
client/components/Video.svelte

@ -6,6 +6,7 @@
import FSM from '$/client/fsm.js';
import assert from "$/client/assert.js";
import { video_config } from "$/client/stores.js";
import { log } from "$/client/logging.js";
export let aspect_ratio = "16/9";
export let source = "";
@ -43,7 +44,7 @@
* return HLS_ERROR if there's a problem.
*/
const recover_hls = (state) => {
console.log("HLS error", $video_config.hls_error_type, "in state", state);
log.debug("HLS error", $video_config.hls_error_type, "in state", state);
switch($video_config.hls_error_type) {
case Hls.ErrorTypes.NETWORK_ERROR:
hls.startLoad();
@ -52,7 +53,7 @@
hls.recoverMediaError();
return state;
default:
console.log("HLS error is unknown type");
log.debug("HLS error is unknown type");
hls.destroy();
return "HLS_ERROR";
}
@ -88,16 +89,16 @@
hls = new Hls();
hls.attachMedia(video);
hls.on(Hls.Events.MEDIA_ATTACHED, () => {
console.log("HLS MEDIA_ATTACHED event start.");
log.debug("HLS MEDIA_ATTACHED event start.");
hls.loadSource(source);
hls.on(Hls.Events.MANIFEST_PARSED,
async (event, details) => {
console.log("HLS MANIFEST_PARSED event start.");
log.debug("HLS MANIFEST_PARSED event start.");
await fsm.do("video_ready")
});
hls.on(Hls.Events.ERROR, async (event, error) => {
console.log("HLS ERROR event start.", error.type);
log.debug("HLS ERROR event start.", error.type);
$video_config.hls_error_type = error.type;
await fsm.do("hls_error");
});
@ -172,7 +173,7 @@
case "VIDEO_READY":
return recover_hls(state);
default:
console.log("HLS error on state", state, "Not handled");
log.debug("HLS error on state", state, "Not handled");
return "ERROR";
}
}
@ -197,7 +198,7 @@
}
destroy(state) {
console.log("Destroying video on state", state);
log.debug("Destroying video on state", state);
if(hls) hls.destroy();
clearInterval(poll_timer)
$video_config.video_ready = false;

7
client/components/WTVideo.svelte

@ -6,6 +6,7 @@
import { blur } from 'svelte/transition';
import Icon from './Icon.svelte';
import Spinner from './Spinner.svelte';
import { log } from "$/client/logging.js";
export let media;
// whether to add a download link to download the video
@ -54,12 +55,12 @@
}
wire(wire) {
console.log("wire", wire);
log.debug("wire", wire);
peers = this.torrent.numPeers;
}
noPeers(announceType) {
console.log("announce", announceType);
log.debug("announce", announceType);
peers = this.torrent.numPeers;
}
}
@ -79,7 +80,7 @@
loading_promise.resolve();
});
} else {
console.log("Failure loading torrent file.");
log.debug("Failure loading torrent file.");
}
}

5
client/fsm.js

@ -1,4 +1,5 @@
import assert from "./assert.js";
import { log } from "./logging.js";
export default class FSM {
@ -38,12 +39,12 @@ export default class FSM {
assert(next_state.length == 2, `Returning an array only allows 2 elements (state, func) but you returned ${next_state}`);
let [state, func] = next_state;
console.debug(`FSM ${this.events.constructor.name}: (${event}) = ${this.state} -> ${state} (${args})`, "DATA:", this.data, func ? `THEN ${func.name}()` : undefined);
log.debug(`FSM ${this.events.constructor.name}: (${event}) = ${this.state} -> ${state} (${args})`, "DATA:", this.data, func ? `THEN ${func.name}()` : undefined);
this.transition(state);
await func();
} else {
console.debug(`FSM ${this.events.constructor.name}: (${event}) = ${this.state} -> ${next_state} (${args})`, "DATA:", this.data);
log.debug(`FSM ${this.events.constructor.name}: (${event}) = ${this.state} -> ${next_state} (${args})`, "DATA:", this.data);
this.transition(next_state);
}

6
client/helpers.js

@ -1,3 +1,5 @@
import { log } from "./logging.js";
/* A simple function that uses the Crypto.getRandomValues to fill an
* array with 32 bit random numbers.
*/
@ -27,12 +29,12 @@ export const defer = (debug="") => {
let promise = new Promise((resolve, reject) => {
if(debug) {
res = (result) => {
console.log("resolved defer", debug);
log.debug("resolved defer", debug);
resolve(result);
}
rej = (error) => {
console.log("REJECT defer", debug);
log.debug("REJECT defer", debug);
reject(error);
}
} else {

41
client/logging.js

@ -0,0 +1,41 @@
import { log_levels } from "./config.js";
const disabled = () => {};
const bind_logging = () => {
// We have to do this because rendered pages will include
// client components but they don't have a window variable.
// We try to use window to bind, and if it doesn't work then
// just use the base function. One question? Why bind window?
try {
return {
debug: console.log.bind(window.console),
warn: console.warn.bind(window.console),
info: console.info.bind(window.console),
error: console.error.bind(window.console),
table: console.table.bind(window.console),
assert: console.assert.bind(window.console),
}
} catch(error) {
return {
debug: console.log,
warn: console.warn,
info: console.info,
error: console.error,
table: console.table,
assert: console.assert
}
}
}
const all_levels = bind_logging();
const as_entries = Object.entries(all_levels);
export const logger = (levels = log_levels) => {
return Object.fromEntries(as_entries.map(([level, logf]) => {
return levels.includes(level) ? [level, logf] : [level, disabled];
}));
}
// this is a default logger that's configured with what's in config.js:log_levels
export const log = logger();

2
client/pages/Login.svelte

@ -3,8 +3,10 @@
import Layout from '$/client/Layout.svelte';
import { user } from '$/client/stores.js';
import { push } from 'svelte-spa-router';
import { log } from "$/client/logging.js";
$: if($user.authenticated) {
log.debug("user is already authenticated");
push("/");
}

9
client/pages/Purchase.svelte

@ -9,6 +9,7 @@
import BTCPay from "$/client/components/BTCPay.svelte";
import Layout from "$/client/Layout.svelte";
import { fake_payments } from "$/client/config.js";
import { log } from "$/client/logging.js";
const quips = {
"0": "Awww, really? Alright then.",
@ -44,12 +45,12 @@
const payment_finished = (event) => {
const { system, status } = event.detail;
console.assert(status === "complete", "Payment status should be complete with finished event", system, event.detail);
log.assert(status === "complete", "Payment status should be complete with finished event", system, event.detail);
paid_in_full = true;
}
const payment_canceled = (event) => {
console.log("CANCELED", event);
log.debug("CANCELED", event);
}
const payment_error = () => {
@ -57,7 +58,7 @@
}
const payment_loading = (event) => {
console.log("LOADING", event);
log.debug("LOADING", event);
}
const pay_nothing = async () => {
@ -67,7 +68,7 @@
if(status === 200) {
paid_in_full = true;
} else {
console.error("status", status, "data", data);
log.error("status", status, "data", data);
payment_failed = true;
form._errors.main = data.message || data.error || "Payment Error.";
}

3
client/pages/Unsubscribe.svelte

@ -5,6 +5,7 @@
import api from "$/client/api.js";
import Spinner from "$/client/components/Spinner.svelte";
import { support_email } from "$/client/config.js";
import { log } from "$/client/logging.js";
export let params = {};
let success;
@ -12,7 +13,7 @@
onMount(async () => {
const [status, data] = await api.get(`/api/email?unsubkey=${params.unsubkey}`);
console.log("failed result is", status, data);
log.debug("failed result is", status, data);
if(status === 200) {
success = true;

3
client/pages/admin/ReadUpdate.svelte

@ -6,6 +6,7 @@
import Modal from "$/client/components/Modal.svelte";
import Form from "$/client/components/Form.svelte";
import api from "$/client/api.js";
import { log } from "$/client/logging.js";
let form_data = [];
let label_names = [];
@ -27,7 +28,7 @@
const update_record = async () => {
let [status, data] = await api.post(`/api/admin/table?name=${params.table}&row_id=${params.row_id}`, form_data);
console.log("update record results", data);
log.debug("update record results", data);
if(status == 200) {
notice = "Update successful.";

4
client/pages/admin/Tests.svelte

@ -4,6 +4,7 @@
import api from "$/client/api.js";
import assert from "$/client/assert.js";
import { random_numbers, defer } from "$/client/helpers.js";
import { log } from "$/client/logging.js";
// just get some random numbers to run that function
const r = random_numbers(2);
@ -27,7 +28,7 @@
try {
assert(status === 200, "Fake test call failed (it should).");
} catch(error) {
console.error(error, "Assert worked!");
log.error(error, "Assert worked!");
assert_promise.resolve("resolve-message");
}
});
@ -60,4 +61,3 @@
{/await}
</Layout>

27
client/wt.js

@ -1,6 +1,7 @@
const seedTimeout = 60000;
import { webtorrent, base_host } from '$/client/config.js';
import assert from "$/client/assert.js";
import { log } from "$/client/logging.js";
/* This needs an entire rewrite using the FSM code. Most of this is hacked on
* garbage that is unreliable at the best of times.
@ -21,8 +22,8 @@ const getClient = () => {
let client = new WebTorrent({dht: webtorrent.use_dht});
// would need to do some kind of global status for these since it's not per torrent
client.on('error', err => console.error(err));
client.on('listening', () => console.log('LISTENING:'));
client.on('error', err => log.error(err));
client.on('listening', () => log.debug('LISTENING:'));
LAZY_CLIENT = client;
return LAZY_CLIENT;
}
@ -45,7 +46,7 @@ export class WTEvents {
this.media.kind = 'video';
file.renderTo(`#${this.appendId}`, {autoplay: false, controls: true, muted: false});
file.getBlobURL((err, url) => {
if(err) console.error(err, "getBlobURL error videoReady");
if(err) log.error(err, "getBlobURL error videoReady");
this.download_available(url);
});
}
@ -54,7 +55,7 @@ export class WTEvents {
this.media.kind = 'audio';
file.renderTo(`#${this.appendId}`, {autoplay: false, controls: true, muted: true});
file.getBlobURL((err, url) => {
if(err) console.error(err, "getBlobURL error audioReady");
if(err) log.error(err, "getBlobURL error audioReady");
this.download_available(url);
});
}
@ -63,7 +64,7 @@ export class WTEvents {
file.renderTo(`#${this.appendId}`, (err, elem) => {
// TODO: hmmm do we need to do anything here with elem?
if(err) {
console.error(err);
log.error(err);
} else {
// keep this active for 60 second
let client = getClient();
@ -72,17 +73,17 @@ export class WTEvents {
});
file.getBlobURL((err, url) => {
if(err) console.error(err, "getBlobURL error");
if(err) log.error(err, "getBlobURL error");
this.download_available(url);
});
}
download_available(url) {
console.log("download url available");
log.debug("download url available");
}
done() {
console.log("done", this.media);
log.debug("done", this.media);
}
infoHash(hash) {
@ -98,11 +99,11 @@ export class WTEvents {
}
warning(msg) {
console.log("WT WARNING", msg);
log.debug("WT WARNING", msg);
}
error(msg) {
console.log("WT ERROR", msg);
log.debug("WT ERROR", msg);
}
download(bytes) {
@ -119,11 +120,11 @@ export class WTEvents {
}
noPeers(announceType) {
console.log('noPeers from', announceType);
log.debug('noPeers from', announceType);
}
client_error(err) {
console.error(err, "client error");
log.error(err, "client error");
return true;
}
}
@ -191,7 +192,7 @@ export const remove = (media) => {
if(media.torrent) {
getClient().remove(media.torrent);
} else {
console.error("remove called with a media object without a torrent", media);
log.error("remove called with a media object without a torrent", media);
}
}

Loading…
Cancel
Save