Browse Source

[YQTemplate] Switched to base64 from library

main
Annwan 4 months ago
parent
commit
3b371e7e08
  1. 48
      utils.lua
  2. 68
      yqform.etlua
  3. 2
      yqtemplate.lua

48
utils.lua

@ -15,54 +15,6 @@ _m.readfile = function(path)
return data
end
local tobase64_helper1 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
--- @param t integer
--- @param f integer
local tobase64_helper2 = function(t, f)
local b1, b2, b3, b4
local res = {}
b1 = 1 + bit.lshift(bit.band(t, 0xfc0000), 18)
b2 = 1 + bit.lshift(bit.band(t, 0x03f000), 12)
b3 = 1 + bit.lshift(bit.band(t, 0x000fc0), 6)
b4 = 1 + bit.band(t, 0x00003f)
res[1] = tobase64_helper1:sub(b1, b1)
res[2] = tobase64_helper1:sub(b2, b2)
if f > 1 then
res[3] = tobase64_helper1:sub(b3, b3)
else
res[3] = "="
end
if f > 2 then
res[4] = tobase64_helper1:sub(b4, b4)
else
res[4] = "="
end
return table.concat(res)
end
--- @param data string
--- @return string encoded
_m.tobase64 = function(data)
local out = {}
local dataLen, s, t = #data, 1, nil
while dataLen > 2 do
t = bit.rshift(data:sub(s, s):byte(), 16); s = s + 1
t = t + bit.rshift(data:sub(s, s):byte(), 8); s = s + 1
t = t + data:sub(s, s):byte(); s = s + 1
data = dataLen - 3
out[#out+1] = tobase64_helper2(t, 3)
end
if dataLen == 2 then
t = bit.rshift(data:sub(s, s):byte(), 16); s = s + 1
t = t + bit.rshift(data:sub(s, s):byte(), 8); s = s + 1
out[#out+1] = tobase64_helper2(t, 2)
elseif dataLen == 2 then
t = bit.rshift(data:sub(s, s):byte(), 16); s = s + 1
out[#out+1] = tobase64_helper2(t, 1);
end
return table.concat(out)
end
--- @param entry string
--- @return string name the name of the form field.
--- @return string? content_type the content type of the attached file, or nil if entry is not a file.

68
yqform.etlua

@ -6,7 +6,7 @@
<body>
<h1>Yokoka’s Quest-style Profile generator</h1>
<h1>THIS IS WORK IN PROGRESS, THIS IS NON FUNCTIONAL, PLEASE DO NOT USE YET</h1>
<% if args %>
<% if args then %>
<h2>Information Gathered</h2>
<h3>General Information</h3>
<dl>
@ -15,7 +15,7 @@
<dt>Avatar</dt>
<dd><img src="data:<%= args.avatar.t -%>;base64,<%= encoder(args.avatar.v) %>" /></dd>
<dt>Is Leader</dt>
<dd><% if avatar.isLeader and avatar.isLeader.v == 1 then %>YES<% else %>NO<% end %></dd>
<dd><%= args.is_leader</dd>
</dl>
<% end %>
<form method="POST" action="/cgi/yqtemplate" enctype="multipart/form-data">
@ -24,8 +24,8 @@
<input type="test" name="name"/><br />
<label for="avatar">Portrait:</label>
<input type="file" name="avatar"/><br />
<label for="isLeader">Party Leader:</label>
<input type="checkbox" name="is-leader"/><br />
<label for="is_leader">Party Leader:</label>
<input type="checkbox" name="is_leader"/><br />
<h2>Classes and Levels</h2>
<label for="class1">Class 1:</label>
<select name="class1">
@ -33,33 +33,33 @@
<option value="<%= v %>"><%= v %></option>
<% end %>
</select>
<label for="class1-lvl">Level:</label>
<input type="number" name="class1-lvl" min="1"/><br/>
<label for="class1_lvl">Level:</label>
<input type="number" name="class1_lvl" min="1"/><br/>
<label for="class2">Class2:</label>
<select name="class2">
<% for _, v in ipairs(classes) do %>
<option value="<%= v %>"><%= v %></option>
<% end %>
</select>
<label for="class2-lvl">Level:</label>
<input type="number"name="class2-lvl" min="1"/><br/>
<label for="class-leaning">
<label for="class2_lvl">Level:</label>
<input type="number"name="class2_lvl" min="1"/><br/>
<label for="class_leaning">
Class leaning (0 for completely class 1, 100 for completely class 2):
</label>
<input type="number" name="class-leaning" min="0" max="100"></br>
<input type="number" name="class_leaning" min="0" max="100"></br>
<h2>Stats</h2>
<label for="stat-luc">Luck</label>
<input type="number" name="stat-luc" min="0" max="100" />
<label for="stat-str">Strength</label>
<input type="number" name="stat-str" min="0" max="100" />
<label for="stat-sta">Stamina</label>
<input type="number" name="stat-sta" min="0" max="100"/>
<label for="stat-agi">Agility</label>
<input type="number" name="stat-agi" min="0" max="100"/>
<label for="stat-int">Intelligence</label>
<input type="number" name="stat-int" min="0" max="100"/>
<label for="stat-res">Resistance</label>
<input type="number" name="stat-res" min="0" max="100"/><br/>
<label for="stat_luc">Luck</label>
<input type="number" name="stat_luc" min="0" max="100" />
<label for="stat_str">Strength</label>
<input type="number" name="stat_str" min="0" max="100" />
<label for="stat_sta">Stamina</label>
<input type="number" name="stat_sta" min="0" max="100"/>
<label for="stat_agi">Agility</label>
<input type="number" name="stat_agi" min="0" max="100"/>
<label for="stat_int">Intelligence</label>
<input type="number" name="stat_int" min="0" max="100"/>
<label for="stat_res">Resistance</label>
<input type="number" name="stat_res" min="0" max="100"/><br/>
<h2>Skills</h2>
<label for="allegiance">Allegiance:</label>
@ -81,18 +81,18 @@
<% end %>
</select><br />
<h2>Equipment</h2>
<label for="weapon-name">Weapon</label>
<input type="file" name="weapon-ico" />
<input type="text" name="weapon-name" /><br />
<label for="outfit-name">Outfit</label>
<input type="file" name="outfit-ico" />
<input type="text" name="outfit-name" /><br />
<label for="accessory1-name">Accessory 1</label>
<input type="file" name="accessory1-ico" />
<input type="text" name="accessory1-name" /><br />
<label for="accessory2-name">Accessory 2</label>
<input type="file" name="accessory2-ico" />
<input type="text" name="accessory2-name" /><br />
<label for="weapon_name">Weapon</label>
<input type="file" name="weapon_ico" />
<input type="text" name="weapon_name" /><br />
<label for="outfit_name">Outfit</label>
<input type="file" name="outfit_ico" />
<input type="text" name="outfit_name" /><br />
<label for="accessory1_name">Accessory 1</label>
<input type="file" name="accessory1_ico" />
<input type="text" name="accessory1_name" /><br />
<label for="accessory2_name">Accessory 2</label>
<input type="file" name="accessory2_ico" />
<input type="text" name="accessory2_name" /><br />
<h2>Generate</h2>
<input type="submit" value="Generate">
</form>

2
yqtemplate.lua

@ -33,7 +33,7 @@ return {
end
fcgi.print(
form {
encoder = utils.tobase64,
encoder = require"base64".encode,
args = args,
classes = {
"Beast",

Loading…
Cancel
Save