updates commands
This commit is contained in:
@@ -6,6 +6,8 @@
|
||||
// @author Dimitrios
|
||||
// @match https://*.grepolis.com/game/*
|
||||
// @grant unsafeWindow
|
||||
// @updateURL https://git.haunter-pets.top/haunter/grepo-remote/raw/branch/main/GrepolisRemoteControl.user.js
|
||||
// @downloadURL https://git.haunter-pets.top/haunter/grepo-remote/raw/branch/main/GrepolisRemoteControl.user.js
|
||||
// ==/UserScript==
|
||||
|
||||
(function () {
|
||||
@@ -128,11 +130,11 @@
|
||||
// ----------------------------------------------------------------
|
||||
// Report command result back to relay
|
||||
// ----------------------------------------------------------------
|
||||
function reportResult(cmdId, success, message) {
|
||||
function reportResult(cmdId, status, message) {
|
||||
fetch(`${BASE_URL}/api/commands/${cmdId}/result`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ status: success ? 'done' : 'failed', message })
|
||||
body: JSON.stringify({ status, message })
|
||||
}).catch(e => log(`reportResult failed: ${e}`));
|
||||
}
|
||||
|
||||
@@ -153,7 +155,7 @@
|
||||
const hasCurator = uw.GameDataPremium?.isAdvisorActivated?.('curator');
|
||||
const maxQueue = hasCurator ? 7 : 2;
|
||||
if (queueLen >= maxQueue) {
|
||||
return { ok: false, msg: `Build queue full (${queueLen}/${maxQueue})` };
|
||||
return { ok: false, requeue: true, msg: `Build queue full (${queueLen}/${maxQueue})` };
|
||||
}
|
||||
|
||||
// Check resources
|
||||
@@ -248,8 +250,9 @@
|
||||
result = { ok: false, msg: `Exception: ${e.message}` };
|
||||
}
|
||||
|
||||
log(`Command #${cmd.id} result: ${result.ok ? '✅' : '❌'} ${result.msg}`);
|
||||
reportResult(cmd.id, result.ok, result.msg);
|
||||
const finalStatus = result.requeue ? 'pending' : (result.ok ? 'done' : 'failed');
|
||||
log(`Command #${cmd.id} result: ${finalStatus === 'done' ? '✅' : (finalStatus === 'pending' ? '⏳' : '❌')} ${result.msg}`);
|
||||
reportResult(cmd.id, finalStatus, result.msg);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
|
||||
@@ -113,15 +113,14 @@ def create_command():
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# DELETE /dashboard/commands/<id>
|
||||
# Cancel a pending command from the dashboard.
|
||||
# Fully delete a command from the dashboard history.
|
||||
# ------------------------------------------------------------------
|
||||
@dashboard.route('/dashboard/commands/<int:cmd_id>', methods=['DELETE'])
|
||||
def cancel_command(cmd_id):
|
||||
conn = get_db()
|
||||
conn.execute('''
|
||||
UPDATE commands SET status = 'cancelled', updated_at = ?
|
||||
WHERE id = ? AND status = 'pending'
|
||||
''', (datetime.utcnow().isoformat(), cmd_id))
|
||||
DELETE FROM commands WHERE id = ?
|
||||
''', (cmd_id,))
|
||||
conn.commit()
|
||||
conn.close()
|
||||
return jsonify({'ok': True})
|
||||
|
||||
@@ -489,9 +489,7 @@ function renderLog(cmds) {
|
||||
? `Build: ${p.building_id}`
|
||||
: `Recruit: ${p.amount}x ${p.unit_id}`;
|
||||
const statusClass = `status-${cmd.status}`;
|
||||
const cancelBtn = cmd.status === 'pending'
|
||||
? `<button class="btn btn-danger btn-sm" onclick="cancelCommand(${cmd.id})">✕</button>`
|
||||
: '';
|
||||
const cancelBtn = `<button class="btn btn-danger btn-sm" onclick="cancelCommand(${cmd.id})">✕</button>`;
|
||||
|
||||
return `<tr>
|
||||
<td style="color:#888;font-size:0.7rem">#${cmd.id}</td>
|
||||
|
||||
Reference in New Issue
Block a user