tgNetDisc

repository·master·Indexed 42 days ago

https://github.com/yohann0617/tgnetdisc

A lightweight file hosting and cloud disk service that leverages the Telegram API for unlimited storage. It allows users to upload files to Telegram channels and access them via a web interface or generated HTML, Markdown, and BBCode links. Supports deployment via Docker or binary executable with configurable modes, password protection, and API endpoints for file uploads.

Tokens
1.5K
Snippets
6
Records
7
Agent score
45%

What's inside tgNetDisc

  1. Run tgNetDisc as a binary executable

    master

    You can run the compiled binary (named tgstate in the documentation) directly. Use the following flags to configure the service:

    • -token <token>: The Telegram Bot token.
    • -channel <channel>: The channel address (e.g., @xxxx) or a numeric personal ID.
    • -port <port>: Customizes the listening port (e.g., -port 8888).
    • -index: If provided, the homepage is disabled, leaving only the API and image display pages.
    • -pass <password>: Enables password-protected access (e.g., -pass csznet).
    • -mode pan: Enables 'Cloud Disk' (网盘) mode.
    # Basic startup
    ./tgstate -token xxxx -channel @xxxx
    
    # Advanced startup with custom port, password, and pan mode
    ./tgstate -token xxxx -channel @xxxx -port 8888 -pass csznet -mode pan
    
    # API/Image only mode (no homepage)
    ./tgstate -token xxxx -channel @xxxx -port 8888 -index
  2. Deploy tgNetDisc using Docker

    master

    The recommended way to deploy tgNetDisc is via Docker. You can pull the image yohannfan/yohann-netdisc:latest and run it with the following environment variables:

    • TOKEN: Your Telegram Bot token.
    • CHANNEL: The Telegram channel address (e.g., @yohannChannl) or a numeric Chat ID. The bot must be an administrator in the channel/chat. If using a channel, it must be public.
    • MODE: Set to pan to enable 'Cloud Disk' (网盘) mode.
    • PASS: (Optional) Sets a password for access control.
    • DOMAIN: (Optional) The domain name used to generate full URLs for files. If not configured, the system returns base64 encoded file IDs.

    Supported architectures include linux/amd64, linux/arm64, linux/arm/v6, linux/arm/v7, linux/386, linux/ppc64le, linux/s390x, and linux/riscv64.

    docker run -d --restart=always \
    --name netdisc \
    -p 8088:8088 \
    -e TOKEN=xxx \
    -e CHANNEL=xxx \
    -e MODE=pan \
    -e PASS=yohann \
    -e DOMAIN=https://hh.abc.com \
    yohannfan/yohann-netdisc:latest
  3. Configure Nginx reverse proxy for tgNetDisc

    master

    If you are running tgNetDisc behind Nginx, use the following configurations.

    General reverse proxy (root path):

    location / {
        proxy_pass http://localhost:8088;
        proxy_method $request_method;
        proxy_set_header Host $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;
    }

    Custom URL reverse proxy (using /tgState prefix): This configuration handles the Netdisk mode and applies rate limiting to specific paths.

    # Netdisk
    location /tgState {
        proxy_pass http://localhost:8088;
    }
    location ~ ^/tgState/(d|pwd|api)(.*)$ {
        limit_req zone=mylimit burst=20; 
        proxy_pass http://localhost:8088/$1$2; 
    }
    location /pwd {
        proxy_pass http://localhost:8088;
    }
  4. Understand tgNetDisc execution modes

    master

    The -mode flag determines the operational behavior of the application. The application supports two primary modes:

    1. pan (Default): The standard mode (likely for 'pan' or disk/storage functionality). If an invalid mode is provided, it defaults to pan.
    2. m: A restricted mode where API endpoints are disabled (OptApi = false).
  5. Upload files via the API

    master

    Use a POST request to upload files (such as images) to the tgNetDisc API.

    Endpoint: https://<YOUR_DOMAIN>/api

    If you have configured a password using the -pass flag or PASS environment variable, you must include the password in the request using the cookie parameter p.

    # Without password
    curl -X POST -F "image=@/root/test/tgNetDisc;type=application/octet-stream" https://hh.abc.com/api
    
    # With password
    curl -X POST -F "image=@/root/test/tgNetDisc;type=application/octet-stream" -b "p=YOURPASSWORD" https://hh.abc.com/api
  6. Reference: tgNetDisc CLI flags

    master

    The following flags are available for configuring the application:

    -port string (default "8088") : Web Port
    -token string (default from $TOKEN) : Bot Token
    -channel string (default from $CHANNEL) : Channel Name
    -pass string (default from $PASS) : Visit Password
    -mode string (default from $MODE) : Run mode
    -domain string (default from $DOMAIN) : domain name
  7. Configure tgNetDisc via CLI flags

    master

    tgNetDisc can be configured using command-line flags. These flags allow you to set the web server port, Telegram Bot Token, target channel name, access password, execution mode, and domain name. If an environment variable is set, the corresponding flag will use that value as a default.

    # Example usage with flags
    ./tgnetdisc -token "YOUR_BOT_TOKEN" -channel "YOUR_CHANNEL" -port "8080" -pass "secret123" -mode "pan"