### Install Plik Go Client Library Source: https://root-gg.github.io/plik/reference/go-library.html Installs the Plik Go client library using the go get command. This is the first step to using the library in your Go projects. ```bash go get -v github.com/root-gg/plik/plik ``` -------------------------------- ### Install Plik Server from Source Source: https://root-gg.github.io/plik/guide/installation.html Compile the Plik server from its source code using Go and Node.js. This method requires cloning the repository and running make commands before starting the server. ```bash git clone https://github.com/root-gg/plik.git cd plik && make cd server && ./plikd ``` -------------------------------- ### Install Plik Server from Release Archive Source: https://root-gg.github.io/plik/guide/installation.html Download the latest Plik server release archive, extract it, and run the server executable. Configuration can be adjusted via `plikd.cfg`. Standalone client binaries are also available. ```bash wget https://github.com/root-gg/plik/releases/download/1.4.1/plik-server-1.4.1-linux-amd64.tar.gz tar xzvf plik-server-1.4.1-linux-amd64.tar.gz cd plik-server-1.4.1/server ./plikd ``` -------------------------------- ### Install Plik Server and Client on Debian/Ubuntu Source: https://root-gg.github.io/plik/guide/installation.html Install Plik server and client packages on Debian-based systems using an APT repository hosted on GitHub Pages. This includes adding the repository, updating package lists, and installing the desired packages. ```bash # Add the repository curl -fsSL https://root-gg.github.io/plik/apt/gpg.key | sudo gpg --dearmor -o /etc/apt/keyrings/plik.gpg echo "deb [signed-by=/etc/apt/keyrings/plik.gpg] https://root-gg.github.io/plik/apt stable main" | sudo tee /etc/apt/sources.list.d/plik.list sudo apt update # Install server sudo apt install plik-server sudo systemctl start plikd # Or install just the CLI client sudo apt install plik-client ``` -------------------------------- ### Example: Upload Multiple Files Source: https://root-gg.github.io/plik/features/mcp.html An example demonstrating how an AI assistant can upload multiple files simultaneously using the `upload_files` tool provided by the Plik MCP server. ```json { "tool": "upload_files", "args": { "files": [ "/path/to/file1.txt", "/path/to/file2.js" ], "ttl": 3600, "comments": "Files for review" } } ``` -------------------------------- ### Server Setup Source: https://root-gg.github.io/plik/architecture/server.html Details on the Plik HTTP server setup, including initialization, middleware chaining, routing, and shutdown procedures. ```APIDOC ## HTTP Server Setup `PlikServer` is the main server struct. It: 1. Initializes backends (metadata, data, stream) and authenticator 2. Builds middleware chains (see root ARCHITECTURE.md for chain table) 3. Configures gorilla/mux router with all routes 4. Starts HTTP server via `net.Listen` + `httpServer.Serve` (supports ephemeral port allocation with `ListenPort: 0`) 5. Starts cleaning routine (if auto-clean enabled) 6. Starts metrics HTTP server (if configured) After start, call `GetListenPort()` to retrieve the actual listen port (useful when configured with port 0). Shutdown: graceful with configurable timeout, closes HTTP server + metadata backend. ``` -------------------------------- ### Install Plik Server using Docker Source: https://root-gg.github.io/plik/guide/installation.html Deploy Plik using official multiarch Docker images. This command maps the default Plik port to the host. Various tags are available for different releases and development versions. ```bash docker run -p 8080:8080 rootgg/plik ``` -------------------------------- ### Local Development Server for Docs Source: https://root-gg.github.io/plik/architecture/system.html Command to start a local development server for the VitePress documentation site. This allows for real-time previewing of changes. ```bash cd docs && npm run dev ``` -------------------------------- ### Plik Client Configuration (.plikrc) Example Source: https://root-gg.github.io/plik/features/cli-client.html Provides an example of the Plik client configuration file (`.plikrc`) in TOML format. This file allows customization of various client settings, including server URL, encryption methods, archive settings, and authentication tokens. ```toml # ~/.plikrc Debug = false # be more verbose Quiet = false # be less verbose URL = "https://plik.root.gg" # URL of the plik server OneShot = false # Set the uploads to be one shot by default (if available server side) Removable = false # Set the uploads to be removable by default (if available server side) Stream = false # Set the uploads to be stream by default (if available server side) Secure = false # Set the uploads to be encrypted by default SecureMethod = "age" # Set the default encryption method (age|openssl|pgp) Archive = false # Set the uploads to be archives by default ArchiveMethod = "tar" # Set the default archive method DownloadBinary = "curl" # Set the default download command (curl / wget) Comments = "" # Set the default upload comments Login = "" # Set the default upload login (http basic auth) Password = "" # Set the default upload password (http basic auth) TTL = 0 # Set the default upload TTL (0 for server default) ExtendTTL = false # Set the uploads to extend TTL by default (if available server side) AutoUpdate = true # Enable/Disable auto update mechanism Token = "" # Set the Authentication Token (can be created from the UI) DisableStdin = false # Disable STDIN input Insecure = false # Disable HTTPS certificate validation [ArchiveOptions] Compress = "gzip" Options = "" Tar = "/bin/tar" ``` -------------------------------- ### GET /config Source: https://root-gg.github.io/plik/architecture/system.html Retrieves the server configuration, including feature flags and global limits. ```APIDOC ## GET /config ### Description Returns the current server configuration, which is useful for clients to determine available features and enforced limits. ### Method GET ### Endpoint /config ### Response #### Success Response (200) - **MaxFileSize** (int64) - Global max file size limit. - **MaxTTL** (int) - Global max TTL limit. #### Response Example { "MaxFileSize": 104857600, "MaxTTL": 3600 } ``` -------------------------------- ### Bootstrap Test Server and Client Source: https://root-gg.github.io/plik/architecture/library.html Illustrates the setup of a transient Plik server and client pair for integration testing, including proper resource cleanup. ```go ps, pc := newPlikServerAndClient() defer shutdown(ps) err := startWithClient(ps, pc) ``` -------------------------------- ### Deploy Plik with Docker Source: https://root-gg.github.io/plik/features/web-ui.html Example command to run the Plik container while mounting custom configuration and styling files from the host machine. ```bash docker run -p 8080:8080 \ -v ./settings.json:/home/plik/server/webapp/dist/settings.json:ro \ -v ./custom.css:/home/plik/server/webapp/dist/css/custom.css:ro \ rootgg/plik ``` -------------------------------- ### Plik CLI Decryption Examples Source: https://root-gg.github.io/plik/features/encryption.html Provides examples for decrypting files uploaded with Plik's end-to-end encryption using the 'age' command. Covers decryption for passphrase-encrypted files, recipient-encrypted files (like SSH keys), and files encrypted for server SSH host keys. ```bash # Decrypt a passphrase-encrypted file curl | age --decrypt # Decrypt a recipient-encrypted file (e.g. GitHub SSH key) curl | age --decrypt -i ~/.ssh/id_ed25519 # Decrypt a file encrypted for a server's SSH host key (requires root) curl | age --decrypt -i /etc/ssh/ssh_host_ed25519_key > secret_file ``` -------------------------------- ### Nginx Configuration for Multi-Instance Deployment Source: https://root-gg.github.io/plik/features/streaming.html Provides an example Nginx configuration using LUA scripting to ensure that stream requests are routed to the same Plik instance based on the file ID. ```APIDOC ## Nginx Configuration for Multi-Instance Deployment ### Description This configuration demonstrates how to use Nginx with LUA scripting to route stream requests to the correct Plik instance in a multi-instance deployment. It ensures that both the uploader and downloader for a specific file ID are directed to the same server instance, which is crucial because stream mode is stateful. ### Configuration This example assumes you have multiple Plik instances running on ports 8080 and 8081, and you want to expose them through a single entry point on port 9000. ### Nginx Configuration Example ```nginx upstream plik { server 127.0.0.1:8080; server 127.0.0.1:8081; } upstream stream { server 127.0.0.1:8080; server 127.0.0.1:8081; hash $hash_key; } server { listen 9000; location / { set $upstream ""; set $hash_key ""; access_by_lua ' _,_,file_id = string.find(ngx.var.request_uri, "^/stream/[a-zA-Z0-9]+/([a-zA-Z0-9]+)/.*$") if file_id == nil then ngx.var.upstream = "plik" else ngx.var.upstream = "stream" ngx.var.hash_key = file_id end '; proxy_pass http://$upstream; } } ``` ### Explanation - The `plik` upstream handles regular (non-stream) requests with standard load balancing. - The `stream` upstream uses `hash $hash_key;` to ensure consistent routing based on the extracted `file_id`. - The `access_by_lua` block extracts the `file_id` from the request URI for `/stream/` requests and sets the `$hash_key` and `$upstream` variables accordingly. If no `file_id` is found (i.e., it's not a stream request), it defaults to the `plik` upstream. ``` -------------------------------- ### GET /config Source: https://root-gg.github.io/plik/architecture/webapp.html Retrieves feature flags and other configuration settings from the server. This endpoint provides information on available features, limits, and authentication methods. ```APIDOC ## GET /config ### Description Retrieves feature flags and other configuration settings from the server. This endpoint provides information on available features, limits, and authentication methods. ### Method GET ### Endpoint `/config` ### Parameters None ### Request Example ``` GET /config ``` ### Response #### Success Response (200) - **feature_e2ee** (string) - "enabled" or "disabled" - Controls E2EE toggle. - **maxFileSize** (integer) - Max file size in bytes. - **maxUserSize** (integer) - Max total size per user in bytes. - **maxTTL** (integer) - Max TTL in seconds. - **googleAuthentication** (boolean) - True if Google OAuth is configured. - **githubAuthentication** (boolean) - True if GitHub OAuth is configured. - **ovhAuthentication** (boolean) - True if OVH OAuth is configured. - **feature_local_login** (string) - "enabled" or "disabled" - Controls local login form visibility. - **oidcAuthentication** (boolean) - True if OIDC is configured. - **oidcProviderName** (string) - Display name for OIDC button. - **downloadDomain** (string) - Alternate domain for download URLs. - **abuseContact** (string) - Abuse contact email. #### Response Example ```json { "feature_e2ee": "enabled", "maxFileSize": 5368709120, "maxUserSize": 107374182400, "maxTTL": 2592000, "googleAuthentication": true, "githubAuthentication": false, "ovhAuthentication": false, "feature_local_login": "enabled", "oidcAuthentication": false, "oidcProviderName": "OpenID", "downloadDomain": "downloads.example.com", "abuseContact": "abuse@example.com" } ``` ``` -------------------------------- ### Install Plik CLI to Local AppData Source: https://root-gg.github.io/plik/guide/windows-send-to.html Commands to create the Plik directory and move the executable into the user's local application data folder. ```cmd mkdir "%LOCALAPPDATA%\Plik" move plik.exe "%LOCALAPPDATA%\Plik\plik.exe" ``` ```powershell mkdir "$env:LOCALAPPDATA\Plik" -Force Move-Item .\plik.exe "$env:LOCALAPPDATA\Plik\plik.exe" ``` -------------------------------- ### Configure Theme Picker Options Source: https://root-gg.github.io/plik/features/web-ui.html Examples of how to define the 'themes' array in settings.json to control which themes are available to users in the UI picker. ```jsonc // All built-in themes available (default) "themes": ["*"] // No theme picker (dark only) "themes": [] // Only allow one specific theme (disables the picker) "themes": ["acme"] // Only allow specific themes "themes": ["auto", {"name": "acme-light", "label": "Acme Light"}, {"name": "acme-dark", "label": "Acme Dark"}] // All built-in themes + your custom ones ("*" expands to all built-ins) "themes": ["*", {"name": "custom-light", "label": "Custom Light"}, {"name": "custom-dark", "label": "Custom Dark"}] ``` -------------------------------- ### Running Per-Backend Storage-Level Tests Manually Source: https://root-gg.github.io/plik/architecture/testing.html Example command to manually run storage-level integration tests against a specific backend, such as MinIO S3. This requires setting the PLIKD_CONFIG environment variable to point to the backend's configuration file. ```bash PLIKD_CONFIG=$PWD/testing/minio/plikd.cfg go test ./server/data/s3/... -v -race ``` -------------------------------- ### Plik CLI End-to-End Encryption Examples Source: https://root-gg.github.io/plik/features/encryption.html Demonstrates various ways to use the Plik CLI for end-to-end encrypted uploads. Supports auto-generated or custom passphrases, encryption for GitHub/GitLab users' SSH keys, raw public keys, and server SSH host keys. ```bash plik --secure # Auto-generated passphrase (default) plik --secure -p "passphrase" # Custom passphrase plik --secure -r @camathieu # Encrypt for a GitHub user's SSH keys plik --secure -r https://gitlab.com/user.keys # SSH keys from any URL plik --secure -r "ssh-ed25519 AAAA..." # Raw SSH public key plik --secure -r ssh://myserver.example.com # Encrypt for a server's SSH host key plik --secure -r age1... # Native age X25519 recipient ``` -------------------------------- ### Documentation Build Pipeline Steps Source: https://root-gg.github.io/plik/architecture/system.html Illustrates the steps involved in the `make docs` build process, including version injection, copying architecture files, and running the VitePress build. ```bash # 1. inject_version.sh — replaces __VERSION__ placeholders # 2. copy_architecture.sh — copies ARCHITECTURE.md files into docs/architecture/ # 3. npm run build — runs the VitePress build ``` -------------------------------- ### Initialize Plik Client Source: https://root-gg.github.io/plik/architecture/library.html Demonstrates how to instantiate a new Plik client pointing to a specific server URL. ```go client := plik.NewClient("http://localhost:8080") ``` -------------------------------- ### Implementing MCP Server Tools Source: https://root-gg.github.io/plik/architecture/client.html Overview of the MCP server implementation using the Go MCP SDK to expose file upload capabilities to AI assistants. ```go import ( "github.com/modelcontextprotocol/go-sdk/mcp" ) // Example structure for MCP tool registration func registerUploadTools(server *mcp.Server) { server.AddTool("upload_file", "Upload a single file by path", func(args map[string]interface{}) (interface{}, error) { // Implementation using plik.UploadParams return "Upload successful", nil }) } ``` -------------------------------- ### GET /me Source: https://root-gg.github.io/plik/architecture/webapp.html Retrieves information about the currently authenticated user. ```APIDOC ## GET /me ### Description Returns the profile information for the currently authenticated user. If an admin is impersonating a user, this returns the impersonated user's data. ### Method GET ### Endpoint /me ### Response #### Success Response (200) - **login** (string) - User login - **email** (string) - User email - **admin** (boolean) - Admin status #### Response Example { "login": "jdoe", "email": "jdoe@example.com", "admin": false } ``` -------------------------------- ### Build Documentation with Make Source: https://root-gg.github.io/plik/architecture/system.html Command to build the human-readable documentation for the Plik project. This command orchestrates several scripts to generate the final documentation site. ```bash make docs ``` -------------------------------- ### GET /me/uploads Source: https://root-gg.github.io/plik/architecture/webapp.html Retrieves the list of uploads associated with the authenticated user. ```APIDOC ## GET /me/uploads ### Description Fetches a paginated list of file uploads created by the currently authenticated user. ### Method GET ### Endpoint /me/uploads ### Query Parameters - **page** (integer) - Optional - Page number for pagination - **token** (string) - Optional - Filter uploads by a specific token ### Response #### Success Response (200) - **uploads** (array) - List of upload objects containing files, date, and size metadata #### Response Example { "uploads": [ { "id": "abc-123", "date": "2023-10-27T10:00:00Z", "size": 1024, "files": [...] } ] } ``` -------------------------------- ### Create and Configure Uploads Source: https://root-gg.github.io/plik/architecture/library.html Shows how to create an upload instance, configure parameters like TTL and tokens, add files from a reader, and execute the upload process. ```go upload := client.NewUpload() upload.OneShot = true upload.TTL = 3600 upload.Token = "xxxx-xxxx-xxxx" file := upload.AddFileFromReader("myfile.txt", reader) err := upload.Upload() ``` -------------------------------- ### GET /users Source: https://root-gg.github.io/plik/architecture/webapp.html Retrieves a paginated list of all users. This endpoint is restricted to administrative users. ```APIDOC ## GET /users ### Description Returns a paginated list of all registered users. Requires administrative privileges. ### Method GET ### Endpoint /users ### Parameters #### Query Parameters - **page** (integer) - Optional - Page number for pagination - **limit** (integer) - Optional - Number of results per page ### Response #### Success Response (200) - **users** (array) - List of user objects containing login, provider, name, email, and quotas. #### Response Example { "users": [ { "id": "user_123", "login": "jdoe", "email": "jdoe@example.com", "admin": false } ] } ``` -------------------------------- ### Download and Execute Plik Bash Client Source: https://root-gg.github.io/plik/features/cli-client.html Provides instructions for downloading and setting up the lightweight bash client for Plik. It shows how to download `plik.sh` from a Plik server or GitHub releases using `curl` or `wget`, and then make it executable. ```bash # From a running Plik server curl -o plik.sh https://your-plik-server/clients/bash/plik.sh chmod +x plik.sh # Or from GitHub releases wget https://github.com/root-gg/plik/releases/download/1.4.1/plik-1.4.1.sh ``` -------------------------------- ### Easy Uploads with Plik Go Client Source: https://root-gg.github.io/plik/reference/go-library.html Demonstrates quick one-liner methods for uploading files using the Plik Go client. It shows how to upload a file directly from a local path or from an io.Reader. ```go client := plik.NewClient("https://plik.server.url") // Upload a file from path upload, file, err := client.UploadFile("/home/file1") // Upload from an io.Reader upload, file, err := client.UploadReader("filename", ioReader) ``` -------------------------------- ### GET /users Source: https://root-gg.github.io/plik/reference/api.html Retrieve a list of users with optional filtering capabilities. ```APIDOC ## GET /users ### Description Retrieves a list of users registered in the system with optional filters. ### Method GET ### Endpoint /users ### Parameters #### Query Parameters - **provider** (string) - Optional - Filter by auth provider (e.g., 'google', 'ovh', 'oidc', 'local') - **admin** (bool) - Optional - Filter by admin status ### Response #### Success Response (200) - **users** (array) - List of user objects ``` -------------------------------- ### Configure Plik via Environment Variables Source: https://root-gg.github.io/plik/architecture/system.html Demonstrates how to override Plik server configuration parameters using environment variables with the PLIKD_ prefix. This approach allows for dynamic configuration without modifying the primary TOML file. ```bash PLIKD_DEBUG_REQUESTS=true ./plikd PLIKD_DATA_BACKEND_CONFIG='{"Directory":"/var/files"}' ./plikd ``` -------------------------------- ### GET /me/uploads Source: https://root-gg.github.io/plik/architecture/system.html Retrieves a paginated list of uploads associated with the authenticated user, supporting sorting and filtering. ```APIDOC ## GET /me/uploads ### Description Lists all uploads for the current user. Supports sorting by date/size and filtering by various upload properties. ### Method GET ### Endpoint /me/uploads ### Parameters #### Query Parameters - **sort** (string) - Optional - Sort by 'date' or 'size'. - **order** (string) - Optional - Sort order 'asc' or 'desc'. - **token** (string) - Optional - Filter by specific upload token. ### Response #### Success Response (200) - **uploads** (array) - List of upload objects. #### Response Example [ { "id": "abc123", "createdAt": "2023-10-27T10:00:00Z", "size": 1024 } ] ``` -------------------------------- ### GET /me/uploads, /uploads Source: https://root-gg.github.io/plik/reference/api.html Retrieve a list of uploads with optional filtering and sorting parameters. ```APIDOC ## GET /me/uploads, /uploads ### Description Retrieves a list of uploads. Supports sorting and various filters to narrow down results. ### Method GET ### Endpoint /me/uploads or /uploads ### Parameters #### Query Parameters - **sort** (string) - Optional - Sort by 'size' (default: 'createdAt') - **user** (string) - Optional - Filter by user ID (admin only) - **token** (string) - Optional - Filter by upload token (admin only) - **oneShot** (bool) - Optional - Filter one-shot uploads - **removable** (bool) - Optional - Filter removable uploads - **stream** (bool) - Optional - Filter stream uploads - **extendTTL** (bool) - Optional - Filter extend-TTL uploads - **password** (bool) - Optional - Filter password-protected uploads - **e2ee** (bool) - Optional - Filter end-to-end encrypted uploads ### Response #### Success Response (200) - **uploads** (array) - List of upload objects ``` -------------------------------- ### Docker Compose Up Command Source: https://root-gg.github.io/plik/guide/docker.html This command starts the services defined in the `docker-compose.yml` file in detached mode. ```bash docker compose up -d ``` -------------------------------- ### Full Mode Uploads with Plik Go Client Source: https://root-gg.github.io/plik/reference/go-library.html Illustrates the complete workflow for uploading files with the Plik Go client, allowing for detailed configuration. This includes adding files from paths or readers, creating the upload server-side, uploading files, and retrieving URLs. ```go client := plik.NewClient("https://plik.server.url") // Optional client configuration client.OneShot = true client.Token = "xxxx-xxxx-xxxx-xxxx" upload := client.NewUpload() // Optional upload configuration upload.OneShot = false // Create file from path file1, err := upload.AddFileFromPath(path) // Create file from reader file2, err := upload.AddFileFromReader("filename", ioReader) // Create upload server side (optional step that is called by upload.Upload() / file.Upload() if omitted) err = upload.Create() // Upload all added files in parallel err = upload.Upload() // Upload a single file err = file.Upload() // Get upload URL uploadURL, err := upload.GetURL() // Get file URLs for _, file := range upload.Files() { fileURL, err := file.GetURL() } ``` -------------------------------- ### Plik Health Check Source: https://root-gg.github.io/plik/guide/docker.html This command sends a GET request to the `/health` endpoint of the running Plik service to check its status. ```bash curl http://localhost:8080/health ``` -------------------------------- ### Reverse Proxy Server Configurations Source: https://root-gg.github.io/plik/operations/reverse-proxy.html Configuration examples for Nginx, Apache, Caddy, and Traefik to route traffic to a Plik instance. ```nginx server { listen 443 ssl; server_name plik.example.com; client_max_body_size 10G; location / { proxy_pass http://127.0.0.1:8080; proxy_set_header Host $http_host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; proxy_request_buffering off; proxy_buffering off; proxy_read_timeout 86400s; } } ``` ```apache ServerName plik.example.com ProxyPreserveHost On ProxyPass / http://127.0.0.1:8080/ ProxyPassReverse / http://127.0.0.1:8080/ RequestHeader set X-Forwarded-For %{REMOTE_ADDR}s RequestHeader set X-Forwarded-Proto https ``` ```caddyfile plik.example.com { reverse_proxy 127.0.0.1:8080 request_body { max_size 10G } } ``` ```yaml services: plik: image: rootgg/plik:latest labels: - "traefik.enable=true" - "traefik.http.routers.plik.rule=Host(`plik.example.com`)" - "traefik.http.routers.plik.entrypoints=websecure" - "traefik.http.routers.plik.tls.certresolver=le" - "traefik.http.services.plik.loadbalancer.server.port=8080" networks: - traefik_network ``` -------------------------------- ### Run Plik End-to-End Tests with Go Source: https://root-gg.github.io/plik/architecture/library.html Instructions for running the Plik end-to-end tests using the Go testing framework. This includes running with default in-memory backends, specifying a data backend, and using a full backend configuration file. ```bash # Default (in-memory backends, fast) cd plik && go test ./... # With a specific data backend data_backend=file go test ./... # With full backend config (used by testing/ Docker scripts) PLIKD_CONFIG=/path/to/test.cfg go test ./... ``` -------------------------------- ### Build and Test (Bash) Source: https://root-gg.github.io/plik/features/internationalization.html Commands to run tests and build the production version of the web application after adding a new language. Navigate to the 'webapp' directory before running. ```bash cd webapp npm test # Run unit tests npm run build # Verify production build ``` -------------------------------- ### Automated Documentation Deployment Workflow Source: https://root-gg.github.io/plik/architecture/system.html Configuration snippet for a GitHub Actions workflow that automates the deployment of the VitePress documentation site to GitHub Pages. This workflow is triggered on pushes to the 'master' branch when documentation files or ARCHITECTURE.md files change. ```yaml # .github/workflows/pages.yml # (Snippet illustrating the trigger and relevant steps) ... ```