Skip to content

xz-dev/website4share

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Website4Share

Website4Share is a Rust-based web application for sharing files and pasteboard content.

Prerequisites

  • Rust and Cargo installed
  • Docker installed (for containerization)

Running the Application with Cargo

To run the application using Cargo, follow these steps:

  1. Clone the repository:

    git clone https://github.com/xz-dev/website4share.git
    cd website4share
  2. Set the required environment variables:

    • LISTEN_ADDR: The address and port the application will listen on (default: 0.0.0.0:8080).
    • TMPDIR: The directory for temporary files (default: system temporary directory).

    Example:

    export LISTEN_ADDR=0.0.0.0:8080
    export TMPDIR=/path/to/tempdir
  3. Run the application:

    cargo run

Building and Running with Docker

To build and run the application using Docker, follow these steps:

  1. Build the Docker image:

    docker build -t website4share -f Containerfile .
  2. Run the Docker container:

    docker run -d \
      -p 8080:8080 \
      -v /path/to/local/cache:/tmp/website4share \
      -e LISTEN_ADDR=0.0.0.0:8080 \
      --name website4share_container \
      website4share

Explanation of Docker Run Command

  • -d: Run the container in detached mode.
  • -p 8080:8080: Map port 8080 on the host to port 8080 in the container.
  • -v /path/to/local/cache:/tmp/website4share: Mount the local directory /path/to/local/cache to /tmp/website4share in the container. This ensures that the cache directory is persisted and not lost when the container is stopped or removed.
  • -e LISTEN_ADDR=0.0.0.0:8080: Set the LISTEN_ADDR environment variable to 0.0.0.0:8080 to ensure the application listens on all network interfaces.
  • --name website4share_container: Assign a name to the container for easier management.
  • website4share: The name of the Docker image to run.

Environment Variables

  • LISTEN_ADDR: The address and port the application will listen on. Default is 0.0.0.0:8080.
  • TMPDIR: The directory for temporary files. Default is the system temporary directory + website4share.

Project Structure

  • src/: Source code of the application.
  • Cargo.toml: Cargo configuration file.
  • Containerfile: Dockerfile for building the Docker image.
  • static/: Static files served by the application.

Feature

  1. Just a website
  2. Multi share thread
  3. Upload resume
  4. Terminal API (curl friendly)

Terminal API

All upload endpoints return plain text URLs by default. Add Accept: application/json header for JSON response.

Create a space

curl -s -X POST http://localhost:8080/api/v1/new/myspace

Upload text (pasteboard)

# Pipe stdin
echo "hello world" | curl -s -X POST --data-binary @- http://localhost:8080/api/v1/paste/myspace
# From wl-clipboard
wl-paste | curl -s -X POST --data-binary @- http://localhost:8080/api/v1/paste/myspace
# From X11 clipboard
xclip -selection clipboard -o | curl -s -X POST --data-binary @- http://localhost:8080/api/v1/paste/myspace
# Returns: /api/v1/paste/myspace/<id>

Download text

curl http://localhost:8080/api/v1/paste/myspace/<id>
# Copy to clipboard
curl http://localhost:8080/api/v1/paste/myspace/<id> | wl-copy

Upload file (PUT)

curl --upload-file photo.jpg http://localhost:8080/api/v1/file/myspace/photo.jpg
# Returns: /files/myspace/files/photo.jpg

Download file

curl -O http://localhost:8080/files/myspace/files/photo.jpg

List

# List all spaces
curl http://localhost:8080/api/v1/list
# ["myspace", "other"]

# List pasteboard & files in a space (JSON, with download URLs)
curl http://localhost:8080/api/v1/list/myspace
# {
#   "pasteboard": [{"id":"..", "url":"/api/v1/paste/myspace/..", "timestamp":.., "size":..}],
#   "files": [{"name":"..", "url":"/files/myspace/files/..", "timestamp":.., "size":..}]
# }

JSON output

echo "hello" | curl -s -X POST -H "Accept: application/json" --data-binary @- http://localhost:8080/api/v1/paste/myspace
# {"url":"/api/v1/paste/myspace/...","id":"..."}

Quick aliases

Add to your .bashrc / .zshrc:

export W4S_HOST="http://localhost:8080"

w4s-new()   { curl -s -o /dev/null -w "%{http_code}" -X POST "$W4S_HOST/api/v1/new/$1"; }
w4s-paste() { curl -s -X POST --data-binary @- "$W4S_HOST/api/v1/paste/$1"; }
w4s-get()   { curl -s "$W4S_HOST$1"; }
w4s-up()    { curl --upload-file "$2" "$W4S_HOST/api/v1/file/$1/$(basename $2)"; }
w4s-ls()    { curl -s "$W4S_HOST/api/v1/list${1:+/$1}"; }

# Usage:
w4s-new myspace                        # create space
echo "hello" | w4s-paste myspace       # paste text
w4s-get /api/v1/paste/myspace/<id>    # get text
w4s-up myspace photo.jpg               # upload file
w4s-ls                                # list all spaces
w4s-ls myspace                        # list space contents

API Reference

Method Endpoint Description
POST /api/v1/new/{pname} Create a space
POST /api/v1/paste/{pname} Upload text (raw body), returns URL
GET /api/v1/paste/{pname}/{id} Download text
PUT /api/v1/file/{pname}/{name} Upload file (raw body), returns URL
GET /api/v1/list List all spaces (JSON array)
GET /api/v1/list/{pname} List space contents (JSON with URLs)

All Terminal API endpoints return 400 with invalid pname or invalid path if the path segment contains .., /, or \.

ScreenShot

  • Home page: 图片
  • Sub-page: 图片 图片

About

Share in LAN/No over-optimization/Focus on use

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors