feat: api token migration, new ACP tokens list, token creation
parent
7b8bffd763
commit
e4888dea17
@ -0,0 +1,7 @@
|
||||
.template-admin-settings-api {
|
||||
[data-action="copy"]:active {
|
||||
i::before {
|
||||
content: '\f00c';
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
'use strict';
|
||||
|
||||
const assert = require('assert');
|
||||
const winston = require('winston');
|
||||
|
||||
const db = require('../../database');
|
||||
const meta = require('../../meta');
|
||||
const api = require('../../api');
|
||||
|
||||
module.exports = {
|
||||
name: 'Migrate tokens away from sorted-list implementation',
|
||||
timestamp: Date.UTC(2023, 4, 2),
|
||||
method: async () => {
|
||||
const { tokens = [] } = await meta.settings.get('core.api');
|
||||
|
||||
await Promise.all(tokens.map(async (tokenObj) => {
|
||||
const { token, uid, description } = tokenObj;
|
||||
await api.utils.tokens.add({ token, uid, description });
|
||||
}));
|
||||
|
||||
// Validate
|
||||
const oldCount = await db.sortedSetCard('settings:core.api:sorted-list:tokens');
|
||||
const newCount = await db.sortedSetCard('tokens:createtime');
|
||||
try {
|
||||
if (oldCount > 0) {
|
||||
assert.strictEqual(oldCount, newCount);
|
||||
}
|
||||
|
||||
// Delete old tokens
|
||||
await meta.settings.set('core.api', {
|
||||
tokens: [],
|
||||
});
|
||||
await db.delete('settings:core.api:sorted-lists');
|
||||
} catch (e) {
|
||||
winston.warn('Old token count does not match migrated tokens count, leaving old tokens behind.');
|
||||
}
|
||||
},
|
||||
};
|
@ -1,21 +0,0 @@
|
||||
<li data-type="item" class="list-group-item">
|
||||
<div class="row">
|
||||
<div class="col-9">
|
||||
<span class="badge bg-primary">{{{ if uid }}}uid {uid}{{{ else }}}master{{{ end }}}</span>
|
||||
{{{ if token }}}<input class="form-control-plaintext" type="text" readonly="readonly" value="{token}" size="32" />{{{ else }}}<em class="text-warning">[[admin/settings/api:token-on-save]]</em>{{{ end }}}<br />
|
||||
<p>
|
||||
{{{ if description }}}
|
||||
{description}
|
||||
{{{ else }}}
|
||||
<em>[[admin/settings/api:no-description]]</em>
|
||||
{{{ end }}}
|
||||
<br />
|
||||
<small class="text-info">{./lastSeen}</small>
|
||||
</p>
|
||||
</div>
|
||||
<div class="col-3 text-end">
|
||||
<button type="button" data-type="edit" class="btn btn-info">Edit</button>
|
||||
<button type="button" data-type="remove" class="btn btn-danger">Delete</button>
|
||||
</div>
|
||||
</div>
|
||||
</li>
|
@ -1,15 +1,13 @@
|
||||
<form>
|
||||
<input type="hidden" name="token" />
|
||||
<input type="hidden" name="timestamp" />
|
||||
<form role="form">
|
||||
<div class="mb-3">
|
||||
<label class="form-label" for="uid">[[admin/settings/api:uid]]</label>
|
||||
<input type="text" inputmode="numeric" pattern="\d+" name="uid" class="form-control" placeholder="1" />
|
||||
<input type="text" inputmode="numeric" pattern="\d+" name="uid" class="form-control" placeholder="0" value="{./uid}" />
|
||||
<p class="form-text">
|
||||
[[admin/settings/api:uid-help-text]]
|
||||
</p>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label class="form-label" for="description">[[admin/settings/api:description]]</label>
|
||||
<input type="text" name="description" class="form-control" placeholder="Description" />
|
||||
<input type="text" name="description" class="form-control" placeholder="Description" value="{./description}" />
|
||||
</div>
|
||||
</form>
|
Loading…
Reference in New Issue