Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Syncthing configuration & REST API datasource #137

Draft
wants to merge 31 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
9b41cf8
fix(dev): :adhesive_bandage: small fixes
LBF38 Aug 25, 2023
567a811
feat(dev): :sparkles: add valibot to validate JSON parsing (#113)
LBF38 Aug 26, 2023
2202b2e
chore(esbuild): :wrench: update tsconfig
LBF38 Aug 26, 2023
e1f5004
refactor(dev): :fire: update getSystemStatus
LBF38 Aug 26, 2023
94f696b
fix(esbuild): :wrench: disable eslint and tsc on esbuild config
LBF38 Aug 26, 2023
2c36ecb
refactor(datasource): :recycle: update requestEndpoint to simplify calls
LBF38 Aug 26, 2023
11d9dd0
feat(datasource): :sparkles: add support for new endpoints
LBF38 Aug 26, 2023
41e7723
feat(ui): :sparkles: add restartRequired warning message
LBF38 Aug 27, 2023
2531583
feat(models): :safety_vest: update SyncthingConfiguration model
LBF38 Aug 27, 2023
a1ad40f
refactor(datasource): :recycle: update syncthing remote
LBF38 Oct 5, 2023
7afe116
refactor(datasource): :recycle: system_browse + system_connections
LBF38 Oct 5, 2023
44000be
refactor(datasource): :recycle: implement all systems endpoints
LBF38 Oct 8, 2023
cdccfc5
refactor(datasource): :recycle: stats endpoints
LBF38 Oct 8, 2023
826d72c
refactor(datasource): :recycle: update cluster endpoints
LBF38 Oct 8, 2023
22a3bb8
refactor(datasource): :recycle: update svc endpoints
LBF38 Oct 8, 2023
64c2b1c
refactor(datasource): :construction: update config endpoint
LBF38 Oct 9, 2023
895e5c6
refactor(datasource): :construction: update folder endpoints
LBF38 Oct 9, 2023
464784f
refactor(datasource): :recycle: update db endpoints
LBF38 Oct 9, 2023
c06a75b
feat(models): :sparkles: add all syncthing event types
LBF38 Oct 9, 2023
f2a5c14
refactor(datasource): :recycle: update events endpoints
LBF38 Oct 9, 2023
f9daa1d
refactor(ui): :construction: work on stores
LBF38 Oct 13, 2023
c2d9604
feat(dev): :sparkles: introduce testing bench for syncthing remote
LBF38 Dec 9, 2023
d6747a9
feat(dev): :hammer: add syncthing docker compose file
LBF38 Dec 9, 2023
3406a6a
refactor(syncthing): :recycle: update syncthing remote datasource
LBF38 Dec 11, 2023
bb26659
refactor(dev): :construction: update svelte component for st remote t…
LBF38 Dec 11, 2023
292b880
feat(dev): :construction: add xstate lib + examples
LBF38 Dec 15, 2023
ad1a67e
chore(dev): :wrench: update tsconfig
LBF38 Dec 16, 2023
43f4793
feat(datasource): :construction: add machine to fetch config
LBF38 Dec 16, 2023
a4c5256
feat(ui): :sparkles: add configuration modal using xstate machines
LBF38 Jan 7, 2024
ce7a607
chore(dev): :hammer: update git hook for commit msg
LBF38 Jan 7, 2024
506fa68
feat(ui): :recycle: update xstate machines for config table modal
LBF38 Jan 7, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules/

main.js
esbuild.config.mjs
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/*.code-snippets

# Intellij
*.iml
Expand Down
2 changes: 1 addition & 1 deletion .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

pnpx commitlint --edit "$1"
npx commitlint --edit "$1"
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"project",
"gh actions",
"release",
"mobile"
"mobile",
"datasource"
],
"markdownlint.config": {
"MD033": false,
Expand Down
26 changes: 26 additions & 0 deletions .vscode/snippets.code-snippets
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
// Place your obsidian-syncthing-integration workspace snippets here. Each snippet is defined under a snippet name and has a scope, prefix, body and
// description. Add comma separated ids of the languages where the snippet is applicable in the scope field. If scope
// is left empty or omitted, the snippet gets applied to all languages. The prefix is what is
// used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders.
// Placeholders with the same ids are connected.
// Example:
// "Print to console": {
// "scope": "javascript,typescript",
// "prefix": "log",
// "body": [
// "console.log('$1');",
// "$2"
// ],
// "description": "Log output to console"
// }
"Create new Syncthing EventTypes": {
"scope": "javascript,typescript",
"prefix": "syncthing-eventTypes",
"body": [
"export const $1 = SyncthingGenericEvent(\"$1\",object({$2}));"
],
"description": "Create new Syncthing EventTypes"
}
}
16 changes: 16 additions & 0 deletions compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
version: "3"
services:
syncthing:
image: syncthing/syncthing:latest
ports:
- 1234:8384
- 22001:22000/tcp
- 22001:22000/udp
- 21028:21027/udp
volumes:
- /wherever/st-sync:/var/syncthing
environment:
- PUID=1000
- PGID=1000
- STGUIADDRESS=0.0.0.0:8384
hostname: my-second-syncthing
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"@types/node": "^18.0.0",
"@typescript-eslint/eslint-plugin": "5.61.0",
"@typescript-eslint/parser": "5.62.0",
"@xstate/svelte": "^3.0.0",
"builtin-modules": "3.3.0",
"child_process": "^1.0.2",
"codemirror": "^6.0.1",
Expand All @@ -54,7 +55,9 @@
"svelte": "^4.2.0",
"svelte-preprocess": "^5.0.4",
"tslib": "2.6.0",
"typescript": "^5.0.0"
"typescript": "^5.0.0",
"valibot": "^0.13.1",
"xstate": "^5.2.1"
},
"repository": {
"type": "git",
Expand Down
36 changes: 33 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions src/components/configuration_item.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
import { Notice } from "obsidian";
import { SyncthingDevice, SyncthingFolder } from "src/models/entities";
import ObsidianLucideIcon from "./obsidian_lucide_icon.svelte";
import { Output } from "valibot";

export let folder: SyncthingFolder | undefined = undefined;
export let device: SyncthingDevice | undefined = undefined;
export let folder: Output<typeof SyncthingFolder> | undefined = undefined;
export let device: Output<typeof SyncthingDevice> | undefined = undefined;
export let isThisDevice = false;
</script>

Expand Down Expand Up @@ -164,7 +165,7 @@
</div>
</td>
<td>
<span>{device.address.join(", ")}</span>
<span>{device.addresses.join(", ")}</span>
</td>
</tr>
<tr>
Expand Down
75 changes: 56 additions & 19 deletions src/components/configuration_table.svelte
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<script lang="ts">
import { useActor } from "@xstate/svelte";
import { Notice } from "obsidian";
import { SyncthingDevice, SyncthingFolder } from "src/models/entities";
import { ConfigurationModal } from "src/views/configuration_modal";
import { onMount } from "svelte";
import { derived } from "svelte/store";
import ConfigurationItem from "./configuration_item.svelte";
import FolderItem from "./folder_item.svelte";
import { syncthingControllerMachine } from "./machines";
import ObsidianLucideIcon from "./obsidian_lucide_icon.svelte";
import RemoteItem from "./remote_item.svelte";
import WarningMessage from "./warning_message.svelte";
Expand All @@ -13,29 +14,65 @@
parent.titleEl.setText("Syncthing Configuration");
parent.titleEl.style.textAlign = "center";

let syncthingBaseUrl = `${parent.plugin.settings.configuration.url?.protocol}://${parent.plugin.settings.configuration.url?.ip_address}:${parent.plugin.settings.configuration.url?.port}/`;
console.log(syncthingBaseUrl);
// TODO: refactor this to use Svelte stores.
let folders: SyncthingFolder[] = [];
let devices: SyncthingDevice[] = [];
let thisDevice: SyncthingDevice | undefined = undefined;
onMount(async () => {
folders = await parent.plugin.syncthingController.getFolders();
devices = await parent.plugin.syncthingController.getDevices();
thisDevice = devices.first();
console.log("Folders: ", folders);
console.log("Devices: ", devices);
let { send, snapshot } = useActor(syncthingControllerMachine, {
input: {
syncthingREST: parent.plugin.syncthingFromREST,
},
});
snapshot.subscribe((data) => {
console.log("snapshot: ", data);
});
const folders = derived(
snapshot,
($snapshot) => $snapshot.context.configuration?.folders ?? [],
);
const devices = derived(
snapshot,
($snapshot) => $snapshot.context.configuration?.devices ?? [],
);
const thisDevice = derived(
snapshot,
($snapshot) =>
$devices.filter(
(device) =>
$snapshot.context.system_status?.myID === device.deviceID,
)[0],
);
</script>

<WarningMessage
message="The following configuration is not fully implemented yet. Some data aren't real-time and some controls are not implemented yet. It is mainly to reproduce the Syncthing GUI and then, real-time data and controls will be added."
/>

{#if $snapshot.matches("failure")}
<WarningMessage
title="An error occurred"
message="Something wrong happened. The configuration might not be correctly shown. Expect some errors."
>
<button on:click={() => send({ type: "RETRY" })}> Retry </button>
</WarningMessage>
{/if}

<!-- {#if restartRequired}
TODO: make it change when configuration changes. (note for later)
<WarningMessage
message="The configuration has been saved but not activated. Syncthing must restart to activate the new configuration."
>
<button
on:click={async () => {
await parent.plugin.syncthingFromREST.restart();
restartRequired = !restartRequired;
}}
>
Restart
</button>
</WarningMessage>
{/if} -->

<div class="left">
<div class="folder">
<h2>Folders ({folders.length})</h2>
{#each folders as folder}
<h2>Folders ({$folders.length})</h2>
{#each $folders as folder}
<FolderItem {folder} />
{/each}
<div class="controls">
Expand Down Expand Up @@ -69,14 +106,14 @@
<div class="right">
<div class="mydevice">
<h2>This Device</h2>
<ConfigurationItem isThisDevice device={thisDevice} />
<ConfigurationItem isThisDevice device={$thisDevice} />
</div>
<div class="remote">
<h2>
Remote Devices ({devices.filter((value) => value !== thisDevice)
Remote Devices ({$devices.filter((value) => value !== $thisDevice)
.length})
</h2>
{#each devices.filter((value) => value !== thisDevice) as device}
{#each $devices.filter((value) => value !== $thisDevice) as device}
<RemoteItem {device} />
{/each}
<div class="controls">
Expand Down
9 changes: 2 additions & 7 deletions src/components/conflicts_list.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,12 @@
dropdown.onChange((value) => {
conflicts = sortFilesBy(
conflicts,
value as keyof typeof sortOptions,
parentModal.syncthingController
value as keyof typeof sortOptions
);
console.log("dropdown", conflicts);
});
});
conflicts = sortFilesBy(
conflicts,
"recent",
parentModal.syncthingController
);
conflicts = sortFilesBy(conflicts, "recent");
});

parentModal.titleEl.setText("Syncthing Conflicts");
Expand Down
7 changes: 4 additions & 3 deletions src/components/folder_item.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
import { SyncthingFolder } from "src/models/entities";
import ConfigurationItem from "./configuration_item.svelte";
import ObsidianLucideIcon from "./obsidian_lucide_icon.svelte";
export let folder: SyncthingFolder = {
import { Output } from "valibot";
export let folder: Output<typeof SyncthingFolder> = {
id: "folder ID",
label: "folder label",
path: "folder path",
type: "sendreceive",
devices: [
{ deviceID: "device 1", encryptionPassword: "", introducedBy: "" },
{ deviceID: "device 2", encryptionPassword: "", introducedBy: "" },
{ deviceID: "device 1", introducedBy: "" },
{ deviceID: "device 2", introducedBy: "" },
],
filesystemType: "filesystem type",
maxConflicts: 0,
Expand Down
13 changes: 13 additions & 0 deletions src/components/light_bulb.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<script>
import { useActor } from "@xstate/svelte";
import { lightMachine } from "./machines";

const { snapshot, send, actorRef } = useActor(lightMachine);
actorRef.subscribe((snapshot) => console.log(snapshot));
</script>

<button on:click={() => send({ type: "TOGGLE" })}>
{$snapshot.value === "on" ? "Turn Off" : "Turn On"}
</button>

<p>The light bulb is currently {$snapshot.value}</p>
Loading
Loading