parsav  Diff

Differences From Artifact [80ca2205e4]:

To Artifact [5d4cebec04]:


477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
...
529
530
531
532
533
534
535





















536
537
538
539
540
541
542
....
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546







































1547
1548
1549
1550
1551
1552
1553
			limit case when $4::bigint = 0 then null
					   else $4::bigint end
			offset $5::bigint
		]];
	};

	artifact_instantiate = {
		params = {binblob, binblob, pstring}, sql = [[
			insert into parsav_artifacts (content,hash,mime) values (
				$1::bytea, $2::bytea, $3::text
			) on conflict do nothing returning id
		]];
	};
	artifact_expropriate = {
		params = {uint64, uint64, pstring}, cmd = true, sql = [[
			insert into parsav_artifact_claims (uid,rid,description,folder) values (
				$1::bigint, $2::bigint, $3::text, 'new'
			) on conflict do nothing
		]];
	};
	artifact_quicksearch = {
		params = {binblob}, sql = [[
			select id, (content is null) from parsav_artifacts where hash = $1::bytea
				limit 1
................................................................................
	-- "ERROR:  cannot insert multiple commands into a prepared
	--  statement" are you fucking shitting me with this shit
		params = {uint64}, sql = [[
			delete from parsav_artifact_claims where
				rid = $1::bigint
			returning uid, description, birth, folder;
		]];





















	};
	post_attach_ctl_ins = {
		params = {uint64, uint64}, cmd=true, sql = [[
			update parsav_posts set
				artifacts = artifacts || $2::bigint
			where id = $1::bigint and not
				artifacts @> array[$2::bigint] -- prevent duplication
................................................................................
			if ban then
				lib.report('user attempted to instantiate forsaken artifact')
				return 0
			end
			var oldid = srec:int(uint64,0,0)
			return oldid
		else -- not in db, insert
			var nrec = queries.artifact_instantiate.exec(src, artifact, hashb, mime)
			if nrec.sz == 0 then
				lib.warn('failed to instantiate artifact -- are you running out of storage?')
				return 0
			else defer nrec:free()
				var newid = nrec:int(uint64,0,0)
				return newid
			end
		end
	end];








































	post_attach_ctl = [terra(
		src: &lib.store.source,
		post: uint64,
		artifact: uint64,
		detach: bool
	): {}







|
|
|




|
|
|







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







|









>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
...
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
....
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
			limit case when $4::bigint = 0 then null
					   else $4::bigint end
			offset $5::bigint
		]];
	};

	artifact_instantiate = {
		params = {binblob, binblob, pstring, int64}, sql = [[
			insert into parsav_artifacts (content,hash,mime,birth) values (
				$1::bytea, $2::bytea, $3::text,$4::bigint
			) on conflict do nothing returning id
		]];
	};
	artifact_expropriate = {
		params = {uint64, uint64, pstring, pstring, int64}, cmd = true, sql = [[
			insert into parsav_artifact_claims (uid,rid,description,folder,birth) values (
				$1::bigint, $2::bigint, $3::text, $4::text, $5::bigint
			) on conflict do nothing
		]];
	};
	artifact_quicksearch = {
		params = {binblob}, sql = [[
			select id, (content is null) from parsav_artifacts where hash = $1::bytea
				limit 1
................................................................................
	-- "ERROR:  cannot insert multiple commands into a prepared
	--  statement" are you fucking shitting me with this shit
		params = {uint64}, sql = [[
			delete from parsav_artifact_claims where
				rid = $1::bigint
			returning uid, description, birth, folder;
		]];
	};
	artifact_enum_uid = {
		params = {uint64, pstring}, sql = [[
			select (pg_temp.parsavpg_translate_artifact(a)).*
			from parsav_artifact_claims as a where uid = $1::bigint and
				($2::text is null or
				 ($2::text = '' and folder is null) or
				 $2::text = folder)
			order by birth desc
		]];
	};
	artifact_fetch = {
		params = {uint64, uint64}, sql = [[
			select (pg_temp.parsavpg_translate_artifact(a)).*
			from parsav_artifact_claims as a where uid = $1::bigint and rid = $2::bigint
		]];
	};
	artifact_load = {
		params = {uint64}, sql = [[
			select content, mime from parsav_artifacts where id = $1::bigint
		]];
	};
	post_attach_ctl_ins = {
		params = {uint64, uint64}, cmd=true, sql = [[
			update parsav_posts set
				artifacts = artifacts || $2::bigint
			where id = $1::bigint and not
				artifacts @> array[$2::bigint] -- prevent duplication
................................................................................
			if ban then
				lib.report('user attempted to instantiate forsaken artifact')
				return 0
			end
			var oldid = srec:int(uint64,0,0)
			return oldid
		else -- not in db, insert
			var nrec = queries.artifact_instantiate.exec(src, artifact, hashb, mime, lib.osclock.time(nil))
			if nrec.sz == 0 then
				lib.warn('failed to instantiate artifact -- are you running out of storage?')
				return 0
			else defer nrec:free()
				var newid = nrec:int(uint64,0,0)
				return newid
			end
		end
	end];

	artifact_expropriate = [terra(
		src: &lib.store.source,
		uid: uint64,
		artifact: uint64,
		desc: pstring,
		folder: pstring
	): {}
		queries.artifact_expropriate.exec(src,uid,artifact,desc,folder, lib.osclock.time(nil))
	end];

	artifact_enum_uid = [terra(
		src: &lib.store.source,
		uid: uint64,
		folder: pstring
	)
		var res = queries.artifact_enum_uid.exec(src,uid,folder)
		if res.sz > 0 then
			var m = lib.mem.heapa([lib.mem.ptr(lib.store.artifact)], res.sz)
			for i=0,res.sz do
				var id = res:int(uint64,i,0)
				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};
				}) ]
				m(i).ptr.rid = id
				m(i).ptr.owner = uid
			end
			return m
		else return [lib.mem.lstptr(lib.store.artifact)].null() end
	end];

	post_attach_ctl = [terra(
		src: &lib.store.source,
		post: uint64,
		artifact: uint64,
		detach: bool
	): {}