parsav  Diff

Differences From Artifact [18e4a71c1d]:

To Artifact [1f18c83945]:


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