gist - configurable token

This commit is contained in:
Jan Prochazka
2024-05-27 14:01:58 +02:00
parent d3737b4e08
commit 22bed04d13
3 changed files with 24 additions and 3 deletions

View File

@@ -10,6 +10,7 @@ const { read } = require('./queryHistory');
const platformInfo = require('../utility/platformInfo');
const _ = require('lodash');
const serverConnections = require('./serverConnections');
const config = require('./config');
const gistSecret = require('../gistSecret');
module.exports = {
@@ -44,9 +45,14 @@ module.exports = {
res.sendFile(path.join(uploadsdir(), req.query.file));
},
async getGistToken() {
const settings = await config.getSettings();
return settings['other.gistCreateToken'] || gistSecret;
},
uploadErrorToGist_meta: true,
async uploadErrorToGist() {
console.log('&&&SECRET', gistSecret);
const logs = await fs.readFile(getLogsFilePath(), { encoding: 'utf-8' });
const connections = await serverConnections.getOpenedConnectionReport();
try {
@@ -91,7 +97,7 @@ module.exports = {
},
{
headers: {
Authorization: `token ${gistSecret}`,
Authorization: `token ${await this.getGistToken()}`,
'Content-Type': 'application/json',
Accept: 'application/vnd.github.v3+json',
},
@@ -113,7 +119,7 @@ module.exports = {
async deleteGist({ url }) {
const response = await axios.default.delete(url, {
headers: {
Authorization: `token ${gistSecret}`,
Authorization: `token ${await this.getGistToken()}`,
'Content-Type': 'application/json',
Accept: 'application/vnd.github.v3+json',
},

View File

@@ -12,15 +12,18 @@
import Link from '../elements/Link.svelte';
import LoadingInfo from '../elements/LoadingInfo.svelte';
import { showSnackbarSuccess } from '../utility/snackbar';
import ErrorInfo from '../elements/ErrorInfo.svelte';
export let error = null;
let htmlUrl;
let url;
let errorMessage;
async function upload() {
const resp = await apiCall('uploads/upload-error-to-gist');
url = resp.url;
htmlUrl = resp.html_url;
errorMessage = resp.errorMessage;
}
onMount(() => {
@@ -49,6 +52,8 @@
</p>
<p><Link href={htmlUrl}>Open uploaded data</Link></p>
</div>
{:else if errorMessage}
<ErrorInfo message={errorMessage} />
{:else}
<LoadingInfo message="Uploading error to gist..." />
{/if}

View File

@@ -74,6 +74,7 @@ ORDER BY
{ label: 'Themes', slot: 3 },
{ label: 'Default Actions', slot: 4 },
{ label: 'Confirmations', slot: 5 },
{ label: 'Other', slot: 6 },
]}
>
<svelte:fragment slot="1">
@@ -313,6 +314,15 @@ ORDER BY
label="Skip confirmation when saving collection data (NoSQL)"
/>
</svelte:fragment>
<svelte:fragment slot="6">
<div class="heading">Other</div>
<FormTextField
name="other.gistCreateToken"
label="API token for creating error gists"
defaultValue=""
/>
</svelte:fragment>
</TabControl>
</FormValues>