mirror of
https://github.com/binaricat/Netcatty.git
synced 2026-10-09 15:58:34 +00:00
e00fa2733b
Updates all code references, IPC channels, CSS classes, and storage keys from "nebula" to "netcatty" to align with new branding and application identity. Ensures consistency across frontend, Electron backend, global types, and package metadata.
67 lines
1.7 KiB
TypeScript
Executable File
67 lines
1.7 KiB
TypeScript
Executable File
import { Host,SSHKey,Snippet } from '../../domain/models';
|
|
|
|
interface BackupData {
|
|
hosts: Host[];
|
|
keys: SSHKey[];
|
|
snippets: Snippet[];
|
|
customGroups: string[];
|
|
timestamp: number;
|
|
version: number;
|
|
}
|
|
|
|
export const syncToGist = async (token: string, gistId: string | undefined, data: Omit<BackupData, 'timestamp' | 'version'>): Promise<string> => {
|
|
const payload = {
|
|
description: "Netcatty SSH Config Backup",
|
|
public: false,
|
|
files: {
|
|
"netcatty-config.json": {
|
|
content: JSON.stringify({ ...data, timestamp: Date.now(), version: 1 }, null, 2)
|
|
}
|
|
}
|
|
};
|
|
|
|
const url = gistId
|
|
? `https://api.github.com/gists/${gistId}`
|
|
: `https://api.github.com/gists`;
|
|
|
|
const method = gistId ? 'PATCH' : 'POST';
|
|
|
|
const response = await fetch(url, {
|
|
method,
|
|
headers: {
|
|
'Authorization': `token ${token}`,
|
|
'Accept': 'application/vnd.github.v3+json'
|
|
},
|
|
body: JSON.stringify(payload)
|
|
});
|
|
|
|
if (!response.ok) {
|
|
throw new Error(`Failed to sync: ${response.statusText}`);
|
|
}
|
|
|
|
const result = await response.json();
|
|
return result.id;
|
|
};
|
|
|
|
export const loadFromGist = async (token: string, gistId: string): Promise<BackupData> => {
|
|
const response = await fetch(`https://api.github.com/gists/${gistId}`, {
|
|
headers: {
|
|
'Authorization': `token ${token}`,
|
|
'Accept': 'application/vnd.github.v3+json'
|
|
}
|
|
});
|
|
|
|
if (!response.ok) {
|
|
throw new Error(`Failed to load: ${response.statusText}`);
|
|
}
|
|
|
|
const result = await response.json();
|
|
const file = result.files["netcatty-config.json"];
|
|
|
|
if (!file || !file.content) {
|
|
throw new Error("Invalid Gist format: netcatty-config.json not found");
|
|
}
|
|
|
|
return JSON.parse(file.content);
|
|
};
|