Skip to content

Commit b225c5e

Browse files
authored
Settings Panel + IPFS Improvements (#157)
* settings ui: - add new settings ui, currently used to set ipfs settings - add option to set custom daemon url and custom gateway url, via settings - settings saved in localStorage * ipfs - more accurate progress updates, including total - update to [email protected], auto-js-ipfs 2.1.1, replaywebpage - cleanup: unify ipfs opts in single ipfsOpts objects, rebuild * ci: update to macos-11 * bump to 0.10.0
1 parent bdcd383 commit b225c5e

File tree

9 files changed

+440
-276
lines changed

9 files changed

+440
-276
lines changed

.github/workflows/buildapp.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ jobs:
88

99
strategy:
1010
matrix:
11-
os: [macos-10.15, ubuntu-latest]
11+
os: [macos-11, ubuntu-latest]
1212
platform: [windows, linux]
1313
exclude:
14-
- os: macos-10.15
14+
- os: macos-11
1515
platform: windows
1616

1717
steps:

dist/embed/replay/sw.js

Lines changed: 11 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/embed/ui.js

Lines changed: 177 additions & 108 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
11
{
22
"name": "@webrecorder/archivewebpage",
33
"productName": "ArchiveWeb.page",
4-
"version": "0.9.8",
4+
"version": "0.10.0",
55
"main": "index.js",
66
"description": "Create Web Archives directly in your browser",
77
"repository": "https://github.com/webrecorder/archiveweb.page",
88
"author": "Webrecorder Software",
99
"license": "AGPL-3.0-or-later",
1010
"dependencies": {
1111
"@fortawesome/fontawesome-free": "^5.13.0",
12-
"@ipld/car": "^5.0.1",
13-
"@ipld/unixfs": "^2.0.0",
14-
"@webrecorder/awp-sw": "^0.2.2",
15-
"@webrecorder/wabac": "^2.15.3",
16-
"auto-js-ipfs": "^2.1.0",
17-
"browsertrix-behaviors": "^0.4.1",
12+
"@webrecorder/awp-sw": "^0.3.0",
13+
"@webrecorder/wabac": "^2.16.1",
14+
"auto-js-ipfs": "^2.3.0",
15+
"browsertrix-behaviors": "^0.5.0",
1816
"btoa": "^1.2.1",
1917
"bulma": "^0.9.3",
2018
"client-zip": "^2.2.2",
@@ -23,13 +21,12 @@
2321
"keyword-mark-element": "^0.1.2",
2422
"multiformats": "^10.0.2",
2523
"node-fetch": "2.6.7",
26-
"p-queue": "^7.3.0",
2724
"pretty-bytes": "^5.6.0",
28-
"replaywebpage": "^1.7.13",
25+
"replaywebpage": "^1.8.1",
2926
"stream-browserify": "^3.0.0",
3027
"unused-filename": "^4.0.1",
3128
"uuid": "^8.3.2",
32-
"warcio": "^2.0.1"
29+
"warcio": "^2.1.0"
3330
},
3431
"devDependencies": {
3532
"copy-webpack-plugin": "^9.0.1",

src/ui/app.js

Lines changed: 111 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import fasHelp from "@fortawesome/fontawesome-free/svgs/solid/question-circle.sv
77
import fasPlus from "@fortawesome/fontawesome-free/svgs/solid/plus.svg";
88

99
import fasUpload from "@fortawesome/fontawesome-free/svgs/solid/upload.svg";
10-
//import fasCog from "@fortawesome/fontawesome-free/svgs/solid/cog.svg";
10+
import fasCog from "@fortawesome/fontawesome-free/svgs/solid/cog.svg";
1111

1212
import "./coll";
1313
import "./coll-info";
@@ -25,6 +25,8 @@ import { getLocalOption, setLocalOption } from "../localstorage";
2525
// eslint-disable-next-line no-undef
2626
const VERSION = __AWP_VERSION__;
2727

28+
const DEFAULT_GATEWAY_URL = "https://w3s.link/ipfs/";
29+
2830

2931
//============================================================================
3032
class ArchiveWebApp extends ReplayWebApp
@@ -36,6 +38,15 @@ class ArchiveWebApp extends ReplayWebApp
3638
this.showCollDrop = false;
3739
this.colls = [];
3840
this.autorun = false;
41+
42+
try {
43+
const res = localStorage.getItem("ipfsOpts");
44+
this.ipfsOpts = JSON.parse(res);
45+
} catch (e) {
46+
}
47+
48+
this.ipfsOpts = this.ipfsOpts || {daemonUrl: "", message: "", useCustom: false, gatewayUrl: DEFAULT_GATEWAY_URL};
49+
3950
getLocalOption("autorunBehaviors").then((res) => this.autorun = res === "1");
4051

4152
if (window.archivewebpage) {
@@ -68,7 +79,9 @@ class ArchiveWebApp extends ReplayWebApp
6879
showDownloadProgress: { type: Boolean },
6980
download: { type: Object },
7081

71-
ipfsDaemonUrl: { type: String }
82+
ipfsOpts: { type: Object },
83+
84+
showSettings: {type: Boolean }
7285
};
7386
}
7487

@@ -85,7 +98,9 @@ class ArchiveWebApp extends ReplayWebApp
8598
this.sourceUrl = pageParams.get("source") || "";
8699
}
87100

88-
this.checkIPFS();
101+
if (!this.embed) {
102+
this.checkIPFS();
103+
}
89104
}
90105

