Keep Drive files in named folders of one shared drive

GOOGLE_SHARED_DRIVE (the shared drive's bare id) replaces
GOOGLE_DRIVE_FOLDER. driveUpload takes a folder path, found by name in
the shared drive or made the first time, so each use gets its own
folder: "Requests" for the Request form now, others later. The docs
say plainly that the setting is the id only, not the address.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Zaldimmar 2026-09-29 16:53:40 -05:00
parent e7743829be
commit 0f6a796021
4 changed files with 113 additions and 30 deletions

View file

@ -1,7 +1,9 @@
# Google Drive and Gmail (the Request form)
The Request form (`/request`) keeps the files people send in a Google
Drive folder, and new requests can be emailed to whoever is listed in
The site keeps files in one Google **shared drive**: the Request form
(`/request`) puts what people send in its "Requests" folder, and later
uses (eg. files linked from blog posts) get folders of their own. New
requests can be emailed to whoever is listed in
Panel → Site settings → Notices. Both go through one Google **service
account** (`server/src/googleService.js`). Nothing here is needed for
the rest of the site; until it's set up, the form takes no files and no
@ -10,7 +12,7 @@ mail goes out.
| Setting on the `ngu-api` service | What it is |
| --- | --- |
| `GOOGLE_SERVICE_ACCOUNT` | Path to the service account's key file, eg. `/etc/ngu/google-service-account.json` |
| `GOOGLE_DRIVE_FOLDER` | The Drive folder's id (the last part of its URL) |
| `GOOGLE_SHARED_DRIVE` | The shared drive's **id only**, eg. `0ACUt32ze-CVGUk9PVA`: never the whole address (see step 2) |
| `GOOGLE_MAIL_FROM` | The Workspace address notices are sent from, eg. `web@nextgenerationofunity.org` |
Files need the first two; mail needs the first and third.
@ -35,21 +37,43 @@ Files need the first two; mail needs the first and third.
Note the account's email (`ngu-site@<project>.iam.gserviceaccount.com`)
and, from its Details page, its **Client ID** (a long number).
## 2. The Drive folder
## 2. The shared drive
A service account has no Drive storage of its own, so the folder must
be in a **shared drive**.
A service account has no Drive storage of its own, so everything goes in
a **shared drive**.
1. In Google Drive, make (or pick) a shared drive, eg. "NGU Website",
and a folder in it, eg. "Requests".
1. In Google Drive, make (or pick) a shared drive, eg. "NGU Website".
2. Shared drive → Manage members → add the service account's email as
**Content manager**.
3. Open the folder; its id is the end of the address:
`https://drive.google.com/drive/folders/<this part>`.
**Content manager** (it makes folders and deletes files).
3. Open the shared drive itself (not a folder in it). Its address is
`https://drive.google.com/drive/u/2/folders/0ACUt32ze-CVGUk9PVA`;
the id is only the part after `folders/`, here `0ACUt32ze-CVGUk9PVA`.
A shared drive's id starts with `0A`. Leave out the address, the
`/u/2/` part and anything after a `?`: pasting the whole URL gives
`404 File not found` on every upload.
Files are named `Request 12 - original name.docx`, so the number matches
the one in Forms → Content requests. Deleting a request in the admin
deletes its files from Drive too.
### Folders in it
The site finds each folder it uses by name, at the top of the shared
drive, and makes it the first time it's needed. Nothing needs making by
hand.
| Folder | Used by | Set in |
| --- | --- | --- |
| `Requests` | Files sent with the Request form | `DRIVE_FOLDER` in `server/src/routes/requests.js` |
A new use calls `driveUpload("<Folder>", name, mime, bytes)` from
`server/src/googleService.js`; a path such as `"Blog/2026"` makes each
level. Add it to this table.
Folders are matched by name, so renaming or moving one in Drive makes
the site start a new one under the old name (files already stored keep
working: they're found by their own id). People can add their own
folders to the drive; the site ignores them.
Request files are named `Request 12 - original name.docx`, so the number
matches the one in Forms → Content requests. Deleting a request in the
admin deletes its files from Drive too.
## 3. Gmail (domain-wide delegation)
@ -77,7 +101,7 @@ sudo systemctl edit ngu-api
```ini
[Service]
Environment=GOOGLE_SERVICE_ACCOUNT=/etc/ngu/google-service-account.json
Environment=GOOGLE_DRIVE_FOLDER=<folder id>
Environment=GOOGLE_SHARED_DRIVE=<shared drive id, eg. 0ACUt32ze-CVGUk9PVA>
Environment=GOOGLE_MAIL_FROM=web@nextgenerationofunity.org
```
@ -101,12 +125,13 @@ location = /api/requests {
- Send a request with a small file at `/request`. The journal shows
`feedback #N (content: new blog, 1 files)`, and with mail on,
`feedback #N: notice sent to 1`.
- The file is in the Drive folder, and downloads from Forms → Content
- The file is in the shared drive's Requests folder (made on the first upload), and downloads from Forms → Content
requests.
- `token refused: unauthorized_client` on mail means the delegation
(step 3) is missing or has the wrong Client ID or scope. `404 File not
found` on upload means the folder id is wrong or the service account
isn't a member of the shared drive.
found` on upload means `GOOGLE_SHARED_DRIVE` isn't the bare id (a
whole URL, say) or the service account isn't a member of the shared
drive.
## What the form takes