Index: backend/pgsql.t ================================================================== --- backend/pgsql.t +++ backend/pgsql.t @@ -1589,23 +1589,38 @@ var idbuf: int8[lib.math.shorthand.maxlen] var idlen = lib.math.shorthand.gen(id, &idbuf[0]) var desc = res:_string(i,2) var folder = res:_string(i,3) var mime = res:_string(i,4) - var url = lib.str.acc{}:init(48):lpush('/media/a/'):push(&idbuf[0],idlen):finalize() defer url:free() m.ptr[i] = [ lib.str.encapsulate(lib.store.artifact, { desc = {`desc.ptr, `desc.ct + 1}; folder = {`folder.ptr, `folder.ct + 1}; mime = {`mime.ptr, `mime.ct + 1}; - url = {`url.ptr, `url.ct + 1}; + url = {`&idbuf[0], `idlen + 1}; }) ] m(i).ptr.rid = id m(i).ptr.owner = uid end return m else return [lib.mem.lstptr(lib.store.artifact)].null() end end]; + + artifact_load = [terra( + src: &lib.store.source, + rid: uint64 + ): {binblob, pstring} + var r = queries.artifact_load.exec(src,rid) + if r.sz == 0 then return binblob.null(), pstring.null() end + + var mime = r:String(0,1) + var mbin = r:bin(0,0) + var bin = lib.mem.heapa(uint8,mbin.ct) + lib.mem.cpy(bin.ptr, mbin.ptr, bin.ct) + + r:free() + return bin, mime + end]; post_attach_ctl = [terra( src: &lib.store.source, post: uint64, artifact: uint64, Index: math.t ================================================================== --- math.t +++ math.t @@ -226,38 +226,40 @@ if f(i) == @',' then goto skip end if f(i) >= 0x30 and f(i) <= 0x39 then sz = sz * 10 sz = sz + f(i) - 0x30 else - if i+1 == f.ct or f(i) == 0 then return sz, true end - if i+2 == f.ct or f(i+1) == 0 then + if i+0 == f.ct or f(i) == 0 then return sz, true end + if i+1 == f.ct or f(i+1) == 0 then if f(i) == @'b' then return sz/8, true end -- bits else var s: intptr = 0 - if i+3 == f.ct or f(i+2) == 0 then + if i+2 == f.ct or f(i+2) == 0 then s = i + 1 - elseif (i+4 == f.ct or f(i+3) == 0) and f(i+1) == @'i' then + elseif (i+3 == f.ct or f(i+3) == 0) and f(i+1) == @'i' then -- grudgingly tolerate ~mebibits~ and its ilk, without -- affecting the result in any way s = i + 2 else return 0, false end if f(s) == @'b' then sz = sz/8 -- bits elseif f(s) ~= @'B' then return 0, false end -- wth end var c = f(i) - if c >= @'A' and c <= @'Z' then c = c - 0x20 end + if c >= @'A' and c <= @'Z' then c = c + 0x20 end switch c do -- normal char literal syntax doesn't work here, leads to llvm error (!!) case [uint8]([string.byte('k')]) then return sz * [1024ULL ^ 1], true end case [uint8]([string.byte('m')]) then return sz * [1024ULL ^ 2], true end case [uint8]([string.byte('g')]) then return sz * [1024ULL ^ 3], true end case [uint8]([string.byte('t')]) then return sz * [1024ULL ^ 4], true end - case [uint8]([string.byte('e')]) then return sz * [1024ULL ^ 5], true end - case [uint8]([string.byte('y')]) then return sz * [1024ULL ^ 6], true end - else return sz, true + case [uint8]([string.byte('p')]) then return sz * [1024ULL ^ 5], true end + case [uint8]([string.byte('e')]) then return sz * [1024ULL ^ 6], true end + case [uint8]([string.byte('z')]) then return sz * [1024ULL ^ 7], true end + case [uint8]([string.byte('y')]) then return sz * [1024ULL ^ 8], true end + else return 0, false end end ::skip::end return sz, true end return m Index: render/media-gallery.t ================================================================== --- render/media-gallery.t +++ render/media-gallery.t @@ -3,64 +3,72 @@ 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_files,show_vid,show_img=1,2,3,4,5 +local show_all,show_new,show_unfiled,show_files,show_vid,show_img=1,2,3,4,5,6 local terra render_media_gallery(co: &lib.srv.convo, path: lib.mem.ptr(lib.mem.ref(int8)), uid: uint64, acc: &lib.str.acc) -- note that when calling this function, path must be adjusted so that path(0) -- eq "media" var owner = false if co.aid ~= 0 and co.who.id == uid then owner = true end var ou = co.srv:actor_fetch_uid(uid) if not ou then goto e404 end + + 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 + + if mode == show_new then + folder = lib.str.plit'' + elseif mode == show_all then + folder = pstr.null() + elseif mode == show_unfiled then + folder = lib.str.plit'' -- TODO + -- else get folder from query str + end var view = data.view.media_gallery { menu = pstr{'',0}; folders = pstr{'',0}; directory = pstr{'',0}; images = pstr{'',0}; + pfx = pstr{'',0}; } + if not owner then + var pa: lib.str.acc pa:init(32) + pa:lpush('/') + if ou(0).origin ~= 0 then pa:lpush('@') end + pa:push(ou(0).xid,0) + view.pfx = pa:finalize() + end if owner then view.menu = P'upload