91106
handleMessages() {
@@ -217,8 +232,13 @@ class ArchiveWebApp extends ReplayWebApp
217232
}
218233
219234
.infomsg {
220-
margin-left: auto;
221235
max-width: 300px;
236+
padding-right: 8px;
237+
}
238+
239+
.rightbar {
240+
margin-left: auto;
241+
display: flex;
222242
}
223243
224244
.dl-progress {
@@ -287,7 +307,12 @@ class ArchiveWebApp extends ReplayWebApp
287307
</span>
288308
<span class="is-hidden-mobile">Start Recording...</span>
289309
</button>
290-
<div class="infomsg is-hidden-mobile">The ArchiveWeb.page ${IS_APP ? "App" : "Extension"} allows you to create web archives directly in your browser!</div>
310+
<div class="rightbar">
311+
<div class="infomsg is-hidden-mobile">The ArchiveWeb.page ${IS_APP ? "App" : "Extension"} allows you to create web archives directly in your browser!</div>
312+
<button class="button is-small" @click="${() => this.showSettings = true}">
313+
<fa-icon .svg=${fasCog}></fa-icon>
314+
</button>
315+
</div>
291316
</div>
292317
</div>
293318
</div>
@@ -296,8 +321,7 @@ class ArchiveWebApp extends ReplayWebApp
296321
<wr-rec-coll-index
297322
dateName="Date Created"
298323
headerName="Current Web Archives"
299-
.ipfsDaemonUrl=${this.ipfsDaemonUrl}
300-
.ipfsMessage=${this.ipfsMessage}
324+
.ipfsOpts=${this.ipfsOpts}
301325
@show-start=${this.onShowStart}
302326
@show-import=${this.onShowImport}
303327
@colls-updated=${this.onCollsLoaded}
@@ -313,6 +337,7 @@ class ArchiveWebApp extends ReplayWebApp
313337
${this.showNew ? this.renderNewCollModal() : ""}
314338
${this.showImport ? this.renderImportModal() : ""}
315339
${this.showDownloadProgress && this.download ? this.renderDownloadModal() : ""}
340+
${this.showSettings ? this.renderSettingsModal() : ""}
316341
${super.render()}`;
317342
}
318343

@@ -325,8 +350,7 @@ class ArchiveWebApp extends ReplayWebApp
325350
.loadInfo="${this.getLoadInfo(this.sourceUrl)}"
326351
.appLogo="${this.mainLogo}"
327352
.autoUpdateInterval=${this.embed || this.showDownloadProgress ? 0 : 10}
328-
.ipfsDaemonUrl=${this.ipfsDaemonUrl}
329-
.ipfsMessage=${this.ipfsMessage}
353+
.ipfsOpts=${this.ipfsOpts}
330354
embed="${this.embed}"
331355
sourceUrl="${this.sourceUrl}"
332356
appName="${this.appName}"
@@ -562,6 +586,35 @@ class ArchiveWebApp extends ReplayWebApp
562586
</div>`;
563587
}
564588

589+
renderSettingsModal() {
590+
return html`
591+
<wr-modal @modal-closed="${() => this.showSettings = false}" title="Settings">
592+
<form class="is-flex is-flex-direction-column" @submit="${this.onSaveSettings}">
593+
<div class="field has-addons">
594+
<p class="control is-expanded">
595+
IPFS Daemon URL (leave blank to auto-detect IPFS):
596+
<input class="input" type="url"
597+
name="ipfsDaemonUrl" id="ipfsDaemonUrl" value="${this.ipfsOpts.daemonUrl}"
598+
placeholder="Set IPFS Daemon URL or set blank to auto-detect IPFS">
599+
</p>
600+
</div>
601+
<div class="field has-addons">
602+
<p class="control is-expanded">
603+
IPFS Gateway URL:
604+
<input class="input" type="url"
605+
name="ipfsGatewayUrl" id="ipfsGatewayUrl" value="${this.ipfsOpts.gatewayUrl}"
606+
placeholder="${DEFAULT_GATEWAY_URL}">
607+
</p>
608+
</div>
609+
<div class="has-text-centered">
610+
<button class="button is-primary" type="submit">Save</button>
611+
<button class="button" type="button" @click="${() => this.showSettings = false}">Close</button>
612+
</div>
613+
</form>
614+
</wr-modal>
615+
`;
616+
}
617+
565618
async onNewColl(event) {
566619
this.showNew = "loading";
567620
event.preventDefault();
@@ -675,43 +728,72 @@ class ArchiveWebApp extends ReplayWebApp
675728
}
676729
}
677730

