Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ The backend (`fastapi_backend`) and the frontend (`nextjs-frontend`) are version
shows only Projects, Areas, Resources or Archive, and each note says which notes it's inside. Jump to (⌘K) finds notes
as well. `GET /api/v1/notes/search`; `find_notes` gives agents the words around each match
([Finding notes](docs/notes.md#finding-notes)).
- **Paste a Drive folder's link.** A Google Drive connection's Root folder and shared drive take the link from the
browser's address bar as well as the bare id, so limiting imports to one folder is a paste, not hunting for the id.

## 0.10.0 <small>October 15, 2026</small> {id="0.10.0"}

Expand Down
3 changes: 3 additions & 0 deletions docs/processing.md
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,9 @@ files, then Import (`POST /api/v1/import/source`). The listing marks files that
- Google Drive can also sign in as a service account: choose Service account and upload its JSON key file
(`service_account_credentials`). Share the folders Lens should read with the account's address, or give a shared
drive ID (`team_drive`); in Google Workspace, `impersonate` reads a user's own Drive through domain-wide delegation.
- To import from one Drive folder only, set Root folder (`root_folder_id`): paste the folder's link from the address
bar (`https://drive.google.com/drive/folders/<id>`, `open?id=<id>`) or its id; Lens keeps the id. The shared drive
takes its link the same way. A file's link is refused with a note to paste its folder's.
- A rate-limited connection (Google Drive throttling an account) still works: its check shows it working, slowly;
rclone backs off and retries (Drive gets 10 low-level retries); and a file a scan couldn't fetch waits for the next
scan, as do the rest of that scan's files, rather than failing for good.
Expand Down
26 changes: 26 additions & 0 deletions fastapi_backend/app/domain/sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,30 @@ def cached_copy(db, cfg, sid, path, space=None):


# ---------- managing sources ----------
DRIVE_FOLDER = re.compile(r"/folders/([\w-]+)|[?&]id=([\w-]+)")


def _drive_folder(k, v):
"""A Drive folder's id from its link as the browser shows it (…/drive/u/0/folders/<id>?usp=sharing, open?id=<id>),
or the id as given."""
v = str(v or "").strip()
if "/" not in v and "?" not in v:
return v
if "/file/d/" in v or "/document/d/" in v or "/spreadsheets/d/" in v:
raise ValueError(f"{k}: that link is a file's; open the folder it's in and paste that link")
m = DRIVE_FOLDER.search(v)
if not m:
raise ValueError(f"{k}: paste the folder's link from Drive, or its id")
return m[1] or m[2]


def tidy(typ, params):
"""Options as people paste them, as rclone wants them: a Drive folder's or shared drive's link becomes its id."""
if typ != "drive" or not params:
return params
return {k: _drive_folder(k, v) if k in ("root_folder_id", "team_drive") and v else v for k, v in params.items()}


def _check_params(typ, params, secret_values):
spec = BACKENDS.get(typ)
if not spec:
Expand All @@ -352,6 +376,7 @@ def _secret(typ, k, v):

def create(db, cfg, name, typ, params=None, secret_values=None, user=None):
spec = _check_params(typ, params, secret_values)
params = tidy(typ, params)
plain = {k: _secret(typ, k, v) for k, v in (secret_values or {}).items() if isinstance(v, str) and v}
sid = db.next_id("storage_source")
sealed = {k: settings.seal(cfg, v, f"source:{sid}:{k}") for k, v in plain.items()}
Expand All @@ -375,6 +400,7 @@ def create(db, cfg, name, typ, params=None, secret_values=None, user=None):
def update(db, cfg, sid, name=None, params=None, secret_values=None):
src = get(db, sid)
_check_params(src["type"], params, secret_values)
params = tidy(src["type"], params)
sealed = dict(src.get("sealed") or {})
for k, v in (secret_values or {}).items():
if v is None or v == "":
Expand Down
27 changes: 27 additions & 0 deletions fastapi_backend/tests/api/test_sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,3 +320,30 @@ def test_google_drive_as_a_service_account(client, db, cfg, monkeypatch):
assert r.status_code == 400 and "service account" in r.text
r = client.patch(f"/api/v1/sources/{sid}", json={"secrets": {"service_account_credentials": "{}"}}, headers=h)
assert r.status_code == 400


def test_a_drive_folder_link_is_kept_as_its_id(client, db, monkeypatch):
"""The root folder and shared drive take the link Drive shows in the address bar, as well as the bare id."""
monkeypatch.setattr(sources, "test", lambda *a, **k: {"ok": True})
make_user(db, "root@x.io", "root password 1", admin=True)
h = login(client, "root@x.io", "root password 1")
links = {
"https://drive.google.com/drive/folders/1AbC-d_E?usp=sharing": "1AbC-d_E",
"https://drive.google.com/drive/u/1/folders/1XyZ": "1XyZ",
"https://drive.google.com/open?id=1Open&authuser=0": "1Open",
" 1Bare ": "1Bare",
}
for link, fid in links.items():
body = {
"name": "Drive",
"type": "drive",
"params": {"root_folder_id": link, "team_drive": "https://drive.google.com/drive/folders/0AShared"},
}
sid = client.post("/api/v1/sources", json=body, headers=h).json()["id"]
params = sources.get(db, sid)["params"]
assert params["root_folder_id"] == fid and params["team_drive"] == "0AShared", link
client.patch(f"/api/v1/sources/{sid}", json={"params": {"root_folder_id": "https://drive.google.com/drive/folders/1Moved"}}, headers=h)
assert sources.get(db, sid)["params"]["root_folder_id"] == "1Moved"
for bad, why in (("https://drive.google.com/file/d/1File/view", "a file's"), ("https://example.com/somewhere", "folder's link")):
r = client.post("/api/v1/sources", json={"type": "drive", "params": {"root_folder_id": bad}}, headers=h)
assert r.status_code == 400 and why in r.json()["detail"], r.text
6 changes: 4 additions & 2 deletions nextjs-frontend/components/sources/connection-fields.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -231,15 +231,17 @@ export function ConnectionFields({
{select("scope", DRIVE_SCOPES)}
{text("root_folder_id", {
mono: true,
label: "Root folder ID",
label: "Root folder",
optional: true,
hint: "From the folder’s URL; limits the connection to that folder",
placeholder: "Folder link or ID",
hint: "Paste the folder’s link from Drive; the connection only sees that folder",
})}
{form.driveAuth === "service_account" && (
<div className="grid grid-cols-2 gap-2.5">
{text("team_drive", {
mono: true,
optional: true,
placeholder: "Shared drive link or ID",
hint: "Read a shared drive the account is a member of",
})}
{text("impersonate", {
Expand Down
4 changes: 2 additions & 2 deletions nextjs-frontend/components/sources/source-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ export const FIELD_LABEL: Record<string, string> = {
secret_access_key: "Secret access key",
token: "Token",
scope: "Scope",
root_folder_id: "Root folder ID",
team_drive: "Shared drive ID",
root_folder_id: "Root folder",
team_drive: "Shared drive",
impersonate: "Act as user",
service_account_credentials: "Service account key",
drive_id: "Drive ID",
Expand Down
Loading