My attempt to make a tiny photos storage with duplicates finder. https://photos.end-play.xyz/docs
Go to file
Profitroll b2146b965a Fixed license link
Signed-off-by: Profitroll <profitroll@noreply.localhost>
2023-11-24 12:19:32 +02:00
classes Added random photo/video request 2023-06-27 13:51:18 +02:00
extensions Fixed direction errors 2023-08-14 13:55:49 +02:00
modules Added db_client_sync 2023-08-14 13:51:18 +02:00
pages Working on pages 2023-01-12 16:21:33 +01:00
.gitignore Added some pages 2022-12-20 15:34:47 +01:00
.renovaterc Update '.renovaterc' 2023-04-21 10:02:18 +03:00
config_example.json Confirmation is disabled by default now 2023-03-13 13:00:42 +01:00
dependencies.md Improved compression 2022-12-20 22:52:05 +01:00
favicon.ico Migrated from main API 2022-12-20 01:22:32 +01:00
LICENSE Updated license 2022-12-20 00:28:05 +01:00
photos_api.py logWrite replaced with logging module 2023-06-23 11:25:27 +02:00
README.md Fixed license link 2023-11-24 12:19:32 +02:00
requirements.txt Update dependency fastapi to v0.104.1 2023-10-30 12:18:40 +02:00

Photos API

License: GPL Code style: black

Small and simple API server for saving photos and videos.

Dependencies

Installation

First you need to have a Python interpreter, MongoDB and optionally git. You can also ignore git and simply download source code, should also work fine. After that you're ready to go.

In this README I assume that you're using default python in your system and your system's PATH contains it. If your default python is python3 or for example /home/user/.local/bin/python3.9 - use it instead.

  1. Install Mongo:

    Please follow official installation manual for that.

  2. Download Photos API:

    1. git clone https://git.end-play.xyz/profitroll/PhotosAPI.git (if you're using git)
    2. cd PhotosAPI
  3. Create virtual environment [Optional yet recommended]:

    1. Install virtualenv module: pip install virtualenv
    2. Create venv: python -m venv env
    3. Activate it using source venv/bin/activate on Linux, venv\Scripts\activate.bat in CMD or venv\Scripts\Activate.ps1 in PowerShell.
  4. Install project's dependencies:

    python -m pip install -r requirements.txt

  5. Configure your API:

    1. Copy file config_example.json to config.json
    2. Open config.json using your favorite text editor. For example nano config.json
    3. Change "database" keys to match your MongoDB setup
    4. Change "external_address" to the ip/http address you may get in responses. By default it's "localhost". This is extremely useful when running behind reverse-proxy.

    After configuring everything listed above your API will be able to boot, however further configuration can be done. You can read about it in repository's wiki. There's no need to focus on that now, it makes more sense to configure it afterwards.

  6. Start your API:

    You can run your API by the following command:
    uvicorn photos_api:app --host 127.0.0.1 --port 8054

    Learn more about available uvicorn arguments using uvicorn --help

Using as a service

It's a good practice to use your API as a systemd service on Linux. Here's a quick overview how that can be done.

  1. Create user and move your API

    You don't always need to do so, but that's a cleaner way to deploy a service.

    1. Create service user photosapi using sudo useradd -r -U photosapi
    2. Assuming you are still in directory PhotosAPI, use cd .. to go up a level and then move your API to the distinguished folder. For example, /opt/: sudo mv ./PhotosAPI /opt/
    3. Make your user and its group own their directory using sudo chown -R photosapi:photosapi /opt/PhotosAPI
  2. Configure service

    Here's an example service file for PhotosAPI that is using virtual environment:

    [Unit]
    Description=Photos API
    After=network.target mongod.service
    Wants=network-online.target mongod.service
    
    [Service]
    Restart=always
    Type=simple
    ExecStart=/bin/bash -c 'source venv/bin/activate && venv/bin/uvicorn photos_api:app --port 8054'
    WorkingDirectory=/opt/PhotosAPI
    User=photosapi
    Group=photosapi
    
    [Install]
    WantedBy=multi-user.target
    
    1. Create a service by pasting code above into /etc/systemd/system/photos-api.service
    2. Enable your service to start on system boot using sudo systemctl enable photos-api.service
    3. Start your service now using sudo systemctl start photos-api.service
    4. Check if it's running using sudo systemctl status photos-api.service
    5. If something goes wrong - check API's logs using sudo journalctl -u photos-api.service