Work for a user while they are offline
Status: delegate is implemented; device lifecycle acceptance on real hardware is pending. The default grant allows one operation, files.moveFromStaging.
A delegate lets your package keep saving files for a DSM user after that user closes the browser. An administrator approves a save scope once, each user picks a destination folder inside it, and your jobs then move finished files there with that user’s own permissions until the user or an administrator revokes access. The package never writes as root and never replaces a file unless you ask it to.
Add it
Section titled “Add it”Create a project with the capability, or add it to a native-go project:
synopkgland init -t native-go --with delegate my-appsynopkgland add delegateBoth write this block to dsm-package.yaml; delegate also turns on jobs.
capabilities: delegate: scope: install-selected operations: [files.moveFromStaging] destinations: [save] lifetime: until-revoked| Field | Allowed values |
|---|---|
scope | install-selected: an administrator picks home or one Shared Folder after install. home: each user’s home folder. shared:<name>: one Shared Folder (no /, \, : or control characters). |
lifetime | until-revoked |
operations | [files.moveFromStaging] |
destinations | 1 to 64 unique keys matching ^[a-z][a-z0-9_-]{0,63}$, not paths. |
install-selected requires lifetime: until-revoked; a partial destinations, lifetime or operations setting must still use all four values.
init --with delegate sets backend/internal/api/permissions.json, add delegate does not. Set "app.status": "authenticated" there for ordinary users; methods default to administrators.
The first synopkgland deploy of an install-selected project must pass --param delegate_share=<Shared Folder> or --param delegate_home=true, or it fails with DEPLOY_PARAM_REQUIRED before building. An upgrade keeps the confirmed scope. synopkgland status reports the approval as ready, needs-admin-approval or blocked; with identity: standalone, use an https:// host, since status reads the executor through an App session that needs HTTPS.
What each person sees
Section titled “What each person sees”The settings page uses BackgroundSaveSettings: one Save folder row per destination key, with Choose folder and Revoke access.
| Who | What happens |
|---|---|
Administrator, install-selected | Chooses the home scope or a Shared Folder root and enters the user password; that submission approves the scope through the executor root task, reads it back, and grants the root as their own destination. |
| Ordinary user | Chooses a folder inside the approved scope through the scoped NAS picker, creating their grant after checking the live DSM session and write permission; no password or second consent. |
User, fixed home or shared:<name> | Chooses a destination inside the manifest’s scope. |
| Administrator, saves disabled through the API | Selects Enable background saves; users choose again. |
Opening settings keeps existing destinations; a new confirmed scope revokes all grants and cancels pending saves, while saved files stay. Revoke access affects only the signed-in user.
The plain UI approves in the DSM window’s own panel, which sends no scope, so it works only with home or shared:<name>; install-selected needs a Vue UI. init --ui plain --with delegate fails with CAPABILITY_COMBINATION_INVALID, and check refuses that scope with a plain UI.
Use it
Section titled “Use it”backend/internal/app/delegate.go builds a delegate.Service from github.com/synopackageland/syno-pkg-land-sdk/delegate and registers its routes. Its one working producer, delegate/example.go, method delegate.example.export, is exposed by BackgroundSavePanel through the opt-in sampleSave flag. An acknowledgement does not mean the file is saved:
- While the user’s session is live, look up the destination with
svc.Destination(ctx, caller, request, "save")and keepDestination.IDin your job record. - Produce the file in
svc.StagingDirwith mode0600. - With no session later, move it with
svc.MoveFromStaging, which refuses to run as root.
selected, err := svc.Destination(ctx, caller, request, "save")// ... write the finished file into svc.StagingDir as <name> ..._, err = svc.MoveFromStaging(ctx, delegate.MoveParams{ DelegationID: selected.Destination.ID, JobID: jobID, Staging: name, Name: name, Size: size,})A repeated JobID returns the original operation; use a new one per file.
Your UI calls these with ctx.call; each needs a live DSM session, otherwise session_required. Arguments and permissions are in the API reference, and delegate.disable and delegate.enable are administrator methods that end all grants.
A save ends as committed with a receipt ({path, size}), canceled, interrupted or uncertain. Do not retry the last two automatically: check the destination first. A user cancel reports operation-canceled-by-user, grant-revoked, scope-changed, integration-disabled or destination-replaced; an executor stop reports grant-revoked, validation-denied, integration-disabled or storage-error and removes the partial file.
Subfolders and name conflicts
Section titled “Subfolders and name conflicts”Name can name folders below the destination, for example Album/CD1/01.flac. Missing folders are created as the user with their own DSM permissions, so owner and inherited ACL match a File Station folder; existing folders are reused, and a canceled move leaves none.
| Rule | Value |
|---|---|
| Separator | /; no leading or trailing /, no empty, . or .. part. |
| Folder names | 1 to 255 bytes, no control characters, none of \ : * ? " < > |; not #recycle, #snapshot or @eaDir (any case). |
| File name | The same rule as a name without folders. |
| Folders, whole name | At most 16 levels and 1024 bytes. |
| Unicode | Stored as sent, not normalized; send NFC to match Windows-typed names in File Station. |
| Symlinks and mounts | A symlink, file or other volume in the name is refused with destination-not-directory. |
Conflict decides what happens when the file name is taken:
Conflict | Effect |
|---|---|
fail or empty | Default; fails with destination-exists. |
overwrite | Writes under a temporary name, then renames over the old file, so a failed move leaves it whole; only a writable regular file is replaced. |
rename | Publishes name (1).ext to name (99).ext; receipt.path reports the name used. |
Combine with a daemon
Section titled “Combine with a daemon”A daemon can run next to the delegate’s jobs only when the delegate uses lifetime: until-revoked. See Manifest reference for the daemon fields.
Time-limited grants
Section titled “Time-limited grants”Leave destinations, lifetime and files.moveFromStaging unset and the delegate is time-limited: operations is any unique subset of the file operations below, and scope is home or shared:<name>. delegate.create takes a ttl_seconds from 1 to 3600 and that grant’s operations. The generated worker runs only download and SHA-256 jobs, at most 64 MiB and 60 seconds; anything else returns POLICY_DENIED. Its URL downloads reach public networks only: loopback, private, link-local and metadata addresses are refused, a DNS answer that mixes public and private addresses is refused, and redirects are not followed.
File operations
Section titled “File operations”A job calls them through job.Files(), with every path inside the grant folder; the executor checks each path before the call and rechecks what File Station reports back. Except for files.write and files.read, it calls synowebapi as the user, so DSM applies that user’s permissions, and only an allowlist of methods works this way. See Read and write user files.
| Operation (Go method) | Needs |
|---|---|
files.list, files.info (List, Info) | Read |
files.createFolder (CreateFolder, CreateFolderAll) | Write on the parent; CreateFolderAll makes missing parents |
files.checkPermission (CheckPermission) | None; writes and removes a probe file |
files.write (Write) | Write; at most 64 MiB from staging |
files.read (Read) | Read; a regular file of at most 64 MiB |
files.rename (Rename) | Modify |
files.copy (Copy) | Read on the source, write on the destination |
files.move (Move) | Delete on the source, write on the destination |
files.delete (Delete) | Delete |
Rules:
- Declare each operation you use; a write never implies
files.delete. An operation outside the policy returnsPOLICY_DENIED, one outside the grantDELEGATION_DENIED. - The grant folder itself cannot be renamed, copied, moved or deleted (
SCOPE_DENIED), and neither can a path outside it or through a symlink; a missing path inside it isnot-found. CopyandMoverefuse a taken name unless you passdelegate.ConflictOverwriteand have norenamepolicy.Deleteof a folder needsRecursive: true(recursive-required); without a recycle bin it returnsrecycle-bin-disabledunless you setPermanent: true.
Long-running file operations
Section titled “Long-running file operations”Copy, Move and Delete return a TaskState with a TaskID; poll TaskStatus until State is finished, failed (with Error) or canceled. Progress runs from 0 to 1, and CancelTask stops it. Only the starting job can follow a task; revoking the grant stops its tasks.
files := job.Files()task, err := files.Move(ctx, "/home/Downloads/album", "/home/Music", "")for err == nil && task.State == "running" { time.Sleep(time.Second) task, err = files.TaskStatus(ctx, task.TaskID)}File Station reports refusals per item; the executor returns that item’s code: PERMISSION_DENIED, destination-exists, not-found, name-too-long, NO_SPACE, or destination-not-directory for CreateFolder below a file. None are retryable; a delete that leaves the item behind fails with PERMISSION_DENIED or DSM_FAILED.
The executor tracks at most 64 tasks, returning task-not-found after a restart; State is unknown when DSM dropped the task, so check with Info. Reporting a task to a later synowebapi process is unverified on a NAS.
Limits
Section titled “Limits”| Limit | Value |
|---|---|
| Backend, architectures | native-go only; x86_64, aarch64 and armv7 (armv7 not verified on a NAS) |
| File size moved | 16 GiB |
| Queued saves, concurrent copies | 16; 1 |
| One copy attempt, tasks tracked | 24 hours; 64 |
Destination keys, folders in name | 1 to 64; 16 levels and 1024 bytes |
files.read, conflict: rename | 64 MiB; name (1) to name (99) |
| Approval on DSM 7.1 | Uses the 7.1 scheduler APIs; see Root operations |
An upgrade resumes saving only if the approved policy still matches; otherwise the app stays at needs-admin-approval. Changing scope, destinations, operations, lifetime or entry needs a new administrator approval. Uninstall removes the approval and grants; see Data and removal.
Troubleshooting
Section titled “Troubleshooting”| Symptom or code | Fix |
|---|---|
needs-admin-approval | An administrator approves again in settings. |
needs-scope-confirmation | An administrator confirms the scope with the user password. |
disabled, revoked, reselection-required | An administrator enables saves, or the user picks the destination again. |
destination-exists, invalid-destination | Use a new name with a new JobID, set conflict, or fix the key. |
invalid-path, path-too-deep, destination-not-directory | Fix the folder name; use a new JobID. |
PERMISSION_DENIED, NO_SPACE | Fix the permission or free space. |
queue-full, EXECUTOR_PAUSED | Wait, start the package, or approve. |
session_required, admin_required | Sign in again, or call it as an administrator. |
Other codes are listed in Errors.