parsav  Diff

Differences From Artifact [e8c2143a0c]:

To Artifact [af3d41e739]:


1
2
3
4
5

6
7
8
9
10
11
12
...
395
396
397
398
399
400
401
402


































































403
404
405
406
407
408
409
...
483
484
485
486
487
488
489


490
491
492
493
494
495
496
-- vim: ft=terra
local r = lib.srv.route
local method = lib.http.method
local pstring = lib.mem.ptr(int8)
local rstring = lib.mem.ref(int8)

local hpath = lib.mem.ptr(rstring)
local http = {}

terra meth_get(meth: method.t) return (meth == method.get) or (meth == method.head) end

terra http.actor_profile(co: &lib.srv.convo, actor: &lib.store.actor, meth: method.t)
	var rel: lib.store.relationship
................................................................................
			return
		else goto badop end
	end

	lib.render.notices(co)
	do return end

	::badop :: do co:complain(405, 'invalid operation', 'the operation you have attempted on this post is not meaningful') return end


































































end

do local branches = quote end
	local filename, flen = symbol(&int8), symbol(intptr)
	local page = symbol(lib.http.page)
	local send = label()
	local storage = data.stmap
................................................................................
		var path = lib.http.hier(uri) defer path:free()
		if path.ct > 1 and path(0):cmp(lib.str.lit('user')) then
			http.actor_profile_uid(co, path, meth)
		elseif path.ct > 1 and path(0):cmp(lib.str.lit('post')) then
			http.tweet_page(co, path, meth)
		elseif path(0):cmp(lib.str.lit('tl')) then
			http.timeline(co, path)


		elseif path(0):cmp(lib.str.lit('doc')) then
			if not meth_get(meth) then goto wrongmeth end
			http.documentation(co, path)
		elseif path(0):cmp(lib.str.lit('conf')) then
			if co.aid == 0 then goto unauth end
			http.configure(co,path,meth)
		else goto notfound end





>







 







|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







>
>







1
2
3
4
5
6
7
8
9
10
11
12
13
...
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
...
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
-- vim: ft=terra
local r = lib.srv.route
local method = lib.http.method
local pstring = lib.mem.ptr(int8)
local rstring = lib.mem.ref(int8)
local binblob = lib.mem.ptr(uint8)
local hpath = lib.mem.ptr(rstring)
local http = {}

terra meth_get(meth: method.t) return (meth == method.get) or (meth == method.head) end

terra http.actor_profile(co: &lib.srv.convo, actor: &lib.store.actor, meth: method.t)
	var rel: lib.store.relationship
................................................................................
			return
		else goto badop end
	end

	lib.render.notices(co)
	do return end

	::badop:: do co:complain(405, 'invalid operation', 'the operation you have attempted on this post is not meaningful') return end
end

terra http.media_manager(co: &lib.srv.convo, path: hpath, meth: method.t)
	if meth == method.post then
		goto badop
	end

	if path.ct == 1 or (path.ct >= 3 and path(1):cmp(lib.str.lit'a')) then
		if meth == method.post then goto badop end
		lib.render.media_gallery(co,path,co.who.id,nil)
	elseif path.ct == 2 then
		if path(1):cmp(lib.str.lit'upload') and co.who.rights.powers.artifact() then
			if meth == method.get then
				var view = data.view.media_upload {
					folders = ''
				}
				var pg = view:tostr() defer pg:free()
				co:stdpage([lib.srv.convo.page] {
					title = lib.str.plit'media :: upload';
					class = lib.str.plit'media upload';
					cache = false; body = pg;
				})
			elseif meth == method.post_file then
				var desc = pstring.null()
				var folder = pstring.null()
				var mime = pstring.null()
				var name = pstring.null()
				var body = binblob.null()
				for i=0, co.uploads.sz do var up = co.uploads.storage.ptr + i
					if up.body.ct > 0 then
						if up.field:cmp(lib.str.plit'desc') then
							desc = up.body
						elseif up.field:cmp(lib.str.plit'folder') then
							folder = up.body
						elseif up.field:cmp(lib.str.plit'file') then
							mime = up.ctype
							body = binblob {ptr = [&uint8](up.body.ptr), ct = up.body.ct}
							name = up.filename
						end
					end
				end
				if not body then goto badop end
				if body.ct > co.srv.cfg.maxupsz then
					co:complain(403, 'file too long', "the file you have attempted to upload exceeds the maximum length permitted by this server's upload policy. if it is an image or video, try compressing it at a lower quality setting or resolution")
					return
				end
				var id = co.srv:artifact_instantiate(body,mime)
				if id == 0 then
					co:complain(500,'upload failed','artifact rejected. either the server is running out of space or this file is banned from the server')
					return
				end
				co.srv:artifact_expropriate(co.who.id,id,desc,folder)

				var idbuf: int8[lib.math.shorthand.maxlen]
				var idlen = lib.math.shorthand.gen(id,&idbuf[0])

				var url = lib.str.acc{}:compose('/media/a/',pstring{&idbuf[0],idlen}):finalize()
				co:reroute(url.ptr)
				url:free()
			else goto badop end
		end
	else goto e404 end
	do return end

	::badop:: do co:complain(405, 'invalid operation', 'the operation you have attempted on this post is not meaningful') return end
	::e404:: do co:complain(404, 'artifact not found', 'no such artifact has been uploaded by this user') return end
end

do local branches = quote end
	local filename, flen = symbol(&int8), symbol(intptr)
	local page = symbol(lib.http.page)
	local send = label()
	local storage = data.stmap
................................................................................
		var path = lib.http.hier(uri) defer path:free()
		if path.ct > 1 and path(0):cmp(lib.str.lit('user')) then
			http.actor_profile_uid(co, path, meth)
		elseif path.ct > 1 and path(0):cmp(lib.str.lit('post')) then
			http.tweet_page(co, path, meth)
		elseif path(0):cmp(lib.str.lit('tl')) then
			http.timeline(co, path)
		elseif path(0):cmp(lib.str.lit('media')) then
			http.media_manager(co, path, meth)
		elseif path(0):cmp(lib.str.lit('doc')) then
			if not meth_get(meth) then goto wrongmeth end
			http.documentation(co, path)
		elseif path(0):cmp(lib.str.lit('conf')) then
			if co.aid == 0 then goto unauth end
			http.configure(co,path,meth)
		else goto notfound end