Skip to content

Commit f18059f

Browse files
committed
fix: bug fixes
1 parent b36360b commit f18059f

4 files changed

Lines changed: 35 additions & 34 deletions

File tree

src/resources/syncthing/syncthing-folder.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const schema = z
2727
.string()
2828
.optional()
2929
.describe('Human-readable display name for this folder'),
30-
type: z
30+
folderType: z
3131
.enum(FOLDER_TYPES)
3232
.optional()
3333
.describe('Folder sync type: sendreceive (default), sendonly, receiveonly, or receiveencrypted'),
@@ -87,7 +87,7 @@ export class SyncthingFolderResource extends Resource<SyncthingFolderConfig> {
8787
parameterSettings: {
8888
path: { type: 'directory', canModify: false },
8989
label: { type: 'string', canModify: true },
90-
type: { type: 'string', canModify: true },
90+
folderType: { type: 'string', canModify: true },
9191
devices: { type: 'array', canModify: true },
9292
fsWatcherEnabled: { type: 'boolean', canModify: true },
9393
rescanIntervalS: { type: 'number', canModify: true },
@@ -227,7 +227,7 @@ function folderFromRaw(raw: RawFolder): Partial<SyncthingFolderConfig> {
227227
id: raw.id,
228228
label: raw.label || undefined,
229229
path: raw.path,
230-
type: raw.type as SyncthingFolderConfig['type'],
230+
folderType: raw.type as SyncthingFolderConfig['folderType'],
231231
devices: raw.devices.map((d) => d.deviceID),
232232
fsWatcherEnabled: raw.fsWatcherEnabled,
233233
rescanIntervalS: raw.rescanIntervalS,
@@ -239,9 +239,9 @@ function folderFromRaw(raw: RawFolder): Partial<SyncthingFolderConfig> {
239239
function folderOptionCliPath(key: keyof SyncthingFolderConfig): string | undefined {
240240
const map: Partial<Record<keyof SyncthingFolderConfig, string>> = {
241241
label: 'label',
242-
type: 'type',
243-
fsWatcherEnabled: 'fsWatcherEnabled',
244-
rescanIntervalS: 'rescanIntervalS',
242+
folderType: 'type',
243+
fsWatcherEnabled: 'fswatcher-enabled',
244+
rescanIntervalS: 'rescan-intervals',
245245
maxConflicts: 'maxConflicts',
246246
paused: 'paused',
247247
};
@@ -254,11 +254,11 @@ function buildFolderAddArgs(config: Partial<SyncthingFolderConfig>): string {
254254
if (config.id) parts.push(`--id ${config.id}`);
255255
if (config.path) parts.push(`--path "${config.path}"`);
256256
if (config.label) parts.push(`--label "${config.label}"`);
257-
if (config.type) parts.push(`--type ${config.type}`);
257+
if (config.folderType) parts.push(`--type ${config.folderType}`);
258258
if (config.fsWatcherEnabled !== undefined)
259-
parts.push(`--fs-watcher-enabled=${config.fsWatcherEnabled}`);
259+
parts.push(config.fsWatcherEnabled ? '--fswatcher-enabled' : '--fswatcher-enabled=false');
260260
if (config.rescanIntervalS !== undefined)
261-
parts.push(`--rescan-interval-s ${config.rescanIntervalS}`);
261+
parts.push(`--rescan-intervals ${config.rescanIntervalS}`);
262262
if (config.maxConflicts !== undefined) parts.push(`--max-conflicts ${config.maxConflicts}`);
263263
if (config.paused !== undefined) parts.push(`--paused=${config.paused}`);
264264

src/resources/syncthing/syncthing-utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export async function getCliConfigValue(cliPath: string): Promise<string | undef
4444
*/
4545
export async function setCliConfigValue(cliPath: string, value: string): Promise<void> {
4646
const $ = getPty();
47-
await $.spawn(`syncthing cli config ${cliPath} set ${value}`, { interactive: true });
47+
await $.spawn(`syncthing cli config ${cliPath} set -- ${value}`, { interactive: true });
4848
}
4949

5050
/** Reads a boolean config value; returns undefined when unavailable. */

src/resources/syncthing/syncthing.ts

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -75,16 +75,17 @@ const schema = z
7575
export type SyncthingConfig = z.infer<typeof schema>;
7676

7777
// Maps schema key → syncthing CLI config path (without trailing "get/set <value>")
78+
// Syncthing v2 uses kebab-case subcommands
7879
const OPTION_CLI_PATHS: Partial<Record<keyof SyncthingConfig, string>> = {
79-
guiAddress: 'gui address',
80-
globalAnnounceEnabled: 'options globalAnnounceEnabled',
81-
localAnnounceEnabled: 'options localAnnounceEnabled',
82-
relaysEnabled: 'options relaysEnabled',
83-
natEnabled: 'options natEnabled',
84-
maxSendKbps: 'options maxSendKbps',
85-
maxRecvKbps: 'options maxRecvKbps',
86-
startBrowser: 'options startBrowser',
87-
urAccepted: 'options urAccepted',
80+
guiAddress: 'gui raw-address',
81+
globalAnnounceEnabled: 'options global-ann-enabled',
82+
localAnnounceEnabled: 'options local-ann-enabled',
83+
relaysEnabled: 'options relays-enabled',
84+
natEnabled: 'options natenabled',
85+
maxSendKbps: 'options max-send-kbps',
86+
maxRecvKbps: 'options max-recv-kbps',
87+
startBrowser: 'options start-browser',
88+
urAccepted: 'options uraccepted',
8889
};
8990

9091
export class SyncthingResource extends Resource<SyncthingConfig> {
@@ -122,15 +123,15 @@ export class SyncthingResource extends Resource<SyncthingConfig> {
122123

123124
// Option values can only be fetched when the daemon is running
124125
if (await isDaemonRunning()) {
125-
result.guiAddress = await getCliConfigValue('gui address');
126-
result.globalAnnounceEnabled = await getCliConfigBool('options globalAnnounceEnabled');
127-
result.localAnnounceEnabled = await getCliConfigBool('options localAnnounceEnabled');
128-
result.relaysEnabled = await getCliConfigBool('options relaysEnabled');
129-
result.natEnabled = await getCliConfigBool('options natEnabled');
130-
result.maxSendKbps = await getCliConfigNumber('options maxSendKbps');
131-
result.maxRecvKbps = await getCliConfigNumber('options maxRecvKbps');
132-
result.startBrowser = await getCliConfigBool('options startBrowser');
133-
result.urAccepted = await getCliConfigNumber('options urAccepted');
126+
result.guiAddress = await getCliConfigValue('gui raw-address');
127+
result.globalAnnounceEnabled = await getCliConfigBool('options global-ann-enabled');
128+
result.localAnnounceEnabled = await getCliConfigBool('options local-ann-enabled');
129+
result.relaysEnabled = await getCliConfigBool('options relays-enabled');
130+
result.natEnabled = await getCliConfigBool('options natenabled');
131+
result.maxSendKbps = await getCliConfigNumber('options max-send-kbps');
132+
result.maxRecvKbps = await getCliConfigNumber('options max-recv-kbps');
133+
result.startBrowser = await getCliConfigBool('options start-browser');
134+
result.urAccepted = await getCliConfigNumber('options uraccepted');
134135
}
135136

136137
return result;

test/syncthing/syncthing.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,13 @@ describe('Syncthing resource integration tests', async () => {
5858
});
5959

6060
const announceResult = await testSpawn(
61-
'syncthing cli config options globalAnnounceEnabled get'
61+
'syncthing cli config options global-ann-enabled get'
6262
);
6363
expect(announceResult.status).toBe(SpawnStatus.SUCCESS);
6464
expect(announceResult.data.trim()).toBe('false');
6565

6666
const relaysResult = await testSpawn(
67-
'syncthing cli config options relaysEnabled get'
67+
'syncthing cli config options relays-enabled get'
6868
);
6969
expect(relaysResult.status).toBe(SpawnStatus.SUCCESS);
7070
expect(relaysResult.data.trim()).toBe('false');
@@ -94,7 +94,7 @@ describe('Syncthing resource integration tests', async () => {
9494
{
9595
validateApply: async () => {
9696
const relaysResult = await testSpawn(
97-
'syncthing cli config options relaysEnabled get'
97+
'syncthing cli config options relays-enabled get'
9898
);
9999
expect(relaysResult.data.trim()).toBe('true');
100100
},
@@ -109,12 +109,12 @@ describe('Syncthing resource integration tests', async () => {
109109
],
110110
validateModify: async () => {
111111
const relaysResult = await testSpawn(
112-
'syncthing cli config options relaysEnabled get'
112+
'syncthing cli config options relays-enabled get'
113113
);
114114
expect(relaysResult.data.trim()).toBe('false');
115115

116116
const bwResult = await testSpawn(
117-
'syncthing cli config options maxSendKbps get'
117+
'syncthing cli config options max-send-kbps get'
118118
);
119119
expect(bwResult.data.trim()).toBe('1024');
120120
},
@@ -144,7 +144,7 @@ describe('Syncthing resource integration tests', async () => {
144144
id: 'codify-test',
145145
path: testFolderPath,
146146
label: 'Codify Test Folder',
147-
type: 'sendreceive',
147+
folderType: 'sendreceive',
148148
fsWatcherEnabled: false,
149149
rescanIntervalS: 3600,
150150
maxConflicts: 0,

0 commit comments

Comments
 (0)