Mercurial Hosting > linkmystyle
comparison src/add_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 Io = require "luan:Io.luan" | |
4 local Http = require "luan:http/Http.luan" | |
5 local Db = require "site:/lib/Db.luan" | |
6 local run_in_transaction = Db.run_in_transaction or error() | |
7 local Pic = require "site:/lib/Pic.luan" | |
8 local get_user_pics = Pic.get_user_pics or error() | |
9 local User = require "site:/lib/User.luan" | |
10 | |
11 | |
12 return function() | |
13 local user = User.current() or error() | |
14 local title = Http.request.parameters.title or error() | |
15 local is_hidden = Http.request.parameters.visible == nil | |
16 local uuid = Http.request.parameters.uuid or error() | |
17 local filename = Http.request.parameters.filename or error() | |
18 local pic | |
19 run_in_transaction( function() | |
20 local pics = get_user_pics(user.id) | |
21 pic = Pic.new{ | |
22 uuid = uuid | |
23 filename = filename | |
24 user_id = user.id | |
25 title = title | |
26 is_hidden = is_hidden | |
27 order = #pics > 0 and pics[1].order - 1 or 0 | |
28 } | |
29 pic.save() | |
30 end ) | |
31 Io.stdout = Http.response.text_writer() | |
32 %> | |
33 mixpanel.ours.track( 'Add Pic', null, {send_immediately:true} ); | |
34 location = '/links.html?saved&pic=<%=pic.id%>'; | |
35 <% | |
36 end |