Administrator guide to the Account Dashboard's Upload page — from a phone in a village to a pin on the Impact Map, with location data removed on the way.
Every pin on the Impact Map is a moment that really happened: a hand pump that now gives clean water, a family that walked out of a brick kiln free, a medical camp in a village with no clinic. For a long time, getting those moments onto the map meant sending files through a chat app, sorting them by hand, and typing in where and when each one happened. The Upload page replaces all of that with one form in the Account Dashboard that Shafiq Bhatti and Cory Dean Kalani can use from any phone or computer.
You choose the impact type, the village, the date the photo or video was taken, and a short description, then pick your files. From that moment the system does the rest: the files travel straight to private storage, a processor removes every trace of location data and converts them to formats every browser plays, and a new pin appears on the map at the village you named. There is no approval step. An upload from one of you goes on the map by itself, usually within a minute or two.
Why it is built this way. The people closest to the work should be able to tell its story without anyone in between. So the design asks you for only what you know — what happened, where, when — and keeps for itself everything you should not have to think about: coordinates, file formats, naming, privacy, and retrying a dropped connection.
flowchart LR
subgraph S1["1 · You, in the field"]
direction TB
PHONE["Phone or computer\nShafiq Bhatti\nCory Dean Kalani"]
FORM["Upload page\nimpact type · village\ndate taken · description"]
PHONE --> FORM
end
subgraph S2["2 · LPO server"]
direction TB
GRANT["Folder permission\nfield_upload_grants"]
VILL["Village coordinates\nmap_regions"]
ROW["Upload record\nfield_uploads"]
GRANT --> VILL --> ROW
end
subgraph S3["3 · Private bucket"]
direction TB
PARTS["8 MB parts\n3 at a time\nretried if dropped"]
ORIG[("Original file\nnever public")]
PARTS --> ORIG
end
subgraph S4["4 · Media processor"]
direction TB
CLAIM["Reserve the\npublic name"]
CLEAN["Rebuild as\nJPEG or MP4\nmetadata removed"]
CHECK{"Location\ndata left?"}
CLAIM --> CLEAN --> CHECK
end
subgraph S5["5 · Impact Map"]
direction TB
SITE[("map-pins/type/\nvillage-date-NNN")]
PIN["Pin at the\nvillage"]
NEWS["Monthly\nnewsletter"]
SITE --> PIN --> NEWS
end
S1 -->|"start upload"| S2
S2 -->|"signed URLs · parts sent direct"| S3
S3 -->|"upload complete"| S4
S4 -->|"none left: publish"| S5
style S1 fill:#1e293b,stroke:#10b981,color:#e2e8f0
style S2 fill:#1e293b,stroke:#60a5fa,color:#e2e8f0
style S3 fill:#1e293b,stroke:#f59e0b,color:#e2e8f0
style S4 fill:#1e293b,stroke:#a855f7,color:#e2e8f0
style S5 fill:#1e293b,stroke:#10b981,color:#e2e8f0
Read the diagram from left to right, through its five numbered stages. Notice what never happens: the file never passes through our servers on its way in, and the original never becomes public. The server only checks, records and signs; storage receives the bytes; the processor decides what the public may see. Each part does one job, which is why each part stays simple.
Uploads are organised into one folder for each impact type on the Impact Map legend. A folder permission is a row that pairs a person's dashboard sign-in with one impact type, so you can give someone a single folder, several, or all seven. Today Shafiq Bhatti and Cory Dean Kalani each hold all seven.
| Folder | Map legend label | What belongs here |
|---|---|---|
medical | Medical Camps | Free medical camps, check-ups and medicine |
water | Clean Water | Hand pumps and clean-water projects |
wheelchair | Wheelchairs | Wheelchairs given and the people who received them |
freedom | Freedom | Families freed from brick kiln debt bondage |
provisions | Provisions | Food and essentials delivered |
word | The Word | Printed and audio Bibles shared |
education | Education | Schooling and training |
The permission is checked on every request, not only when the page loads. That matters because it means the page is a convenience, never the security boundary: even a hand-written request for a folder you do not hold is refused by the server. The menu entry appears only for accounts that hold at least one folder, so everyone else's dashboard stays exactly as it was.
One rule worth knowing. Uploads are not available while an administrator is impersonating another account. Every upload records who sent it, and that record has to be the person who actually did.
The page has two cards. New upload is the form; Your uploads shows what you have sent and where each file is on its way to the map. Here is the page as an administrator sees it on a computer.
Every file you send carries four facts. They are the same four facts the map already stores for every pin, which is what lets an upload become a pin without anyone rewriting it.
| On the form | Becomes on the pin | Why it is asked for |
|---|---|---|
| Impact type | map_pins.type | Chooses the legend colour and icon, and the folder the file is stored in. Only the folders you hold are offered. |
| Village or area | map_pins.region and the pin's coordinates | Places the pin. You name the village; the system supplies the latitude and longitude (section 5). |
| Date the photo or video was taken | map_pins.date | The day it happened, not the day you upload it. A camp held in March and uploaded in October belongs to March. |
| Description | map_pins.caption | The words a visitor reads beside the photo. Required, up to 1,000 characters. |
The form adds one more choice, Language of the description, which starts at the language your dashboard is in. Write the description in whatever language comes naturally and tell the form which one it is. The map then translates it for each visitor from that language (section 8).
Every file you choose in one upload gets the same four facts and becomes its own pin. To give files different details, upload them in separate rounds; the form keeps its values between rounds, so you change only what differs.
These are the formats phones and cameras actually produce, including the ones iPhones use by default. Each file can be up to 2 GB.
| Kind | Format | File endings | Usually comes from |
|---|---|---|---|
| Photos | JPEG | .jpg .jpeg | Android phones, cameras, most shared photos |
| HEIC / HEIF | .heic .heif | iPhone camera (its default setting) | |
| PNG | .png | Screenshots and edited images | |
| WebP | .webp | Images saved from the web or from some chat apps | |
| Videos | MP4 | .mp4 | Android phones and most cameras |
| QuickTime | .mov | iPhone camera | |
| M4V | .m4v | Videos exported from Apple devices | |
| 3GP | .3gp | Older Android phones | |
| WebM | .webm | Screen recordings and browser recordings |
Anything else — a GIF, an AVI or MKV video, a PDF or other document — is stopped before it uploads, with a message naming the file, so nothing is sent that could not become a pin. You never need to convert a file first: whatever the format on this list, the public copy becomes a JPEG photo or an MP4 video, the two formats every browser plays (section 6).
Press Upload and each file shows its own progress bar. A phone video can be hundreds of megabytes and a village connection can drop at any moment, so the page never sends a file in one piece. It splits each file into 8 MB parts and sends three parts at a time. If the connection drops, only the part in flight is retried, with a growing pause between attempts, and the file carries on from where it was. Each part gets 8 attempts, the pause starting at a second and a half and doubling up to 30 seconds. Even the very first request for upload addresses is retried inside each part's own attempts, so a drop in the first second does not end the upload.
Why the bytes skip our servers. The browser sends each part straight to Amazon S3 using a short-lived upload URL that the server signed for that one part of that one file. Our API servers never carry a single byte of video, so a large upload cannot slow down the price feeds and reports they serve, and the files never pass through the web firewall's request-size limits.
You never type a latitude or longitude. Photos shared through chat apps lose their location data on the way, and location data is something we remove on purpose anyway (section 6.1). So a pin's coordinates come from its village, and every village has its place stored once, in one table, map_regions.
Start typing in Village or area and the field suggests the villages already on the map, most-used first. Pick one and the form confirms it: This village is already on the map.
The work is growing, and new villages are expected. Type a name the map does not know yet and the form tells you it is a new village, then opens a small map. Tap where the village is, and that place is saved with the village, so every future upload there lands in the right spot without being placed again.
If you are not sure where it is, leave the map alone and upload anyway. The pin goes on the map at a temporary point, and once the village is given its place, every pin there moves to it (section 11).
A village name becomes part of each published file name and web address, and every village already on the map is written that way. So the form asks for the name in English letters and says so, in your dashboard's language, if it sees anything else.
Spelling variants of the same place are recognised as one village: Bilal Town, bilal-town and bilal_town all lead to the same row, because a village's identity ignores capital letters and treats spaces, dashes and underscores alike.
When the last part of a file arrives, storage tells the processor, tbi-field-media-processor, and the rest happens without you. A photo is prepared by the processor itself, in seconds. A video is handed to a task of its own on Fargate (tbi-field-media-video), which runs the same steps with the same code but has no time limit, because a long phone video can take longer to convert than the 15 minutes a Lambda function is allowed. The sequence below is the whole conversation between the pieces. Every step in it is safe to repeat, which is what lets the system retry anything that fails partway without ever making a second pin.
%%{init: {"sequence": {"mirrorActors": false}, "themeVariables": {"sequenceNumberColor": "#0f172a"}}}%%
sequenceDiagram
autonumber
participant B as Upload page
participant L as LPO server
participant A as Aurora
participant P as Private bucket
participant F as Media processor
participant W as Website bucket
B->>L: Start upload: type, village, date, description, file size
L->>A: Check folder permission, find or add village, record upload
L->>P: Open a multipart upload
L-->>B: Upload id and number of 8 MB parts
loop Every part, three at a time
B->>L: Ask for upload URLs (up to 50 at once)
L-->>B: Signed URLs, valid for 1 hour
B->>P: Send the part (retried if the connection drops)
end
B->>L: Complete, with each part's receipt
L->>P: Join the parts into one file
L->>A: Status: being prepared for the map
P-)F: A new file has arrived
F->>L: Claim this upload
L->>A: Reserve the next free public name
L-->>F: Proceed, and publish under this name
Note over F: A photo is prepared right here. A video is handed to a Fargate task that runs the same steps, with no time limit
F->>P: Read the original
Note over F: Rebuild the image or video, remove all metadata, confirm no location data survived
F->>W: Write the public copy, never over an existing file
F->>L: Result: published at this address
L->>A: Create the map pin and mark the upload published, in one transaction
Two details in the diagram carry most of the reliability. The public name is reserved before the file is written (step 13), so two photos from the same day and village can never be given the same number. And the pin is created in the same database transaction that marks the upload published (step 18), so a pin can never exist without its upload saying so.
The Impact Map promises every visitor that pin locations are approximate, to protect the families and field workers in sensitive areas. A photo taken on a phone and uploaded directly can carry the exact spot where it was taken. The processor keeps the promise by never copying a file as it is.
Your original stays in the private bucket, untouched and never public. The pin itself sits at its village's coordinates, and the map adds a small random offset of about a kilometre every time it draws it. The location a visitor sees is always the village, never a doorstep.
Every photo and video on the map follows one naming pattern, and the files you upload follow it too:
map-pins/<impact type>/<village>-<YYYY-MM-DD>-<NNN>.<jpg or mp4>
That means a file name is not a random string. It can be read back into the pin's own facts:
| Example | Impact type | Village | Date taken | Number | Kind |
|---|---|---|---|---|---|
map-pins/water/dhunde-2026-10-20-001.jpg | water | dhunde | 2026-10-20 | 001 | photo |
map-pins/medical/central-punjab-2026-10-12-003.mp4 | medical | central-punjab | 2026-10-12 | 003 | video |
The number is the next free one for that type, village and date. The server finds it by looking at existing pins, at names already reserved by other uploads, and at the files actually in the website bucket, so even a stray old file keeps its number. Your own file name (IMG_2041.JPG and so on) is kept in the upload's record for reference, but never appears in any address.
Photos and videos are prepared by one program, built once into one container image and run in two places. The Lambda function tbi-field-media-processor runs the image as a Lambda function: it receives every new file, prepares photos itself, and starts a video task for each video. The ECS task definition tbi-field-media-video runs the same image as a Fargate task, with a different entry point, to prepare one video and then stop. Because both run the same image, a photo and a video are always prepared by exactly the same code.
%%{init: {"flowchart": {"nodeSpacing": 50, "rankSpacing": 60}}}%%
flowchart LR
IMG[("ECR image\ntbi-field-media-processor\narm64")]
S3["Private bucket\ntrinity-beast-field-uploads"]
L["Lambda function\ntbi-field-media-processor\nentry point: awslambdaric"]
T["Fargate task\ntbi-field-media-video\nentry point: python -m handler\n4 vCPU, 8 GB, 100 GiB, ARM64"]
API["LPO server\n/admin/field-uploads/claim\n/admin/field-uploads/result"]
W["Website bucket\nmap-pins/"]
EB["EventBridge rule\ntbi-field-media-video-stopped"]
LOG["Log group\n/ecs/tbi-field-media-video"]
AL["Alarm\nVideoTask-Problems"]
IMG -.->|"same image"| L
IMG -.->|"same image, pinned by digest"| T
S3 -->|"new file"| L
L -->|"photo: claim and result"| API
L -->|"photo: public copy"| W
L -->|"video: ecs RunTask\nwith S3_KEY"| T
T -->|"claim and result"| API
T -->|"public copy"| W
T -->|"log lines"| LOG
LOG --> AL
T -->|"task STOPPED"| EB
EB -->|"report a task that\ndid not finish"| L
style IMG fill:#1e293b,stroke:#94a3b8,color:#e2e8f0
style T fill:#14532d,stroke:#34d399,color:#e2e8f0
style AL fill:#3f1d1d,stroke:#f87171,color:#fecaca
The image is built from lambdas/field-media-processor/Dockerfile in the LPO server repository, with build.sh in the same folder. It starts from the official Python 3.12 image for ARM64 (python:3.12-slim-bookworm), adds Debian's ffmpeg for video, and installs Pillow and pillow-heif for photos, including iPhone HEIC files. Its default entry point is the AWS Lambda runtime client, which is how the Lambda function runs it. Each build is pushed to the ECR repository tbi-field-media-processor.
| Lambda setting | Value |
|---|---|
| Package | Container image, ARM64 |
| Memory and temporary storage | 10,240 MB each |
| Time limit | 900 seconds (15 minutes) |
| Reserved concurrency | 10, so at most ten files are prepared at once |
| Network | Not in a VPC |
| Settings it passes to the video task | VIDEO_CLUSTER, VIDEO_TASK_DEFINITION, VIDEO_CONTAINER, VIDEO_SUBNETS, VIDEO_SECURITY_GROUPS |
The task definition is kept in the LPO server repository as deployments/field-media-video-task-def.json, and the registered revision matches it. It has no ECS service. Nothing runs until a video arrives, and the only thing that starts a task is the Lambda function.
| Setting | Value | Why |
|---|---|---|
| Family and revision | tbi-field-media-video, revision 2 | Revision 1 is deregistered |
| Cluster | trinity-beast-fargate-cluster | The cluster the LPO services run in |
| Launch type and platform | Fargate, Linux on ARM64 | The image is built for ARM64 |
| Size | 4 vCPU, 8 GB of memory, 100 GiB of working space | Converting video is CPU work, and a 2 GB original and its copy must both fit on disk |
| Container | video, essential | The task's only container |
| Image | The processor image, pinned by digest | A task always runs the exact build that was tested, never whatever was pushed last |
| Entry point | /usr/local/bin/python -m handler | Replaces the Lambda runtime client, so the program runs once and exits |
| Environment | FIELD_MEDIA_MODE=task, VIDEO_TIMEOUT_SECONDS=10800, LPO_BASE, PYTHONUNBUFFERED=1 | Task mode; the 3-hour safety stop; the server's address; log lines written as they happen instead of all at the end |
| Per-task setting | S3_KEY | Added by the Lambda function when it starts the task: the one file this task prepares |
| Task role | tbi-field-media-video-task-role | Reads originals, writes public copies under map-pins/ and reads the admin key. Nothing else |
| Execution role | ecsTaskExecutionRole | Pulls the image and writes the logs |
| Logs | /ecs/tbi-field-media-video, stream prefix video | One stream per video, kept 90 days |
The Lambda function calls ecs:RunTask with three things the task definition cannot know in advance:
S3_KEY.startedBy set to fmv- followed by the upload's id. If storage reports the same file twice, the function finds the task already running and does not start a second one.Inside the task, a server or network error is retried twice, after 30 seconds and after 2 minutes. If all three attempts fail, the task marks the upload Could not be prepared itself. A file that cannot be read is marked straight away, without retries, because trying again would not change it.
When any video task stops, the EventBridge rule tbi-field-media-video-stopped sends the event back to the Lambda function. A clean exit needs nothing. Any other ending, including a task that never started, marks the upload Could not be prepared, so an upload can never wait for ever. The server ignores that report for an upload that is already published. If the task logs an error or stops early, the alarm Trinity-Beast-FieldMedia-VideoTask-Problems emails the operations list.
Changing the image. A new build reaches the Lambda function when the function is updated to it. The video task keeps running the old build until a new revision of the task definition is registered with the new digest. The function names the task definition without a revision, so it always starts the newest active one. Update both, from the same build, every time, then deregister the old revision.
Your uploads lists your 100 most recent files. Each row shows the four facts you entered, the day you uploaded the file, its original name and size, and a status, with a thumbnail once a photo is on the map. Every file that is on the map also has a Show on map link under its status (section 8). While anything is being prepared, the list refreshes itself every fifteen seconds; the Refresh button is there when you want to look sooner.
Select a column heading to sort the list by it: Impact type, Village, Date taken, Uploaded or Status. Select the same heading again to reverse the order. The arrow beside each heading shows which column is in use and in which direction (↑ or ↓); the others show ↕. Sorting by Status puts the files that need you first: could not be prepared; then uploads still open after a day with no report of why they stopped; then every other stopped file; then uploading, being prepared, and last, on the map. An upload an administrator closed as abandoned reads like the ones still open after a day, but it sorts with the other stopped files. Files that tie keep the newest upload first. Your chosen order stays in place while the list refreshes. If you have more than 100 uploads, a note under the list says that only the most recent are shown.
On a phone, each upload becomes its own card, with its village and both dates labelled, and the column headings become a row of buttons above the list that sort the same way. Nothing on the page has to be scrolled sideways.
| The list says | What is happening | What to do |
|---|---|---|
| Uploading | Parts are still on their way from your device. | Keep the page open. |
| Stopped: the page was closed or the device went to sleep. Upload it again. | The upload started more than a day ago and the page never reported that it stopped — usually a page closed, or a phone that slept, mid-upload. An administrator can close such an upload as abandoned, and it then reads the same. | Choose the file again. |
| Being prepared for the map | The file arrived; the processor is building the public copy. | Nothing. Photos take seconds. A video waits about half a minute for its task to start, then takes roughly half its own length to prepare at 1080p, and a little more than its own length at 4K. |
| On the map | Published. The pin is live. | Select Show on map to open the map at the pin. |
| Could not be prepared | The file could not be read, location data could not be removed, or preparing it stopped before it finished, so it was not published. | Try the original file from the phone, or ask an administrator to look (section 11). |
| Stopped: the connection kept dropping. Upload it again. | A part could not be sent after 8 attempts, or the connection dropped while the parts were being joined into one file. | Choose the file again, ideally where the signal is stronger. |
| Stopped: the upload service was unavailable. Upload it again. | Our server answered that the upload service was unavailable. | Choose the file again in a little while. |
| Stopped: the upload could not be finished. Upload it again. | Every part arrived, but joining them into one file was refused. | Choose the file again. |
| Stopped: you were signed out. Sign in and upload it again. | The dashboard session ended in the middle of the upload. | Sign in, then choose the file again. |
| Cancelled | The page stopped the file without recording why: a stop from before November 5, 2026, or from an older copy of the page. | Choose the file again. |
%%{init: {"flowchart": {"nodeSpacing": 90, "rankSpacing": 60}}}%%
flowchart LR
START(("Upload\npressed")) --> U["Uploading\nuploading"]
U -->|"last part arrives"| P["Being prepared\nfor the map\nprocessing"]
U -->|"page stops it and says why"| C["Stopped, with the reason\ncancelled"]
P -->|"public copy written,\npin created"| OK["On the map\npublished"]
P -->|"unreadable, location data\nsurvived, or preparation\nstopped early"| F["Could not be prepared\nfailed"]
style OK fill:#14532d,stroke:#34d399,color:#e2e8f0
style F fill:#3f1d1d,stroke:#f87171,color:#fecaca
style C fill:#1e293b,stroke:#94a3b8,color:#e2e8f0
style START fill:#334155,stroke:#94a3b8,color:#e2e8f0
A published upload is an ordinary pin. It takes the legend colour of its impact type, shows a camera or play badge for photos and videos, joins the clusters in its area, and opens the same detail panel as every other pin: the impact type, your description, the date it was taken and the village, with the photo or video below.
A new pin can be hard to spot. When the map first opens, it shows the whole country, and pins that sit close together are grouped into a numbered circle in their impact type's colour. Your pin is inside that number until you zoom in. Select a circle to zoom into it; closer still, the circle splits into its pins.
The quicker way is the Show on map link beside each published file in Your uploads. It opens the Impact Map in a new tab, in your dashboard language, already zoomed in on that pin with its panel open. The general View the Impact Map link on the Upload page opens the map in your language too.
Descriptions are translated for each visitor from the language you chose on the form. A note Shafiq writes in Urdu reaches an English visitor in English, with his original words shown beneath it, and a visitor reading the map in Urdu sees his words exactly as he wrote them.
The Upload page speaks all twelve dashboard languages, and Urdu and Arabic are laid out right to left. Every label, hint, status and error message comes in the uploader's own language, including the messages from the server. This is the page as Shafiq Bhatti sees it on his phone.
The language follows the account, the way the rest of the dashboard does: no second language picker, no English left behind on a page someone reads in Urdu.
Day to day, the system needs nothing from you. These are the few tasks an administrator does by hand, all through the admin SQL endpoint. Replace each value in angle brackets with your own; a sign-in email is the email address the person uses to sign in to the dashboard.
One row per folder. This gives a person all seven:
INSERT INTO field_upload_grants (email, impact_type, granted_by)
SELECT lower('<sign-in email>'), t, '<your name>'
FROM unnest(ARRAY['medical','water','wheelchair','freedom','provisions','word','education']) AS t
ON CONFLICT (email, impact_type) DO NOTHING;
To give fewer folders, list only those types. To take a folder away, delete its row. The person sees the change the next time their dashboard loads.
A village added without a place has no coordinates, and its pins wait at a temporary point. Set the village's place once, then move its waiting pins:
SELECT key, name FROM map_regions WHERE lat IS NULL;
UPDATE map_regions SET lat = <latitude>, lng = <longitude>, source = 'kiro', updated_at = now()
WHERE key = '<village key>';
UPDATE map_pins SET lat = <latitude>, lng = <longitude>
WHERE region = '<village name>' AND lat IS NULL;
When someone says a photo never appeared, the upload record says why:
SELECT created_at, impact_type, region, event_date, original_name, status, stop_reason, error
FROM field_uploads
WHERE status <> 'published'
ORDER BY created_at DESC
LIMIT 20;
For a file the page stopped (cancelled), stop_reason says why: connection_failed, storage_unavailable, finish_failed or signed_out, or abandoned when an administrator closed out an upload the page never reported on. Its error then holds the page's own detail, for example part 24 of 237, 8 attempts, last: put network; 184 of 1892 MB sent, which tells you which part failed, how, and how far the file got. The LPO server also logs every stop at warning level, as field upload <id> stopped by the page: reason=… detail=…, in the log group /aws/ecs/trinity-beast.
The error column holds the processor's own explanation for anything marked Could not be prepared. The processor's log lines all begin with [field-media]: photos, and every video hand-off, in the log group /aws/lambda/tbi-field-media-processor; the work on each video in /ecs/tbi-field-media-video, one stream per video. If anything goes wrong on the way, an alarm emails the operations list, so a problem is found before anyone has to report a missing pin.
SELECT event_date, impact_type, region, caption, caption_lang, public_url
FROM field_uploads
WHERE status = 'published'
AND published_at >= date_trunc('month', now() - interval '1 month')
AND published_at < date_trunc('month', now())
ORDER BY event_date;
Use the Map Pins page first. In the Account Dashboard, the Admin section's Map Pins page searches every pin, old and new, and saves a correction with the same rules as below, in the administrator's own language. It also corrects the date a photo or video was taken. It is described in the Account Dashboards guide, section 5.12. The SQL in this section is for when the dashboard cannot be used.
With SQL, an administrator can correct four things on any pin on the map: its description, the description's language, its impact type and its village. A description has 1 to 1,000 characters, the same limit as the Upload page, and the map shows all of it.
There are two kinds of pin, and each has its own correction. A pin made by the Upload page has an upload record as well. Most pins on the map are older: they were added before the Upload page existed and have no upload record, so only the pin itself changes.
This search covers every pin, old and new. Fill in any of the five values and leave the rest as NULL. The village and the words match any part of the text, in capital or small letters. The dates are the day the photo or video was taken; the second date is not included. It shows up to 50 pins, newest first.
WITH f AS (
SELECT NULL::text AS village, -- part of a village name, such as 'kasur'
NULL::text AS impact_type, -- medical, water, wheelchair, freedom, provisions, word or education
NULL::text AS words, -- words in the description, such as 'hand pump'
NULL::date AS taken_from, -- such as '2024-01-01'
NULL::date AS taken_before -- such as '2025-01-01'
)
SELECT p.id AS pin_id, u.id AS upload_id, p.date::date AS taken, p.type, p.region,
p.caption, p.media_urls ->> 0 AS first_file
FROM map_pins p
CROSS JOIN f
LEFT JOIN field_uploads u ON u.map_pin_id = p.id
WHERE p.status = 'active'
AND (f.village IS NULL OR p.region ILIKE '%' || f.village || '%')
AND (f.impact_type IS NULL OR p.type = f.impact_type)
AND (f.words IS NULL OR p.caption ILIKE '%' || f.words || '%')
AND (f.taken_from IS NULL OR p.date >= f.taken_from)
AND (f.taken_before IS NULL OR p.date < f.taken_before)
ORDER BY p.date DESC
LIMIT 50;
To look at a result on the map, open https://cpmp-site.org/map.html?pin=<pin id>; the map opens on that pin with its panel showing. If upload_id has a value, the pin came from the Upload page: follow steps 2 to 4. If it is empty, the pin is an older one: follow "Correcting an older pin" below.
Each published file is stored twice. Its upload record is what the uploader sees in Your uploads. Its map pin is what every visitor sees on the Impact Map. When the file is published, the server copies the description, its language, the impact type and the village from the upload into the new pin, and after that the two are separate rows. A correction must change both in one transaction, so that the list and the map can never disagree.
map_regions, so the village must already be in that table, with its place set if the pin is to sit there.Save the result of this query until the correction is checked. If anything looks wrong afterwards, it holds every value needed to put the rows back.
SELECT row_to_json(u) AS upload, row_to_json(p) AS pin
FROM field_uploads u
JOIN map_pins p ON p.id = u.map_pin_id
WHERE u.id = '<upload id>';
Fill in the upload's id and only the values that change. Leave the others as NULL and they stay as they are. Inside a value, write an apostrophe twice ('Shafiq''s'). The language is one of the twelve dashboard codes. Send the whole block as one query to /admin/sql with mode write. Do not split it, and do not send it through /admin/sql-batch, which runs each statement on its own and so is not one transaction.
DO $$
DECLARE
v_upload uuid := '<upload id>';
v_caption text := NULL; -- the new description, or NULL to keep it
v_lang text := NULL; -- the language of the description: en, ar, de, es, fr, hi, it, ja, pt, ru, ur or zh
v_type text := NULL; -- medical, water, wheelchair, freedom, provisions, word or education
v_village text := NULL; -- the village name, as in map_regions
u field_uploads%ROWTYPE;
r map_regions%ROWTYPE;
n int;
BEGIN
SELECT * INTO u FROM field_uploads WHERE id = v_upload AND status = 'published' FOR UPDATE;
IF NOT FOUND THEN
RAISE EXCEPTION 'no published upload %', v_upload;
END IF;
IF v_caption IS NOT NULL AND (btrim(v_caption) = '' OR char_length(v_caption) > 1000) THEN
RAISE EXCEPTION 'a description must have 1 to 1000 characters';
END IF;
IF v_lang IS NOT NULL AND v_lang NOT IN ('en','ar','de','es','fr','hi','it','ja','pt','ru','ur','zh') THEN
RAISE EXCEPTION 'unknown description language %', v_lang;
END IF;
IF v_village IS NOT NULL THEN
SELECT * INTO r FROM map_regions
WHERE key = regexp_replace(lower(btrim(v_village)), '[^a-z0-9]', '_', 'g');
IF NOT FOUND THEN
RAISE EXCEPTION 'no village %; add it to map_regions first', v_village;
END IF;
END IF;
UPDATE field_uploads SET
caption = coalesce(v_caption, caption),
caption_lang = coalesce(v_lang, caption_lang),
impact_type = coalesce(v_type, impact_type),
region = coalesce(r.name, region)
WHERE id = u.id;
UPDATE map_pins SET
caption = coalesce(v_caption, caption),
caption_lang = coalesce(v_lang, caption_lang),
type = coalesce(v_type, type),
region = coalesce(r.name, region),
lat = CASE WHEN v_village IS NULL THEN lat ELSE r.lat END,
lng = CASE WHEN v_village IS NULL THEN lng ELSE r.lng END
WHERE id = u.map_pin_id;
GET DIAGNOSTICS n = ROW_COUNT;
IF n <> 1 THEN
RAISE EXCEPTION 'pin % not found; nothing was changed', u.map_pin_id;
END IF;
END $$;
The block checks everything before it keeps anything. An unknown upload, language, impact type or village, a description that is blank or longer than 1,000 characters, or a missing pin, stops it with a message, and then neither row changes. The village is found the same way the Upload page finds it, so capital letters and spaces at either end do not matter, and both rows get the village's name exactly as map_regions spells it.
SELECT u.caption = p.caption AS same_description,
u.caption_lang, p.caption_lang AS pin_language,
u.impact_type, p.type AS pin_type,
u.region, p.region AS pin_village, p.lat, p.lng
FROM field_uploads u
JOIN map_pins p ON p.id = u.map_pin_id
WHERE u.id = '<upload id>';
Each pair should match, and the new values should be there. Then open the pin through the uploader's Show on map link, or reload the Impact Map. The map reads the pins from the database on every load, so the change shows at once. When both look right, delete the copy you saved in step 2.
To move a pin to a village that is not in the list yet, add the village first, with its place, then run the correction with its name. The key is the name in lower case, with every character other than a letter or a digit replaced by _:
INSERT INTO map_regions (key, name, lat, lng, source, created_by)
VALUES ('<village key>', '<village name>', <latitude>, <longitude>, 'kiro', '<your name>');
An older pin has no upload record, so only the pin changes. Most older pins carry one of six standard descriptions, one for each kind of work, so this is also how a pin gets its own story. The same four values can be corrected, with the same rules: a new village moves the pin, and a new impact type changes its colour and group.
First keep a copy of the pin:
SELECT row_to_json(p) AS pin FROM map_pins p WHERE p.id = '<pin id>';
Then fill in the pin's id and only the values that change, and send the block as one query to /admin/sql with mode write:
DO $$
DECLARE
v_pin uuid := '<pin id>';
v_caption text := NULL; -- the new description, or NULL to keep it
v_lang text := NULL; -- the language of the description: en, ar, de, es, fr, hi, it, ja, pt, ru, ur or zh
v_type text := NULL; -- medical, water, wheelchair, freedom, provisions, word or education
v_village text := NULL; -- the village name, as in map_regions
p map_pins%ROWTYPE;
r map_regions%ROWTYPE;
BEGIN
SELECT * INTO p FROM map_pins WHERE id = v_pin FOR UPDATE;
IF NOT FOUND THEN
RAISE EXCEPTION 'no pin %', v_pin;
END IF;
IF EXISTS (SELECT 1 FROM field_uploads WHERE map_pin_id = v_pin) THEN
RAISE EXCEPTION 'pin % came from an upload; use the upload correction instead', v_pin;
END IF;
IF v_caption IS NOT NULL AND (btrim(v_caption) = '' OR char_length(v_caption) > 1000) THEN
RAISE EXCEPTION 'a description must have 1 to 1000 characters';
END IF;
IF v_lang IS NOT NULL AND v_lang NOT IN ('en','ar','de','es','fr','hi','it','ja','pt','ru','ur','zh') THEN
RAISE EXCEPTION 'unknown description language %', v_lang;
END IF;
IF v_type IS NOT NULL AND v_type NOT IN ('medical','water','wheelchair','freedom','provisions','word','education') THEN
RAISE EXCEPTION 'unknown impact type %', v_type;
END IF;
IF v_village IS NOT NULL THEN
SELECT * INTO r FROM map_regions
WHERE key = regexp_replace(lower(btrim(v_village)), '[^a-z0-9]', '_', 'g');
IF NOT FOUND THEN
RAISE EXCEPTION 'no village %; add it to map_regions first', v_village;
END IF;
END IF;
UPDATE map_pins SET
caption = coalesce(v_caption, caption),
caption_lang = coalesce(v_lang, caption_lang),
type = coalesce(v_type, type),
region = coalesce(r.name, region),
lat = CASE WHEN v_village IS NULL THEN lat ELSE r.lat END,
lng = CASE WHEN v_village IS NULL THEN lng ELSE r.lng END
WHERE id = p.id;
END $$;
The block refuses a pin that came from the Upload page, so a correction can never change a pin without its upload record. It checks the impact type itself, because the pins table has no rule of its own for it. Then run the search again with the pin's village or words, or open it on the map, to see the change. When it looks right, delete the copy.
All require a dashboard session, and every one checks the folder permission itself.
| Method | Path | Purpose |
|---|---|---|
GET | /dashboard/api/uploads/config | The folders this account holds, the known villages, accepted file types and limits |
GET | /dashboard/api/uploads | This account's 100 most recent uploads with their statuses, and more: whether older ones exist |
POST | /dashboard/api/uploads | Start one file: permission check, village, upload record, multipart upload |
POST | /dashboard/api/uploads/{id}/parts | Signed URLs for up to 50 parts, valid for 1 hour |
POST | /dashboard/api/uploads/{id}/complete | Join the parts; the file moves to Being prepared |
POST | /dashboard/api/uploads/{id}/cancel | Stop an unfinished file and record why: optional reason and detail; a repeat only fills in a missing reason |
Two more serve the Map Pins page. They need an administrator's own session and refuse one used for impersonation.
| Method | Path | Purpose |
|---|---|---|
GET | /dashboard/api/admin/map-pins | Search every pin, with the village list for the edit form |
POST | /dashboard/api/admin/map-pins/{id} | Save one pin, and its upload record when it has one, in one transaction |
| Method | Path | Purpose |
|---|---|---|
POST | /admin/field-uploads/claim | Claim an arrived file and reserve its public name; answers "nothing to do" for one already published |
POST | /admin/field-uploads/result | Record the outcome; on success, create the pin and mark the upload published in one transaction |
| Table | Holds |
|---|---|
field_upload_grants | The folder permissions: one row per sign-in and impact type |
field_uploads | One row per file: who sent it, the four facts, the description's language, the original name, type and size, status and, for a stopped file, why it stopped (stop_reason), public name and address, the pin it became, and any error |
map_regions | The villages and their coordinates — the only copy of the village list |
map_pins | The map's pins; caption_lang records the language each description is written in. A published upload's pin is a copy of its upload's description, language, impact type and village, made when it is published; correct both together. Older pins have no upload record (section 11.1) |
| Resource | Name | Role |
|---|---|---|
| Private bucket | trinity-beast-field-uploads | The originals. Public access fully blocked and encrypted. Writes need a URL the server signed for that one part of that one file, browsers may send them only from the dashboard's address, and unfinished uploads are cleared after three days |
| Processor | tbi-field-media-processor | Container Lambda with its own copy of the image and video tools. Prepares photos itself, at most ten at once, and hands each video to the video task. Also receives every stopped video task, and marks the upload Could not be prepared if the task stopped before finishing |
| Video task | tbi-field-media-video | One Fargate task per video, from the same image: 4 vCPU, 8 GB of memory and 100 GB of working space. No time limit; it starts in about half a minute, stops when the video is done, and costs only while it runs. Full task definition in section 6.3 |
| Alarms | Trinity-Beast-Lambda-Errors-tbi-field-media-processor, Trinity-Beast-FieldMedia-VideoTask-Problems | Email the operations list when the processor fails, or when a video task logs an error or stops before finishing |
| Website bucket | trinity-beast-website-east2 | Public copies under map-pins/, served by the CDN at cpmp-site.org |