updates commands

This commit is contained in:
2026-04-20 00:14:48 +03:00
parent 10cca7135a
commit c801b1800c
3 changed files with 12 additions and 12 deletions

View File

@@ -6,6 +6,8 @@
// @author Dimitrios // @author Dimitrios
// @match https://*.grepolis.com/game/* // @match https://*.grepolis.com/game/*
// @grant unsafeWindow // @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== // ==/UserScript==
(function () { (function () {
@@ -128,11 +130,11 @@
// ---------------------------------------------------------------- // ----------------------------------------------------------------
// Report command result back to relay // Report command result back to relay
// ---------------------------------------------------------------- // ----------------------------------------------------------------
function reportResult(cmdId, success, message) { function reportResult(cmdId, status, message) {
fetch(`${BASE_URL}/api/commands/${cmdId}/result`, { fetch(`${BASE_URL}/api/commands/${cmdId}/result`, {
method: 'POST', method: 'POST',
headers: { 'Content-Type': 'application/json' }, headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ status: success ? 'done' : 'failed', message }) body: JSON.stringify({ status, message })
}).catch(e => log(`reportResult failed: ${e}`)); }).catch(e => log(`reportResult failed: ${e}`));
} }
@@ -153,7 +155,7 @@
const hasCurator = uw.GameDataPremium?.isAdvisorActivated?.('curator'); const hasCurator = uw.GameDataPremium?.isAdvisorActivated?.('curator');
const maxQueue = hasCurator ? 7 : 2; const maxQueue = hasCurator ? 7 : 2;
if (queueLen >= maxQueue) { 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 // Check resources
@@ -248,8 +250,9 @@
result = { ok: false, msg: `Exception: ${e.message}` }; result = { ok: false, msg: `Exception: ${e.message}` };
} }
log(`Command #${cmd.id} result: ${result.ok ? '✅' : '❌'} ${result.msg}`); const finalStatus = result.requeue ? 'pending' : (result.ok ? 'done' : 'failed');
reportResult(cmd.id, result.ok, result.msg); log(`Command #${cmd.id} result: ${finalStatus === 'done' ? '✅' : (finalStatus === 'pending' ? '⏳' : '❌')} ${result.msg}`);
reportResult(cmd.id, finalStatus, result.msg);
} }
// ---------------------------------------------------------------- // ----------------------------------------------------------------

View File

@@ -113,15 +113,14 @@ def create_command():
# ------------------------------------------------------------------ # ------------------------------------------------------------------
# DELETE /dashboard/commands/<id> # 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']) @dashboard.route('/dashboard/commands/<int:cmd_id>', methods=['DELETE'])
def cancel_command(cmd_id): def cancel_command(cmd_id):
conn = get_db() conn = get_db()
conn.execute(''' conn.execute('''
UPDATE commands SET status = 'cancelled', updated_at = ? DELETE FROM commands WHERE id = ?
WHERE id = ? AND status = 'pending' ''', (cmd_id,))
''', (datetime.utcnow().isoformat(), cmd_id))
conn.commit() conn.commit()
conn.close() conn.close()
return jsonify({'ok': True}) return jsonify({'ok': True})

View File

@@ -489,9 +489,7 @@ function renderLog(cmds) {
? `Build: ${p.building_id}` ? `Build: ${p.building_id}`
: `Recruit: ${p.amount}x ${p.unit_id}`; : `Recruit: ${p.amount}x ${p.unit_id}`;
const statusClass = `status-${cmd.status}`; const statusClass = `status-${cmd.status}`;
const cancelBtn = cmd.status === 'pending' const cancelBtn = `<button class="btn btn-danger btn-sm" onclick="cancelCommand(${cmd.id})">✕</button>`;
? `<button class="btn btn-danger btn-sm" onclick="cancelCommand(${cmd.id})">✕</button>`
: '';
return `<tr> return `<tr>
<td style="color:#888;font-size:0.7rem">#${cmd.id}</td> <td style="color:#888;font-size:0.7rem">#${cmd.id}</td>