Differences From
Artifact [79b3557b2e]:
1 1 -- vim: ft=terra
2 2 local pstr = lib.str.t
3 3 local P = lib.str.plit
4 4 local terra cs(s: rawstring)
5 5 return pstr { ptr = s, ct = lib.str.sz(s) }
6 6 end
7 7
8 -local show_all,show_new,show_files,show_vid,show_img=1,2,3,4,5
8 +local show_all,show_new,show_unfiled,show_files,show_vid,show_img=1,2,3,4,5,6
9 9
10 10 local terra
11 11 render_media_gallery(co: &lib.srv.convo, path: lib.mem.ptr(lib.mem.ref(int8)), uid: uint64, acc: &lib.str.acc)
12 12 -- note that when calling this function, path must be adjusted so that path(0)
13 13 -- eq "media"
14 14 var owner = false
15 15 if co.aid ~= 0 and co.who.id == uid then owner = true end
16 16 var ou = co.srv:actor_fetch_uid(uid)
17 17 if not ou then goto e404 end
18 +
19 + var mode: uint8 = show_new
20 + var folder: pstr
21 + if path.ct == 2 then
22 + if path(1):cmp(lib.str.lit'unfiled') then
23 + mode=show_unfiled
24 + elseif path(1):cmp(lib.str.lit'all') then
25 + mode=show_all
26 + else goto e404 end
27 + elseif path.ct == 3 and path(1):cmp(lib.str.lit'kind') then
28 + end
29 +
30 + if mode == show_new then
31 + folder = lib.str.plit''
32 + elseif mode == show_all then
33 + folder = pstr.null()
34 + elseif mode == show_unfiled then
35 + folder = lib.str.plit'' -- TODO
36 + -- else get folder from query str
37 + end
18 38
19 39 var view = data.view.media_gallery {
20 40 menu = pstr{'',0};
21 41 folders = pstr{'',0};
22 42 directory = pstr{'',0};
23 43 images = pstr{'',0};
44 + pfx = pstr{'',0};
24 45 }
46 + if not owner then
47 + var pa: lib.str.acc pa:init(32)
48 + pa:lpush('/')
49 + if ou(0).origin ~= 0 then pa:lpush('@') end
50 + pa:push(ou(0).xid,0)
51 + view.pfx = pa:finalize()
52 + end
25 53
26 54 if owner then
27 55 view.menu = P'<a class="pos" href="/media/upload">upload</a><hr>'
28 56 end
29 - var mode: uint8 = show_new
30 - var folder: pstr
31 - if mode == show_new then
32 - folder = lib.str.plit''
33 - elseif mode == show_all then
34 - folder = pstr.null()
35 - -- else get folder from query str
36 - end
37 57
38 58 var md = co.srv:artifact_enum_uid(uid, folder)
39 59 var gallery: lib.str.acc gallery:init(256)
40 60 var files: lib.str.acc files:init(256)
41 61 for i=0,md.ct do
42 62 if lib.str.ncmp(md(i)(0).mime, 'image/', 6) == 0 then
43 - gallery:lpush('<a class="thumb" href="')
44 - if not owner then
45 - gallery:lpush('/')
46 - if ou(0).origin ~= 0 then gallery:lpush('@') end
47 - gallery:push(ou(0).xid,0):lpush('/')
48 - end
49 - gallery:push(md(i)(0).url,0)
50 - :lpush('"><img src="') :push(md(i)(0).url,0)
51 - :lpush('/raw"><div class="caption">') :push(md(i)(0).desc,0)
63 + gallery:lpush('<a class="thumb" href="'):ppush(view.pfx):lpush('/media/a/')
64 + :push(md(i)(0).url,0):lpush('"><img src="/file/'):push(md(i)(0).url,0)
65 + :lpush('"><div class="caption">'):push(md(i)(0).desc,0)
52 66 :lpush('</div></a>')
53 67 else
54 - files:lpush('<a class="file" href="')
55 - if not owner then
56 - gallery:lpush('/')
57 - if ou(0).origin ~= 0 then gallery:lpush('@') end
58 - gallery:push(ou(0).xid,0):lpush('/')
59 - end
60 - files:push(md(i)(0).url,0)
61 - :lpush('"><span class="label">'):push(md(i)(0).desc,0)
68 + files:lpush('<a class="file" href="'):ppush(view.pfx):lpush('/media/a/')
69 + :push(md(i)(0).url,0):lpush('"><span class="label">'):push(md(i)(0).desc,0)
62 70 :lpush('</span> <span class="mime">'):push(md(i)(0).mime,0)
63 71 :lpush('</span></a>')
64 72 end
65 73 md(i):free()
66 74 end
67 75
68 76 view.images = gallery:finalize()
69 77 view.directory = files:finalize()
70 78
71 79 if acc ~= nil then
72 80 view:append(acc)
73 81 else
82 + lib.dbg('emitting page')
74 83 var pg = view:tostr() defer pg:free()
84 + lib.dbg('compiled page')
75 85 co:stdpage([lib.srv.convo.page] {
76 86 title = P'media';
77 87 class = P'media manager';
78 88 cache = false;
79 89 body = pg;
80 90 })
91 + lib.dbg('sent page')
81 92 end
82 93
83 94 view.images:free()
84 95 view.directory:free()
96 + if not owner then view.pfx:free() end
85 97 if md:ref() then md:free() end
86 98 do return end
87 99
88 100 ::e404:: co:complain(404,'media not found','no such media exists on this server')
89 101 end
90 102
91 103 return render_media_gallery