731+
async onSaveSettings(event) {
732+
event.preventDefault();
733+
this.showSettings = false;
734+
735+
const daemonUrlText = this.renderRoot.querySelector("#ipfsDaemonUrl");
736+
const gatewayUrlText = this.renderRoot.querySelector("#ipfsGatewayUrl");
737+
738+
if (!daemonUrlText || !gatewayUrlText) {
739+
return;
740+
}
741+
742+
const daemonUrl = daemonUrlText.value;
743+
const gatewayUrl = gatewayUrlText.value;
744+
745+
//const method = "POST";
746+
747+
//const body = JSON.stringify({daemonUrl});
748+
749+
//const resp = await fetch(`${apiPrefix}/ipfs/daemonUrl`, {method, body});
750+
751+
this.ipfsOpts = {
752+
daemonUrl, useCustom: !!daemonUrl, gatewayUrl
753+
};
754+
755+
await this.checkIPFS();
756+
757+
localStorage.setItem("ipfsOpts", JSON.stringify(this.ipfsOpts));
758+
759+
return false;
760+
}
761+
678762
async checkIPFS() {
763+
const ipfsOpts = this.ipfsOpts;
764+
679765
// use auto-js-ipfs to get possible local daemon url (eg. for Brave)
680766
// if so, send it to the service worker
767+
if (ipfsOpts.useCustom && ipfsOpts.daemonUrl) {
768+
ipfsOpts.message = "IPFS Access -- Custom IPFS Daemon";
769+
return;
770+
}
681771

682-
let ipfsDaemonUrl = sessionStorage.getItem("ipfsDaemonUrl");
683-
let ipfsMessage = sessionStorage.getItem("ipfsMessage");
684-
685-
if (ipfsDaemonUrl === null) {
772+
if (!ipfsOpts.daemonUrl) {
686773
// eslint-disable-next-line no-undef
687774
const autoipfs = await createAutoIpfs({web3StorageToken: __WEB3_STORAGE_TOKEN__});
688775

689776
if (autoipfs instanceof DaemonAPI) {
690-
ipfsDaemonUrl = autoipfs.url;
777+
ipfsOpts.daemonUrl = autoipfs.url;
691778
}
692779

780+
ipfsOpts.useCustom = false;
781+
693782
if (autoipfs instanceof Web3StorageAPI) {
694-
ipfsMessage = "Sharing via remote web3.storage";
695-
} else if (!ipfsDaemonUrl) {
696-
ipfsMessage = "IPFS Access Unknown - Sharing Not Available";
697-
} else if (ipfsDaemonUrl.startsWith("http://localhost:45")) {
698-
ipfsMessage = "Sharing via Brave IPFS node";
699-
} else if (ipfsDaemonUrl.startsWith("http://localhost")) {
700-
ipfsMessage = "Sharing via local IPFS node";
783+
ipfsOpts.message = "Sharing via remote web3.storage";
784+
} else if (!ipfsOpts.daemonUrl) {
785+
ipfsOpts.message = "IPFS Access Unknown - Sharing Not Available";
786+
} else if (ipfsOpts.daemonUrl.startsWith("http://localhost:45")) {
787+
ipfsOpts.message = "Sharing via Brave IPFS node";
788+
} else if (ipfsOpts.daemonUrl.startsWith("http://localhost")) {
789+
ipfsOpts.message = "Sharing via local IPFS node";
701790
} else {
702-
ipfsMessage = "";
791+
ipfsOpts.message = "";
703792
}
704-
705-
sessionStorage.setItem("ipfsDaemonUrl", ipfsDaemonUrl);
706-
sessionStorage.setItem("ipfsMessage", ipfsMessage);
707793
}
708-
709-
this.ipfsDaemonUrl = ipfsDaemonUrl;
710-
this.ipfsMessage = ipfsMessage;
711794
}
712795
}
713796

714-
715797
customElements.define("archive-web-page-app", ArchiveWebApp);
716798

717799
export { ArchiveWebApp, Loader, Embed };

src/ui/coll-index.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,7 @@ class WrRecCollIndex extends CollIndex
5757
...CollIndex.properties,
5858

5959
deleteConfirm: { type: Object },
60-
ipfsDaemonUrl: { type: String },
61-
ipfsMessage: { type: String }
60+
ipfsOpts: { type: Object },
6261
};
6362
}
6463

@@ -67,8 +66,7 @@ class WrRecCollIndex extends CollIndex
6766
<wr-rec-coll-info
6867
style="overflow: visible" data-coll="${coll.id}"
6968
.coll=${coll}
70-
.ipfsDaemonUrl=${this.ipfsDaemonUrl}
71-
.ipfsMessage=${this.ipfsMessage}
69+
.ipfsOpts=${this.ipfsOpts}
7270
@ipfs-share="${this.onIpfsShare}">
7371
</wr-rec-coll-info>`;
7472
}

0 commit comments

Comments
 (0)