Mercurial Hosting > linkmystyle
comparison src/save_link.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 Link = require "site:/lib/Link.luan" | |
8 local Shared = require "site:/lib/Shared.luan" | |
9 local show_editable_link = Shared.show_editable_link or error() | |
10 local User = require "site:/lib/User.luan" | |
11 local Db = require "site:/lib/Db.luan" | |
12 local run_in_transaction = Db.run_in_transaction or error() | |
13 | |
14 | |
15 return function() | |
16 local user = User.current() or error() | |
17 local link_id = Http.request.parameters.link or error() | |
18 local url = Http.request.parameters.url or error() | |
19 local title = Http.request.parameters.title or error() | |
20 local link = Link.get_by_id(link_id) | |
21 link.user_id == user.id or error() | |
22 run_in_transaction( function() | |
23 link = link.reload() | |
24 link.url = url | |
25 link.title = title | |
26 link.save() | |
27 end ) | |
28 local html = ` show_editable_link(link) ` | |
29 Io.stdout = Http.response.text_writer() | |
30 %> | |
31 document.querySelector('div[link="<%=link_id%>"]').outerHTML = <%= json_string(html) %>; | |
32 dragInit(); | |
33 <% | |
34 end |