TheDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/S4nti4goCoder/cloudsyncpro/llms.txt
Use this file to discover all available pages before exploring further.
purge-files Edge Function permanently removes files from both Cloudflare R2 object storage and the files Postgres table. It handles three distinct scenarios through a single mode field: deleting specific file IDs chosen by a user, emptying all trash in a workspace, and the daily scheduled job that auto-purges trash older than 30 days. Only files already in status = 'deleted' (i.e. in the trash) are eligible for purging.
Endpoint
Authentication
The function supports two authentication modes depending on themode value:
User-initiated modes (user_ids, user_workspace_trash): include a Bearer token and apikey header. The function validates the JWT, resolves the caller’s identity, and checks has_workspace_edit_permission before deleting anything.
Cron mode (auto_purge): include the X-Cron-Secret header containing the value of the CRON_SECRET environment variable. No user JWT is required. This header is sent by the Supabase pg_cron job that runs daily at 03:15 UTC.
| Header | Required for |
|---|---|
Authorization: Bearer <access_token> | user_ids, user_workspace_trash |
apikey: <anon_key> | user_ids, user_workspace_trash |
x-cron-secret: <cron_secret> | auto_purge |
Request body
Controls which files are purged and how the caller is authenticated. One of
"user_ids", "user_workspace_trash", or "auto_purge".Required when
mode is "user_ids". An array of file UUIDs to purge. Only files visible to the caller via RLS and with status = 'deleted' are deleted. Files that fail the RLS check are silently skipped.Required when
mode is "user_workspace_trash". UUID of the workspace whose entire trash should be emptied.Mode reference
| Mode | Triggered by | Deletes | Auth |
|---|---|---|---|
user_ids | User selects specific files | Specific file IDs (must be in trash) | Bearer token |
user_workspace_trash | User clicks “Empty trash” | All trashed files in one workspace | Bearer token |
auto_purge | pg_cron daily job | All trashed files older than 30 days | X-Cron-Secret |
Response
Number of file rows deleted from Postgres.
Number of R2 objects successfully deleted. May be less than
purged if some R2 deletions failed; the database rows are still removed in that case to avoid ghost entries in the UI.Error responses
| Status | Error message | Cause |
|---|---|---|
400 | Missing "mode" field | The request body did not include a mode |
400 | Missing ids | mode is "user_ids" but ids is absent or empty |
400 | Missing workspaceId | mode is "user_workspace_trash" but workspaceId is absent |
400 | Invalid mode | mode is not one of the three recognised values |
401 | Missing Authorization | User-initiated request sent without an Authorization header |
401 | Unauthorized | Bearer token is invalid or expired |
403 | Forbidden | Caller lacks edit permission in one of the affected workspaces |
403 | auto_purge requires valid cron secret | X-Cron-Secret header is missing or does not match CRON_SECRET |
500 | (error message) | Postgres query or R2 batch deletion failed |
Examples
200 immediately: