parsav  Diff

Differences From Artifact [56f7ddd740]:

To Artifact [1bb0eb41f3]:


   284    284   	else
   285    285   		co:complain(404, 'no such documentation', 'invalid documentation URL')
   286    286   	end
   287    287   end
   288    288   
   289         -terra http.tweet_page(co: &lib.srv.convo, path: hpath, meth: method.t)
          289  +terra http.tweet_page(co: &lib.srv.convo, path: hpath)
   290    290   	var pid, ok = lib.math.shorthand.parse(path(1).ptr, path(1).ct)
   291    291   	if not ok then
   292    292   		co:complain(400, 'bad post ID', 'that post ID is not valid')
   293    293   		return
   294    294   	end
................................................................................
   308    308   
   309    309   	if path.ct == 3 then
   310    310   		var lnk: lib.str.acc lnk:compose('/post/', path(1))
   311    311   		var lnkp = lnk:finalize() defer lnkp:free()
   312    312   		if post:ref() and path(2):cmp(lib.str.lit 'snitch') then
   313         -			if meth_get(meth) then
          313  +			if meth_get(co.method) then
   314    314   				var ui = data.view.report {
   315    315   					badtweet = lib.render.tweet(co, post.ptr, nil);
   316    316   					clnk = lnkp;
   317    317   				}
   318    318   
................................................................................
   328    328   		elseif post:ref() and post(0).author ~= co.who.id then
   329    329   			co:complain(403, 'forbidden', 'you cannot alter other people\'s posts')
   330    330   			return
   331    331   		elseif post:ref() and path(2):cmp(lib.str.lit 'edit') then
   332    332   			if not co:assertpow('edit') then return end
   333         -			if meth_get(meth) then
          333  +			if meth_get(co.method) then
   334    334   				lib.render.compose(co, post.ptr, nil)
   335    335   				return
   336         -			elseif meth == method.post then
          336  +			elseif co.method == method.post then
   337    337   				var newbody = co:postv('post')._0
   338    338   				var newacl = co:postv('acl')._0
   339    339   				var newsubj = co:postv('subject')._0
   340    340   				if newbody ~= nil then post(0).body = newbody end
   341    341   				if newacl  ~= nil then post(0).acl = newacl end
................................................................................
   343    343   				post(0):save(true)
   344    344   				co:reroute(lnkp.ptr)
   345    345   			end
   346    346   			return
   347    347   		elseif path(2):cmp(lib.str.lit 'del') then
   348         -			if meth_get(meth) then
          348  +			if meth_get(co.method) then
   349    349   				var conf: data.view.confirm
   350    350   				if post:ref() then
   351    351   					conf = data.view.confirm {
   352         -						title =  'delete post';
   353         -						query =  'are you sure you want to delete this post?';
          352  +						title = 'delete post';
          353  +						query = 'are you sure you want to delete this post?';
   354    354   						cancel = lnkp
   355    355   					}
   356    356   				else
   357    357   					conf = data.view.confirm {
   358         -						title =  'cancel retweet';
   359         -						query =  'are you sure you want to undo this retweet?';
          358  +						title = 'cancel retweet';
          359  +						query = 'are you sure you want to undo this retweet?';
   360    360   						cancel = '/';
   361    361   					}
   362    362   				end
   363    363   				var body = conf:poolstr(&co.srv.pool) --defer body:free()
   364    364   				co:stdpage([lib.srv.convo.page] {
   365         -					title =  'post :: delete';
   366         -					class =  'query';
          365  +					title = 'post :: delete';
          366  +					class = 'query';
   367    367   					body = body; cache = false;
   368    368   				})
   369    369   				return
   370         -			elseif meth == method.post then
          370  +			elseif co.method == method.post then
   371    371   				var act = co:ppostv('act')
   372    372   				if act:cmp('confirm') then
   373    373   					if post:ref() then
   374    374   						post().source:post_destroy(post().id)
   375    375   					elseif rt.kind ~= 0 then
