# drive_link_save

Create or Update Share Link

## Beschreibung

Linear-style upsert. Omit `id` to mint a fresh share link for
the given file. Pass `id` (dlk_…) to update expiry or password
on an existing link. Same primitives as the in-app share modal:

- `expires_at` — ISO 8601, date-only, or relative offset
  (`+7d`, `+2h`). Null / omitted = no expiry.
- `password` — plaintext; hashed via has_secure_password AND
  stored plaintext-encrypted so a manager can look it up later.
  Null / omitted on create = no password. On update, omit to
  keep existing; pass empty string to clear.

Manager on the drive is required (Pundit DriveLinkPolicy).
Returns the public `/links/:token` URL.

## Zugriff

Zugriffsprofil: `gated`. Module: `files`.
Die Freigabe im Profil ersetzt keine Account-, Workspace- oder Rollenberechtigung.

## Parameter

| Name | Typ | Pflicht | Beschreibung |
| --- | --- | --- | --- |
| `account_id` | string | Ja |  |
| `id` | string | Nein | DriveLink prefix ID (dlk_…). Omit to create. |
| `file_id` | string | Nein | File prefix ID (dfi_…). Required on create. |
| `expires_at` | string / null | Nein | ISO 8601, date, or relative offset (`+7d`). |
| `password` | string / null | Nein | Plaintext password. Empty string clears on update. |

## Eingabeschema

```json
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "properties": {
    "account_id": {
      "type": "string"
    },
    "id": {
      "type": "string",
      "description": "DriveLink prefix ID (dlk_…). Omit to create."
    },
    "file_id": {
      "type": "string",
      "description": "File prefix ID (dfi_…). Required on create."
    },
    "expires_at": {
      "type": [
        "string",
        "null"
      ],
      "description": "ISO 8601, date, or relative offset (`+7d`)."
    },
    "password": {
      "type": [
        "string",
        "null"
      ],
      "description": "Plaintext password. Empty string clears on update."
    }
  },
  "required": [
    "account_id"
  ],
  "type": "object"
}
```

## Ausgabeschema

```json
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "properties": {
    "id": {
      "type": "string"
    },
    "file_id": {
      "type": "string"
    },
    "token": {
      "type": "string"
    },
    "public_url": {
      "type": "string"
    },
    "expires_at": {
      "type": [
        "string",
        "null"
      ],
      "format": "date-time"
    },
    "password_protected": {
      "type": "boolean"
    },
    "revoked": {
      "type": "boolean"
    },
    "created": {
      "type": "boolean"
    }
  },
  "required": [
    "id",
    "file_id",
    "token",
    "public_url",
    "expires_at",
    "password_protected",
    "revoked",
    "created"
  ],
  "type": "object"
}
```
