Browse Source

Merging in changes from ljsthw but some of the merge is really messed up with deletes I didn't intend.

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

15
api/admin/email.js

@ -1,6 +1,5 @@
import logging from '../../lib/logging.js';
import assert from 'assert';
import { API } from '../../lib/api.js';
import { developer_admin, API } from '../../lib/api.js';
import { company } from '../../emails/config.js';
import { get_config, dns_check, send_email, load_templates } from '../../lib/email.js';
@ -100,6 +99,10 @@ export const get = async (req, res) => {
const rules = { domain_name: "required"}
const form = api.validate(rules);
if(!api.admin_authenticated) {
return api.error(401, "Admin rights required.");
}
try {
if(form._valid) {
const dns = await dns_check(form.domain_name);
@ -116,6 +119,8 @@ export const get = async (req, res) => {
}
}
get.authenticated = !developer_admin;
const send_test = async (email) => {
try {
const test_email = await load_templates("test");
@ -138,6 +143,10 @@ export const post = async (req, res) => {
const rules = { to_address: "required|email" }
const api = new API(req, res);
if(!api.admin_authenticated) {
return api.error(401, "Admin rights required.");
}
try {
const form = api.validate(rules);
@ -158,3 +167,5 @@ export const post = async (req, res) => {
return api.error(500, error.message || "Internal Server Error");
}
}
post.authenticated = !developer_admin;

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);
}

14
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>
@ -128,8 +129,8 @@
<style>
panel {
position: absolute;
top: var(--fixed-header-height);
position: fixed;
top: 0;
left: 0;
right: 0;
padding: 0;
@ -137,6 +138,7 @@
border: 3px solid var(--color-accent);
display: flex;
flex-direction: row;
z-index: 100000;
}
panel description {
@ -225,7 +227,7 @@
<Icon name="x" />
</span>
<span on:click={ () => search_icons() }><Icon name="feather" /></span>
<a href="/bando/components/" use:link on:click={ () => shown = !shown }><Icon name="tool" /></a>
<a href="/client/#/bando/components/" target="_" on:click={ () => shown = !shown }><Icon name="tool" /></a>
</buttons>
<h1>Tables</h1>

8
client/bando/Components.svelte

@ -44,7 +44,7 @@
import AspectRatio from "./demos/AspectRatio.svelte";
import Layout from "../Layout.svelte";
import { link, push } from "svelte-spa-router";
import { link, replace } from "svelte-spa-router";
export let params = {};
@ -107,10 +107,6 @@
selected.active = true;
let show = "DEMO";
$: if(params.name != selected.title) {
push(`/bando/components/${params.name}/`);
}
const load_docs = async (from) => {
const res = await fetch(`${from.code}.md`);
return res.status == 200 ? res.text() : undefined;
@ -127,7 +123,7 @@
return x;
});
push(`/bando/components/${selected.title}/`);
replace(`/bando/components/${selected.title}/`);
}
</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',

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);
}
}

1
scripts/deploy.sh

@ -4,7 +4,6 @@ set -xe
# quick deploy hack script
mkdir -p /tmp/build
mkdir -p debug/errors/
npm run build
rsync -rv -T /tmp/build/ public/* /var/www/zedshaw.games/
find /var/www/zedshaw.games/ -name "*.js" -exec gzip -9f {} \;

4
tests/ui/login.js

@ -47,10 +47,10 @@ test('standalone login page works', async (t) => {
await p.fill("#password", user.password);
await p.click(tid('login-button'));
await sleep(1000);
await wait(p, tid('clips-home-page'));
await wait(p, tid('home-page'));
// confirm home page and logout-link are visible
await expect(t, p, tid('clips-home-page'));
await expect(t, p, tid('home-page'));
await expect(t, p, tid('logout-link'));
// logout and see login to chat

Loading…
Cancel
Save