Mercurial Hosting > linkmystyle
comparison src/change_pic.js.luan @ 0:8f4df159f06b
start public repo
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Fri, 11 Jul 2025 20:57:49 -0600 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:8f4df159f06b |
---|---|
1 local Luan = require "luan:Luan.luan" | |
2 local error = Luan.error | |
3 local Parsers = require "luan:Parsers.luan" | |
4 local json_string = Parsers.json_string or error() | |
5 local Io = require "luan:Io.luan" | |
6 local Http = require "luan:http/Http.luan" | |
7 local Pic = require "site:/lib/Pic.luan" | |
8 local User = require "site:/lib/User.luan" | |
9 local Db = require "site:/lib/Db.luan" | |
10 local run_in_transaction = Db.run_in_transaction or error() | |
11 | |
12 | |
13 return function() | |
14 local user = User.current() or error() | |
15 local pic_id = Http.request.parameters.pic or error() | |
16 local uuid = Http.request.parameters.uuid or error() | |
17 local filename = Http.request.parameters.filename or error() | |
18 local pic = Pic.get_by_id(pic_id) | |
19 pic.user_id == user.id or error() | |
20 run_in_transaction( function() | |
21 pic = pic.reload() | |
22 pic.uuid = uuid | |
23 pic.filename = filename | |
24 pic.save() | |
25 end ) | |
26 Io.stdout = Http.response.text_writer() | |
27 %> | |
28 document.querySelector('div[pic] img').src = <%= json_string(pic.get_url()) %>; | |
29 <% | |
30 end |