1
2
3
4
5
6
7
8
9
10
..
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
..
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
..
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
...
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
...
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
|
-- vim: ft=terra
local pstr = lib.str.t
local P = lib.str.plit
local terra cs(s: rawstring)
return pstr { ptr = s, ct = lib.str.sz(s) }
end
local show_all,show_new,show_unfiled,show_files,show_vid,show_img=1,2,3,4,5,6
local terra
................................................................................
var pa = co:stra(32)
pa:lpush('/')
if ou(0).origin ~= 0 then pa:lpush('@') end
pa:push(ou(0).xid,0)
pfx = pa:finalize()
end
if path.ct >= 3 and path(1):cmp(lib.str.lit'a') then
var id, idok = lib.math.shorthand.parse(path(2).ptr, path(2).ct)
if not idok then goto e404 end
var art = co.srv:artifact_fetch(uid, id)
if not art then goto e404 end
if path.ct == 3 then
-- sniff out the artifact type and display the appropriate viewer
var artid = cs(art(0).url)
................................................................................
pfx = pfx, desc = desc;
id = artid; btns = btntxt;
}
if lib.str.ncmp(art(0).mime, 'image/', 6) == 0 then
var view = data.view.media_image(viewerprops)
var pg = view:poolstr(&co.srv.pool)
co:stdpage([lib.srv.convo.page] {
title = lib.str.plit'media :: image';
class = lib.str.plit'media viewer img';
cache = false, body = pg;
})
--pg:free()
elseif lib.str.cmp(art(0).mime, 'text/markdown') == 0 then
var view = data.view.media_text(viewerprops)
var text, mime = co.srv:artifact_load(id) mime:free()
view.text = lib.smackdown.html(&co.srv.pool, pstr{[rawstring](text.ptr),text.ct}, false)
text:free()
var pg = view:poolstr(&co.srv.pool)
--view.text:free()
co:stdpage([lib.srv.convo.page] {
title = lib.str.plit'media :: text';
class = lib.str.plit'media viewer text';
cache = false, body = pg;
})
--pg:free()
elseif
lib.str.ncmp(art(0).mime, 'text/', 5) == 0 or
lib.str.cmp(art(0).mime, 'application/x-perl') == 0 or
lib.str.cmp(art(0).mime, 'application/sql') == 0
................................................................................
var san = lib.html.sanitize(&co.srv.pool,pstr{[rawstring](text.ptr),text.ct}, false)
text:free()
view.text = co:qstr('<pre>',san,'</pre>')
--san:free()
var pg = view:poolstr(&co.srv.pool)
--view.text:free()
co:stdpage([lib.srv.convo.page] {
title = lib.str.plit'media :: text';
class = lib.str.plit'media viewer text';
cache = false, body = pg;
})
--pg:free()
else co:complain(500,'bad file type','this file type is not supported') end
elseif path.ct == 4 then
var act = path(3)
var curl = co:qstr('/media/a/', path(2))
-- defer curl:free()
if act:cmp(lib.str.lit'avi') and lib.str.ncmp(art(0).mime, 'image/', 6) == 0 then
co:confirm('set avatar', 'are you sure you want this image to be your new avatar?',curl)
elseif act:cmp(lib.str.lit'del') then
co:confirm('delete', 'are you sure you want to permanently delete this artifact?',curl)
else goto e404 end
end
else
var mode: uint8 = show_new
var folder: pstr
if path.ct == 2 then
if path(1):cmp(lib.str.lit'unfiled') then
mode=show_unfiled
elseif path(1):cmp(lib.str.lit'all') then
mode=show_all
else goto e404 end
elseif path.ct == 3 and path(1):cmp(lib.str.lit'kind') then
end
var folders = co.srv:artifact_folder_enum(uid)
if mode == show_new then
folder = lib.str.plit''
elseif mode == show_all or mode == show_unfiled then
folder = pstr.null()
end
var view = data.view.media_gallery {
menu = pstr{'',0};
folders = pstr{'',0};
................................................................................
end
fa:lpush('<hr>')
view.folders = fa:finalize()
folders:free()
end
if owner then
view.menu = P'<a class="pos" href="/media/upload">upload</a><hr>'
end
var md = co.srv:artifact_enum_uid(uid, folder)
var gallery: lib.str.acc gallery:pool(&co.srv.pool,256)
var files: lib.str.acc files:pool(&co.srv.pool,256)
for i=0,md.ct do
var desc = lib.smackdown.html(&co.srv.pool,pstr{md(i)(0).desc,0}, true) --defer desc:free()
................................................................................
view.directory = files:finalize()
if acc ~= nil then
view:append(acc)
else
var pg = view:poolstr(&co.srv.pool) -- defer pg:free()
co:stdpage([lib.srv.convo.page] {
title = P'media';
class = P'media manager';
cache = false;
body = pg;
})
end
--view.images:free()
--view.directory:free()
|
<
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1
2
3
4
5
6
7
8
9
..
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
..
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
..
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
...
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
...
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
|
-- vim: ft=terra
local pstr = lib.str.t
local terra cs(s: rawstring)
return pstr { ptr = s, ct = lib.str.sz(s) }
end
local show_all,show_new,show_unfiled,show_files,show_vid,show_img=1,2,3,4,5,6
local terra
................................................................................
var pa = co:stra(32)
pa:lpush('/')
if ou(0).origin ~= 0 then pa:lpush('@') end
pa:push(ou(0).xid,0)
pfx = pa:finalize()
end
if path.ct >= 3 and path(1):cmp('a') then
var id, idok = lib.math.shorthand.parse(path(2).ptr, path(2).ct)
if not idok then goto e404 end
var art = co.srv:artifact_fetch(uid, id)
if not art then goto e404 end
if path.ct == 3 then
-- sniff out the artifact type and display the appropriate viewer
var artid = cs(art(0).url)
................................................................................
pfx = pfx, desc = desc;
id = artid; btns = btntxt;
}
if lib.str.ncmp(art(0).mime, 'image/', 6) == 0 then
var view = data.view.media_image(viewerprops)
var pg = view:poolstr(&co.srv.pool)
co:stdpage([lib.srv.convo.page] {
title = 'media :: image';
class = 'media viewer img';
cache = false, body = pg;
})
--pg:free()
elseif lib.str.cmp(art(0).mime, 'text/markdown') == 0 then
var view = data.view.media_text(viewerprops)
var text, mime = co.srv:artifact_load(id) mime:free()
view.text = lib.smackdown.html(&co.srv.pool, pstr{[rawstring](text.ptr),text.ct}, false)
text:free()
var pg = view:poolstr(&co.srv.pool)
--view.text:free()
co:stdpage([lib.srv.convo.page] {
title = 'media :: text';
class = 'media viewer text';
cache = false, body = pg;
})
--pg:free()
elseif
lib.str.ncmp(art(0).mime, 'text/', 5) == 0 or
lib.str.cmp(art(0).mime, 'application/x-perl') == 0 or
lib.str.cmp(art(0).mime, 'application/sql') == 0
................................................................................
var san = lib.html.sanitize(&co.srv.pool,pstr{[rawstring](text.ptr),text.ct}, false)
text:free()
view.text = co:qstr('<pre>',san,'</pre>')
--san:free()
var pg = view:poolstr(&co.srv.pool)
--view.text:free()
co:stdpage([lib.srv.convo.page] {
title = 'media :: text';
class = 'media viewer text';
cache = false, body = pg;
})
--pg:free()
else co:complain(500,'bad file type','this file type is not supported') end
elseif path.ct == 4 then
var act = path(3)
var curl = co:qstr('/media/a/', path(2))
-- defer curl:free()
if act:cmp('avi') and lib.str.ncmp(art(0).mime, 'image/', 6) == 0 then
co:confirm('set avatar', 'are you sure you want this image to be your new avatar?',curl)
elseif act:cmp('del') then
co:confirm('delete', 'are you sure you want to permanently delete this artifact?',curl)
else goto e404 end
end
else
var mode: uint8 = show_new
var folder: pstr
if path.ct == 2 then
if path(1):cmp('unfiled') then
mode=show_unfiled
elseif path(1):cmp('all') then
mode=show_all
else goto e404 end
elseif path.ct == 3 and path(1):cmp('kind') then
end
var folders = co.srv:artifact_folder_enum(uid)
if mode == show_new then
folder = ''
elseif mode == show_all or mode == show_unfiled then
folder = pstr.null()
end
var view = data.view.media_gallery {
menu = pstr{'',0};
folders = pstr{'',0};
................................................................................
end
fa:lpush('<hr>')
view.folders = fa:finalize()
folders:free()
end
if owner then
view.menu = '<a class="pos" href="/media/upload">upload</a><hr>'
end
var md = co.srv:artifact_enum_uid(uid, folder)
var gallery: lib.str.acc gallery:pool(&co.srv.pool,256)
var files: lib.str.acc files:pool(&co.srv.pool,256)
for i=0,md.ct do
var desc = lib.smackdown.html(&co.srv.pool,pstr{md(i)(0).desc,0}, true) --defer desc:free()
................................................................................
view.directory = files:finalize()
if acc ~= nil then
view:append(acc)
else
var pg = view:poolstr(&co.srv.pool) -- defer pg:free()
co:stdpage([lib.srv.convo.page] {
title = 'media';
class = 'media manager';
cache = false;
body = pg;
})
end
--view.images:free()
--view.directory:free()
|