This commit is contained in:
Kieran 2023-01-03 22:24:53 +00:00
parent 8e783b0eb6
commit 455cdc4bf0
Signed by: Kieran
GPG Key ID: DE71CEB3925BE941
2 changed files with 48 additions and 42 deletions

View File

@ -111,27 +111,31 @@ export default function Note(props) {
if (typeof f === "string") { if (typeof f === "string") {
return f.split(UrlRegex).map(a => { return f.split(UrlRegex).map(a => {
if (a.startsWith("http")) { if (a.startsWith("http")) {
let url = new URL(a); try {
let ext = url.pathname.toLowerCase().match(FileExtensionRegex); let url = new URL(a);
if (ext) { let ext = url.pathname.toLowerCase().match(FileExtensionRegex);
switch (ext[1]) { if (ext) {
case "gif": switch (ext[1]) {
case "jpg": case "gif":
case "jpeg": case "jpg":
case "png": case "jpeg":
case "bmp": case "png":
case "webp": { case "bmp":
return <img key={url} src={url} />; case "webp": {
} return <img key={url} src={url} />;
case "mp4": }
case "mkv": case "mp4":
case "avi": case "mkv":
case "m4v": { case "avi":
return <video key={url} src={url} controls /> case "m4v": {
return <video key={url} src={url} controls />
}
} }
} else {
return <a href={url}>{url.toString()}</a>
} }
} else { } catch (e) {
return <a href={url}>{url.toString()}</a> console.warn(`Not a valid url: ${a}`);
} }
} }
return a; return a;

View File

@ -43,29 +43,31 @@ export default class Connection {
} }
OnMessage(e) { OnMessage(e) {
let msg = JSON.parse(e.data); if (e.data.length > 0) {
let tag = msg[0]; let msg = JSON.parse(e.data);
switch (tag) { let tag = msg[0];
case "EVENT": { switch (tag) {
this._OnEvent(msg[1], msg[2]); case "EVENT": {
break; this._OnEvent(msg[1], msg[2]);
} break;
case "EOSE": { }
this._OnEnd(msg[1]); case "EOSE": {
break; this._OnEnd(msg[1]);
} break;
case "OK": { }
// feedback to broadcast call case "OK": {
console.debug("OK: ", msg[1]); // feedback to broadcast call
break; console.debug("OK: ", msg[1]);
} break;
case "NOTICE": { }
console.warn(`[${this.Address}] NOTICE: ${msg[1]}`); case "NOTICE": {
break; console.warn(`[${this.Address}] NOTICE: ${msg[1]}`);
} break;
default: { }
console.warn(`Unknown tag: ${tag}`); default: {
break; console.warn(`Unknown tag: ${tag}`);
break;
}
} }
} }
} }