mirror of
https://github.com/stfrigerio/sqliteDB.git
synced 2026-07-22 05:38:02 +00:00
new settings
This commit is contained in:
parent
add626d956
commit
9ab65793df
4 changed files with 57 additions and 11 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
|
@ -20,3 +20,5 @@ data.json
|
|||
|
||||
# Exclude macOS Finder (System Explorer) View States
|
||||
.DS_Store
|
||||
|
||||
.env
|
||||
|
|
@ -87,15 +87,23 @@ export class DBService {
|
|||
* @returns Promise resolving to an array of result objects
|
||||
*/
|
||||
async getQuery<T extends Record<string, any>>(sql: string, params: any[] = []): Promise<T[]> {
|
||||
if (this.mode === "remote") {
|
||||
const res = await fetch(`${this.apiBaseUrl}/query`, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ sql, params }),
|
||||
});
|
||||
if (!res.ok) throw new Error(await res.text());
|
||||
return await res.json();
|
||||
}
|
||||
if (this.mode === "remote") {
|
||||
const res = await fetch(`${this.apiBaseUrl}/query`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
...(this.settings?.cfAccessClientId && {
|
||||
"CF-Access-Client-Id": this.settings.cfAccessClientId,
|
||||
}),
|
||||
...(this.settings?.cfAccessClientSecret && {
|
||||
"CF-Access-Client-Secret": this.settings.cfAccessClientSecret,
|
||||
}),
|
||||
},
|
||||
body: JSON.stringify({ sql, params }),
|
||||
});
|
||||
if (!res.ok) throw new Error(await res.text());
|
||||
return await res.json();
|
||||
}
|
||||
|
||||
if (!this.db) throw new Error("Database not loaded (local mode).");
|
||||
|
||||
|
|
@ -125,8 +133,16 @@ export class DBService {
|
|||
if (this.mode === "remote") {
|
||||
const res = await fetch(`${this.apiBaseUrl}/execute`, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ sql, params }),
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
...(this.settings?.cfAccessClientId && {
|
||||
"CF-Access-Client-Id": this.settings.cfAccessClientId,
|
||||
}),
|
||||
...(this.settings?.cfAccessClientSecret && {
|
||||
"CF-Access-Client-Secret": this.settings.cfAccessClientSecret,
|
||||
}),
|
||||
},
|
||||
body: JSON.stringify({ sql, params }),
|
||||
});
|
||||
if (!res.ok) throw new Error(await res.text());
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -69,5 +69,29 @@ export class SQLiteDBSettingTab extends PluginSettingTab {
|
|||
this.plugin.settings.journalTableName = value;
|
||||
await this.plugin.saveSettings();
|
||||
}));
|
||||
|
||||
new Setting(containerEl)
|
||||
.setName("CF Access Client ID")
|
||||
.setDesc("Cloudflare Access client ID for remote API authentication")
|
||||
.addText(text =>
|
||||
text
|
||||
.setPlaceholder("your-client-id")
|
||||
.setValue(this.plugin.settings.cfAccessClientId || "")
|
||||
.onChange(async (value) => {
|
||||
this.plugin.settings.cfAccessClientId = value;
|
||||
await this.plugin.saveSettings();
|
||||
}));
|
||||
|
||||
new Setting(containerEl)
|
||||
.setName("CF Access Client Secret")
|
||||
.setDesc("Cloudflare Access client secret for remote API authentication")
|
||||
.addText(text =>
|
||||
text
|
||||
.setPlaceholder("your-client-secret")
|
||||
.setValue(this.plugin.settings.cfAccessClientSecret || "")
|
||||
.onChange(async (value) => {
|
||||
this.plugin.settings.cfAccessClientSecret = value;
|
||||
await this.plugin.saveSettings();
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,8 @@ export interface SQLiteDBSettings {
|
|||
apiBaseUrl: string;
|
||||
journalFolderPath: string;
|
||||
journalTableName: string;
|
||||
cfAccessClientId: string;
|
||||
cfAccessClientSecret: string;
|
||||
}
|
||||
|
||||
export const DEFAULT_SETTINGS: SQLiteDBSettings = {
|
||||
|
|
@ -12,4 +14,6 @@ export const DEFAULT_SETTINGS: SQLiteDBSettings = {
|
|||
apiBaseUrl: "",
|
||||
journalFolderPath: "",
|
||||
journalTableName: "",
|
||||
cfAccessClientId: "",
|
||||
cfAccessClientSecret: "",
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in a new issue