Skip to content
Snippets Groups Projects
Commit b3ca1251 authored by Hugo Trentesaux's avatar Hugo Trentesaux
Browse files

add a tiny bit of content validation to prevent overloading database

parent 95cdec7b
No related branches found
Tags 0.1.0-a0.1
No related merge requests found
......@@ -87,10 +87,13 @@ const userFsQb: QueryBuilder = {
data_cid = EXCLUDED.data_cid,
WHERE EXCLUDED.time > profiles.time;
`,
// we do not need to fetch any data
dataGetter: (_dataCID) => Promise.resolve(null),
// we do not *need* to fetch any data
// however, we do fetch the first node to make sure it becomes available locally
// this is the place where we could fetch more specific parts of this FS
// to be sure to make them available on the network for later
dataGetter: defaultDataGetter,
dataTransform: defaultDataTransform,
paramBuilder: (irCID: CID, ir: IndexRequest, dataCID: CID, _data: null) => [
paramBuilder: (irCID: CID, ir: IndexRequest, dataCID: CID, _data: any) => [
// $1 index_request_cid
irCID.toString(),
// $2 time
......@@ -133,20 +136,20 @@ const cesiumPlusProfile: QueryBuilder = {
ir.pubkey,
// $4 data_cid
dataCID.toString(),
// $5 title
data.title,
// $6 description
data.description,
// $7 avatar
data.avatar?.toString(),
// $5 title (truncated to 128 chars)
data.title.substring(0,128),
// $6 description (truncated to 1024 chars, full version still available on IPFS)
data.description.substring(0,1024),
// $7 avatar (makes sure it is not more than a reasonable CID)
data.avatar?.toString().substring(0,64),
// $8 geoloc
data.geoPoint?.lat,
// $9
data.geoPoint?.lon,
// $10 city
data.city,
// $11 socials
data.socials ? JSON.stringify(data.socials) : undefined
// $10 city (truncated to 128 chars)
data.city?.toString().substring(0,128),
// $11 socials (json truncated to 4096 chars, full version available on IPFS, research in json is unlikely)
data.socials ? JSON.stringify(data.socials).substring(0,4096) : undefined
]
}
......@@ -183,31 +186,6 @@ const cesiumPlusProfileRaw: QueryBuilder = {
paramBuilder: cesiumPlusProfile.paramBuilder
}
// transaction comment query and param builder
// prevents overwrite
const txComment: QueryBuilder = {
query: `INSERT INTO
transaction_comments(index_request_cid, time, pubkey, tx_id, comment)
VALUES ($1, $2, $3, $4, $5)
ON CONFLICT (pubkey, tx_id)
DO NOTHING;
`,
dataGetter: defaultDataGetter,
dataTransform: defaultDataTransform,
paramBuilder: (irCID: CID, ir: IndexRequest, _dataCID: CID, data: TxComment) => [
// $1 index_request_cid
irCID.toString(),
// $2 time
new Date(ir.time).toISOString(),
// $3 pubkey
ir.pubkey,
// $4 tx_id
data.tx_id,
// $5 comment
data.comment
]
}
/// return data handler for a query builder
const dataHandler: <T>(
q: QueryBuilder,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment