add get sharex config button to api key
This commit is contained in:
@@ -1850,6 +1850,7 @@
|
||||
const btnCopyApiKey = document.getElementById('btn-copy-api-key');
|
||||
const btnRegenApiKey = document.getElementById('btn-regen-api-key');
|
||||
const btnRevokeApiKey = document.getElementById('btn-revoke-api-key');
|
||||
const btnShareXDownload = document.getElementById('btn-sharex-download');
|
||||
const apiKeyActionStatus = document.getElementById('api-key-action-status');
|
||||
|
||||
const showApiKeyStatus = (msg, type) => {
|
||||
@@ -1866,9 +1867,11 @@
|
||||
`<span>Active key: <code style="font-size:0.9em;">${escHTML(preview)}</code></span>` +
|
||||
`<span style="color:var(--text-muted); margin-left:12px; font-size:0.85em;">Created: ${escHTML(date)}</span>`;
|
||||
if (btnRevokeApiKey) btnRevokeApiKey.style.display = '';
|
||||
if (btnShareXDownload) btnShareXDownload.style.display = '';
|
||||
} else {
|
||||
apiKeyStatusBox.innerHTML = '<span class="text-muted">No API key generated yet.</span>';
|
||||
if (btnRevokeApiKey) btnRevokeApiKey.style.display = 'none';
|
||||
if (btnShareXDownload) btnShareXDownload.style.display = 'none';
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1966,6 +1969,8 @@
|
||||
const data = await res.json();
|
||||
|
||||
if (data.success) {
|
||||
btnRevokeApiKey.disabled = false;
|
||||
btnRevokeApiKey.textContent = 'Revoke Key';
|
||||
renderApiKeyState(false, null, null);
|
||||
if (apiKeyRevealBox) apiKeyRevealBox.style.display = 'none';
|
||||
if (apiKeyFullDisplay) apiKeyFullDisplay.textContent = '';
|
||||
|
||||
@@ -811,6 +811,51 @@ export default router => {
|
||||
}
|
||||
});
|
||||
|
||||
// GET /api/v2/settings/api-key/sharex-config
|
||||
// Downloads a pre-filled ShareX custom uploader (.sxcu) for the requesting user.
|
||||
group.get(/\/api-key\/sharex-config$/, lib.loggedin, async (req, res) => {
|
||||
if (cfg.websrv.enable_user_api_keys === false) {
|
||||
return res.status(403).reply({ body: 'API keys are disabled' });
|
||||
}
|
||||
try {
|
||||
const row = (await db`
|
||||
SELECT api_key FROM user_api_keys
|
||||
WHERE user_id = ${+req.session.id}
|
||||
LIMIT 1
|
||||
`)[0];
|
||||
|
||||
if (!row) {
|
||||
return res.status(404).reply({ body: 'No API key — generate one first in Settings.' });
|
||||
}
|
||||
|
||||
const sxcu = {
|
||||
Version: '15.0.0',
|
||||
Name: cfg.main.url.domain,
|
||||
DestinationType: 'ImageUploader, FileUploader',
|
||||
RequestMethod: 'POST',
|
||||
RequestURL: `${cfg.main.url.full}/api/v2/upload`,
|
||||
Headers: {
|
||||
'X-Api-Key': row.api_key
|
||||
},
|
||||
Body: 'MultipartFormData',
|
||||
FileFormName: 'file',
|
||||
URL: '$json:url$',
|
||||
ErrorMessage: '$json:msg$'
|
||||
};
|
||||
|
||||
const filename = `${cfg.main.url.domain}.sxcu`;
|
||||
const body = JSON.stringify(sxcu, null, 2);
|
||||
res.writeHead(200, {
|
||||
'Content-Type': 'application/json; charset=utf-8',
|
||||
'Content-Disposition': `attachment; filename="${filename}"`,
|
||||
'Content-Length': Buffer.byteLength(body)
|
||||
}).end(body);
|
||||
} catch (e) {
|
||||
console.error('[API KEY] ShareX config error:', e);
|
||||
return res.status(500).reply({ body: 'Error generating config' });
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
// --- User Invite System ---
|
||||
// Eligibility: ≥150 uploads, ≥30 days old, ≥66 comments, ≥200 tags
|
||||
|
||||
@@ -567,6 +567,7 @@
|
||||
|
||||
<div style="display: flex; gap: 10px; flex-wrap: wrap; align-items: center;">
|
||||
<button type="button" id="btn-regen-api-key" class="button button-primary">Generate / Regenerate Key</button>
|
||||
<a id="btn-sharex-download" href="/api/v2/settings/api-key/sharex-config" download style="display:none; box-sizing:border-box; line-height:normal;" class="button">⭳ ShareX Config</a>
|
||||
<button type="button" id="btn-revoke-api-key" class="button button-danger" style="display:none;">Revoke Key</button>
|
||||
</div>
|
||||
<div id="api-key-action-status" class="avatar-status" style="margin-top: 10px;"></div>
|
||||
|
||||
Reference in New Issue
Block a user