annotate src/bump.js.luan @ 20:914a37651a38

minor
author Franklin Schmidt <fschmidt@gmail.com>
date Sun, 05 Nov 2023 11:31:16 -0700
parents 552d6f944acb
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
16
552d6f944acb add bump
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1 local Luan = require "luan:Luan.luan"
552d6f944acb add bump
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2 local error = Luan.error
552d6f944acb add bump
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3 local Time = require "luan:Time.luan"
552d6f944acb add bump
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4 local time_now = Time.now or error()
552d6f944acb add bump
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
5 local Io = require "luan:Io.luan"
552d6f944acb add bump
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
6 local Http = require "luan:http/Http.luan"
552d6f944acb add bump
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
7 local Server = require "site:/lib/Server.luan"
552d6f944acb add bump
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
8 local Utils = require "site:/lib/Utils.luan"
552d6f944acb add bump
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
9 local get_user = Utils.get_user or error()
552d6f944acb add bump
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
10 local Db = require "site:/lib/Db.luan"
552d6f944acb add bump
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
11 local run_in_transaction = Db.run_in_transaction or error()
552d6f944acb add bump
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
12
552d6f944acb add bump
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
13
552d6f944acb add bump
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
14 return function()
552d6f944acb add bump
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
15 local server_id = Http.request.parameters.server or error()
552d6f944acb add bump
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
16 run_in_transaction( function()
552d6f944acb add bump
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
17 local server = Server.get_by_id(server_id) or error()
552d6f944acb add bump
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
18 server.owner_discord_id == get_user() or error()
552d6f944acb add bump
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
19 server.bumped = time_now()
552d6f944acb add bump
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
20 server.save()
552d6f944acb add bump
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
21 end )
552d6f944acb add bump
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
22 Io.stdout = Http.response.text_writer()
552d6f944acb add bump
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
23 %>
552d6f944acb add bump
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
24 location.reload();
552d6f944acb add bump
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
25 <%
552d6f944acb add bump
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
26 end