du-cki / comet

A blazingly fast CDN node written in rust.
MIT License
4 stars 1 forks source link
cdn rust sql

Comet

Comet is a blazingly fast Content Delivery Network (CDN) node written in Rust.

Installation

Before you start, make sure you have Rust installed on your system. If you don't have it installed, you can download it from the official website: https://www.rust-lang.org/tools/install

  1. Clone the repository & Navigate to it:

    git clone https://github.com/du-cki/comet.git
    cd comet
  2. Build the project:

    SQLX_OFFLINE=true cargo build --release
  3. Edit the comet-config.toml file and apply the necessary configurations.

  4. Run the project:

    cargo run --release

    Please refer to the wiki for other ways to running & exposing this project.

Usage

Once you've installed comet, you can start using it as a CDN node. Here's a basic guide on how to use it:

Uploading a File

To upload a file, you need to make a POST request to the /upload endpoint with the file (as FormData) and the password (set in the comet-config.toml file) in the Authorisation header.

Retrieving a File

To retrieve a file, make a GET request to the /media/:media_id endpoint, replacing :media_id with the name of the file you want to retrieve.

Deleting a File

To delete a file, make a DELETE request to the /delete/:media_id endpoint, replacing :media_id with the relevant file name and along with the password set in the Authorisation header.

Configuration

You can configure Comet by modifying the comet-config.example.toml file. Here are the available settings (don't forget to rename the file into comet-config.toml):

bind_addr: The IP address to bind the server to.
bind_port: The port to bind the server to.
password: The password required to access authenticated routes (i.e. upload route).
file_name_length: The length of the randomly generated file names.
file_save_path: The path on disk where uploaded files will be saved onto.
file_size_limit: The file upload limit, if you pass in 0, this will be disabled.
enforce_file_extensions: Whether to enforce file extensions when requesting for the file.
fallback_content_type: The content type to use when the uploaded file's content type cannot be determined.
endpoints.get_file: The endpoint for retrieving files.
endpoints.upload_file: The endpoint for uploading files.
endpoints.delete_file: The endpoint for deleting files.

Please note that you should restart the server for the changes to take effect.

Contributing

If you are interested in contributing to the development of Comet, here's how to setup an development enviroment:

Dev Environment Setup

Make sure you have Rust installed on your system. If not, you can download it from the official website: https://www.rust-lang.org/tools/install

  1. Clone the Repository & Navigate to the project

    Clone the repository to your local machine:

    git clone https://github.com/du-cki/comet.git
    cd comet
  2. Build the Project

    As comet uses SQLite as its database as choice, you'll need to set up the database. To do so, you will need to perform an offline compilation. Build the project with the env variable SQLX_OFFLINE as true:

    SQLX_OFFLINE=true cargo build
  3. Environment Variables

    After building the project initially, you can create an .env file in the root of the project and set DATABASE_URL as sqlite://data.db for compile-time checks.

If you make changes to any SQL queries, you'll need to regenerate the sqlx-data.json file for a successful offline compilation. You can regenerate it with the SQLx CLI through cargo sqlx prepare.

Once you've made your changes, please provide a clear and detailed explanation of your changes and open a pull request.

License

comet is licensed under the MIT license.