Legacy document ingest
Overview
POST /api/documents and POST /api/files/upload/ reject a create when Bcyip-Agent is missing. A document create also requires fileId or idUpload, except when the agent is iptower. The header values are stored on the document as auto-attributes.
How it works
requireAgentHeader returns 400 when Bcyip-Agent is missing or blank. Any non-empty value is accepted. The value is not checked against agent_codes.
validatePostDocumentCreate then requires fileId or idUpload unless the trimmed header is iptower (case-insensitive). When a reference is present, assertLinkableRemoteFile checks that the RemoteFile exists, belongs to the job, matches the document hash, and is not already linked. The document row is removed if that check fails.
buildIngestAutoAttributes writes bcyip:agent and bcyip:agent-version from the headers. A blank header is omitted. The values are not read from users.agent or apitokens.agent.
Key files
app/util/documentIngest.js— Header guard, fileId rule, auto-attributesapp/routes/documents.js— Guard and attributes on document createapp/routes/files.js— Guard onPOST /files/upload/app/routes/files-big.js— Same guard on the upload APIapp/services/documents.js— RemoteFile ownership, hash, and link checksapp/database/schema/document.js—autoAttributeson the document
Technical decisions
- Tower may create a document without a file. Every other agent must link an upload.
- The header is required for Tower too. Only the file reference is optional for
iptower. - Header text is stored as sent (trimmed). It is not replaced by the token's
agentfield.
Known issues
- The document is inserted, then deleted, when the RemoteFile check fails.
Next steps
- Reject the create before the insert when
fileIdis invalid