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
No related tags found
No related merge requests found
...@@ -87,10 +87,13 @@ const userFsQb: QueryBuilder = { ...@@ -87,10 +87,13 @@ const userFsQb: QueryBuilder = {
data_cid = EXCLUDED.data_cid, data_cid = EXCLUDED.data_cid,
WHERE EXCLUDED.time > profiles.time; WHERE EXCLUDED.time > profiles.time;
`, `,
// we do not need to fetch any data // we do not *need* to fetch any data
dataGetter: (_dataCID) => Promise.resolve(null), // 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, dataTransform: defaultDataTransform,
paramBuilder: (irCID: CID, ir: IndexRequest, dataCID: CID, _data: null) => [ paramBuilder: (irCID: CID, ir: IndexRequest, dataCID: CID, _data: any) => [
// $1 index_request_cid // $1 index_request_cid
irCID.toString(), irCID.toString(),
// $2 time // $2 time
...@@ -133,20 +136,20 @@ const cesiumPlusProfile: QueryBuilder = { ...@@ -133,20 +136,20 @@ const cesiumPlusProfile: QueryBuilder = {
ir.pubkey, ir.pubkey,
// $4 data_cid // $4 data_cid
dataCID.toString(), dataCID.toString(),
// $5 title // $5 title (truncated to 128 chars)
data.title, data.title.substring(0,128),
// $6 description // $6 description (truncated to 1024 chars, full version still available on IPFS)
data.description, data.description.substring(0,1024),
// $7 avatar // $7 avatar (makes sure it is not more than a reasonable CID)
data.avatar?.toString(), data.avatar?.toString().substring(0,64),
// $8 geoloc // $8 geoloc
data.geoPoint?.lat, data.geoPoint?.lat,
// $9 // $9
data.geoPoint?.lon, data.geoPoint?.lon,
// $10 city // $10 city (truncated to 128 chars)
data.city, data.city?.toString().substring(0,128),
// $11 socials // $11 socials (json truncated to 4096 chars, full version available on IPFS, research in json is unlikely)
data.socials ? JSON.stringify(data.socials) : undefined data.socials ? JSON.stringify(data.socials).substring(0,4096) : undefined
] ]
} }
...@@ -183,31 +186,6 @@ const cesiumPlusProfileRaw: QueryBuilder = { ...@@ -183,31 +186,6 @@ const cesiumPlusProfileRaw: QueryBuilder = {
paramBuilder: cesiumPlusProfile.paramBuilder 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 /// return data handler for a query builder
const dataHandler: <T>( const dataHandler: <T>(
q: QueryBuilder, q: QueryBuilder,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment