Skip to content
Syno Package Land
Language: English

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.

Create a project with the capability, or add it to a native-go project:

Terminal window
synopkgland init -t native-go --with delegate my-app
Terminal window
synopkgland add delegate

Both 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
FieldAllowed values
scopeinstall-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).
lifetimeuntil-revoked
operations[files.moveFromStaging]
destinations1 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.

The settings page uses BackgroundSaveSettings: one Save folder row per destination key, with Choose folder and Revoke access.

WhoWhat happens
Administrator, install-selectedChooses 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 userChooses 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 APISelects 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.

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:

  1. While the user’s session is live, look up the destination with svc.Destination(ctx, caller, request, "save") and keep Destination.ID in your job record.
  2. Produce the file in svc.StagingDir with mode 0600.
  3. 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.

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.

RuleValue
Separator/; no leading or trailing /, no empty, . or .. part.
Folder names1 to 255 bytes, no control characters, none of \ : * ? " < > |; not #recycle, #snapshot or @eaDir (any case).
File nameThe same rule as a name without folders.
Folders, whole nameAt most 16 levels and 1024 bytes.
UnicodeStored as sent, not normalized; send NFC to match Windows-typed names in File Station.
Symlinks and mountsA symlink, file or other volume in the name is refused with destination-not-directory.

Conflict decides what happens when the file name is taken:

ConflictEffect
fail or emptyDefault; fails with destination-exists.
overwriteWrites under a temporary name, then renames over the old file, so a failed move leaves it whole; only a writable regular file is replaced.
renamePublishes name (1).ext to name (99).ext; receipt.path reports the name used.

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.

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.

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 returns POLICY_DENIED, one outside the grant DELEGATION_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 is not-found.
  • Copy and Move refuse a taken name unless you pass delegate.ConflictOverwrite and have no rename policy.
  • Delete of a folder needs Recursive: true (recursive-required); without a recycle bin it returns recycle-bin-disabled unless you set Permanent: true.

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.

LimitValue
Backend, architecturesnative-go only; x86_64, aarch64 and armv7 (armv7 not verified on a NAS)
File size moved16 GiB
Queued saves, concurrent copies16; 1
One copy attempt, tasks tracked24 hours; 64
Destination keys, folders in name1 to 64; 16 levels and 1024 bytes
files.read, conflict: rename64 MiB; name (1) to name (99)
Approval on DSM 7.1Uses 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.

Symptom or codeFix
needs-admin-approvalAn administrator approves again in settings.
needs-scope-confirmationAn administrator confirms the scope with the user password.
disabled, revoked, reselection-requiredAn administrator enables saves, or the user picks the destination again.
destination-exists, invalid-destinationUse a new name with a new JobID, set conflict, or fix the key.
invalid-path, path-too-deep, destination-not-directoryFix the folder name; use a new JobID.
PERMISSION_DENIED, NO_SPACEFix the permission or free space.
queue-full, EXECUTOR_PAUSEDWait, start the package, or approve.
session_required, admin_requiredSign in again, or call it as an administrator.

Other codes are listed in Errors.