CDN Docs

Документація CDN-сервера

CDN Server Documentation

Оновлена документація для локального CDN-сервісу. Нижче наведені інструкції налаштування, API та приклади використання.

Updated documentation for the local CDN service. Below you will find setup instructions, API reference and usage examples.

Швидкий старт

Quick start

composer install
# налаштуйте includes/config.php
https://cdn.konex.com.ua/file/?url=path/to/file

API

API

Ендпоінти

Endpoints

GET /file/

  • url (string, required) — шлях до файлу відносно cdn_dir
  • url (string, required) — path to file relative to cdn_dir
  • token (string, optional) — JWT (альтернатива заголовку Authorization)
  • token (string, optional) — JWT (alternative to Authorization header)
Відповіді: 200 — файл, 404 — не знайдено, 401 — помилка токена
Responses: 200 — file, 404 — not found, 401 — token error
{
                "status": "ok",
                "filename": "report.pdf",
                "size": 12345,
                "mime": "application/pdf"
                // ...або файл напряму (200), або {"error": "not found"} (404)
            }
{
                "status": "ok",
                "filename": "report.pdf",
                "size": 12345,
                "mime": "application/pdf"
                // ...or file stream (200), or {"error": "not found"} (404)
            }

GET /list/

  • path (string, optional) — піддиректорія CDN
  • path (string, optional) — CDN subdirectory
  • token (string, required) — JWT
  • token (string, required) — JWT
Відповідь: JSON зі списком файлів/папок
Response: JSON with file/folder list
{
                "files": [
                    {"name": "file1.pdf", "size": 12345, "type": "file"},
                    {"name": "folder1", "type": "dir"}
                ]
            }
{
                "files": [
                    {"name": "file1.pdf", "size": 12345, "type": "file"},
                    {"name": "folder1", "type": "dir"}
                ]
            }

GET /search/

  • search (string, required) — пошуковий рядок
  • search (string, required) — search query
  • path (string, optional) — піддиректорія
  • path (string, optional) — subdirectory
  • token (string, required) — JWT
  • token (string, required) — JWT
Відповідь: JSON з результатами пошуку
Response: JSON with search results
{
                "results": [
                    {"name": "file1.pdf", "path": "docs/", "type": "file"},
                    {"name": "folder1", "path": "docs/", "type": "dir"}
                ]
            }
{
                "results": [
                    {"name": "file1.pdf", "path": "docs/", "type": "file"},
                    {"name": "folder1", "path": "docs/", "type": "dir"}
                ]
            }

POST /upload/

  • file (file, required) — файл для завантаження
  • file (file, required) — file to upload
  • path (string, optional) — піддиректорія
  • path (string, optional) — subdirectory
  • token (string, required) — JWT
  • token (string, required) — JWT
Відповідь: JSON з інформацією про завантаження
Response: JSON with upload info
{
                "status": "ok",
                "filename": "example.pdf",
                "size": 12345,
                "message": "Файл завантажено"
            }
{
                "status": "ok",
                "filename": "example.pdf",
                "size": 12345,
                "message": "File uploaded"
            }

POST /delete/

  • filename (string, optional) — ім'я файлу для видалення
  • filename (string, optional) — file name to delete
  • folder (string, optional) — ім'я папки для рекурсивного видалення
  • folder (string, optional) — folder name to delete recursively
  • path (string, optional) — піддиректорія
  • path (string, optional) — subdirectory
  • token (string, required) — JWT
  • token (string, required) — JWT
Відповідь: JSON зі статусом видалення
Response: JSON with delete status
{
                "status": "ok",
                "deleted": "example.pdf"
                // або {"status": "error", "error": "not found"}
            }
{
                "status": "ok",
                "deleted": "example.pdf"
                // or {"status": "error", "error": "not found"}
            }

GET /list/

Повертає список файлів і папок (JSON). Потрібна авторизація.

Returns folder listing (JSON). $config['public_keys']

If token contains cdnDir claim, access is restricted to that directory.

Налаштування (includes/config.php)

Configuration

Приклади

Examples

GET /file/

curl -v \
      -H "Authorization: Bearer <JWT>" \
      "https://cdn.konex.com.ua/file/?url=private/report.pdf"

GET /list/

curl -v \
      -H "Authorization: Bearer <JWT>" \
      "https://cdn.konex.com.ua/list/?path=reports"

GET /search/

curl -v \
      -H "Authorization: Bearer <JWT>" \
      "https://cdn.konex.com.ua/search/?search=pdf&path=reports"

POST /upload/

curl -X POST \
      -H "Authorization: Bearer <JWT>" \
      -F "file=@example.pdf" \
      -F "path=reports" \
      "https://cdn.konex.com.ua/upload/"

POST /delete/ (файл)

POST /delete/ (file)

curl -X POST \
      -H "Authorization: Bearer <JWT>" \
      -F "filename=example.pdf" \
      -F "path=reports" \
      "https://cdn.konex.com.ua/delete/"

POST /delete/ (папка)

POST /delete/ (folder)

curl -X POST \
      -H "Authorization: Bearer <JWT>" \
      -F "folder=reports" \
      -F "path=2024" \
      "https://cdn.konex.com.ua/delete/"