................................................................................
   380    380   				else goto badop end
   381    381   			end
   382    382   		else goto badurl end
   383    383   	end
   384    384   
   385         -	if post:ref() and meth == method.post then
          385  +	if post:ref() and co.method == method.post then
   386    386   		if co.aid == 0 then goto noauth end
   387    387   		var act = co:ppostv('act')
   388         -		if act:cmp( 'like') and not co.srv:post_liked_uid(co.who.id,pid) then
          388  +		if act:cmp('like') and not co.srv:post_liked_uid(co.who.id,pid) then
   389    389   			co.srv:post_like(co.who.id, pid, false)
   390    390   			post.ptr.likes = post.ptr.likes + 1
   391         -		elseif act:cmp( 'dislike') and co.srv:post_liked_uid(co.who.id,pid) then
          391  +		elseif act:cmp('dislike') and co.srv:post_liked_uid(co.who.id,pid) then
   392    392   			co.srv:post_like(co.who.id, pid, true)
   393    393   			post.ptr.likes = post.ptr.likes - 1
   394         -		elseif act:cmp( 'rt') then
          394  +		elseif act:cmp('rt') then
   395    395   			co.srv:post_retweet(co.who.id, pid, false)
   396    396   			post.ptr.rts = post.ptr.rts + 1
   397         -		elseif act:cmp( 'post') then
          397  +		elseif act:cmp('post') then
   398    398   			var replytext = co:ppostv('post')
   399    399   			var acl = co:ppostv('acl')
   400    400   			var subj = co:ppostv('subject')
   401         -			if not acl then acl =  'all' end
          401  +			if not acl then acl = 'all' end
   402    402   			if not replytext then goto badop end
   403    403   			
   404    404   			var reply = lib.store.post {
   405    405   				author = co.who.id, parent = pid;
   406    406   				subject = subj.ptr, acl = acl.ptr, body = replytext.ptr;
................................................................................
   410    410   		else goto badop end
   411    411   	end
   412    412   
   413    413   	if not post then goto badurl end
   414    414   
   415         -	lib.render.tweet_page(co, path, post.ptr)
          415  +	if co:matchmime(lib.http.mime.html) then
          416  +		lib.render.tweet_page(co, path, post.ptr)
          417  +	elseif co:matchmime(lib.http.mime.json) then
          418  +		co:json(lib.api.lp.tweet(co, post.ptr, false))
          419  +	else goto notacc end
   416    420   	do return end
   417    421   
   418    422   	::noauth:: do co:fail(401) return end
   419    423   	::badurl:: do co:fail(404) return end
   420    424   	::badop :: do co:fail(405) return end
          425  +	::notacc:: do co:fail(406) return end
   421    426   end
   422    427   
   423    428   local terra 
   424    429   credsec_for_uid(co: &lib.srv.convo, uid: uint64)
   425    430   	var act = co:ppostv('act')
................................................................................
   467    472   			if not lib.math.truncate64(hmac.ptr, hmac.ct) == noncevld then
   468    473   				co:complain(403,'nice try','what exactly are you trying to accomplish here, buddy')
   469    474   				return false
   470    475   			end
   471    476   
   472         -			var pkres = lib.crypt.loadpub(rsapub.ptr,rsapub.ct+1) -- needs NUL
          477  +			var pkres = lib.crypt.loadpub(binblob{rsapub.ptr,rsapub.ct+1}) -- needs NUL
   473    478   			if not pkres.ok then
   474    479   				co:complain(400,'invalid key','the key you have supplied is not a valid PEM or DER file')
   475    480   				return false
   476    481   			end
   477    482   			var pk = pkres.val
................................................................................
   974    979   	else -- hierarchical routes
   975    980   		var path = lib.http.hier(&co.srv.pool, uri) --defer path:free()
   976    981   		if path.ct > 1 and path(0):cmp('user') then
   977    982   			http.actor_profile_uid(co, path)
   978    983   		elseif path.ct > 1 and path(0):cmp('post') then
   979         -			http.tweet_page(co, path, meth)
          984  +			http.tweet_page(co, path)
   980    985   		elseif path(0):cmp('tl') then
   981    986   			http.timeline(co, path)
   982    987   		elseif path(0):cmp('.well-known') then
   983    988   			if path(1):cmp('webfinger') then
   984    989   				if not co:matchmime(lib.http.mime.json) then goto nacc end