Skip to content

Commit

Permalink
Merge pull request #32 from vgarcia007/fileops
Browse files Browse the repository at this point in the history
refactor frontend with routing because we need more api routes f…
  • Loading branch information
PhilippMundhenk authored Nov 9, 2024
2 parents 93e6f9c + fdf7a2e commit 3d2b7c7
Show file tree
Hide file tree
Showing 51 changed files with 1,713 additions and 382 deletions.
19 changes: 10 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM python:slim-bullseye
FROM python:slim-bookworm

RUN <<EOF
apt-get update && \
Expand Down Expand Up @@ -43,9 +43,11 @@ cp /etc/lighttpd/conf-available/15-fastcgi-php.conf /etc/lighttpd/conf-enabled/
cp /etc/lighttpd/conf-available/10-fastcgi.conf /etc/lighttpd/conf-enabled/ && \
mkdir -p /var/run/lighttpd && \
touch /var/run/lighttpd/php-fastcgi.socket && \
chown -R www-data /var/run/lighttpd
chown -R www-data /var/run/lighttpd && \
echo 'www-data ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers
EOF


ENV NAME="Scanner"
ENV MODEL="MFC-L2700DW"
ENV IPADDRESS="192.168.1.123"
Expand All @@ -69,13 +71,12 @@ ENV TELEGRAM_CHATID=""
# Make sure this ends in a slash.
ENV FTP_PATH="/scans/"

#ADD files/gui/index.php /var/www/html
#ADD files/gui/main.css /var/www/html
#ADD files/api/scan.php /var/www/html
#ADD files/api/active.php /var/www/html
#ADD files/api/list.php /var/www/html
#ADD files/api/download.php /var/www/html
COPY html /var/www/html
EXPOSE 54925
EXPOSE 54921
EXPOSE 80

# Copy the web files to the web directory
COPY www /var/www
RUN chown -R www-data /var/www/

#directory for scans:
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ You can configure the tool via environment variables:
| USE_JPEG_COMPRESSION | optional | use JPEG compression when creating PDFs |
| TELEGRAM_TOKEN | optional | If TELEGRAM_TOKEN and TELEGRAM_CHATID are set, then this sends notification |
| TELEGRAM_CHATID | optional | If TELEGRAM_TOKEN and TELEGRAM_CHATID are set, then this sends notification |
| ALLOW_GUI_FILEOPERATIONS | optional | true/false. Let you delete and rename files in files list |
### FTPS upload
Expand Down Expand Up @@ -203,9 +204,8 @@ Thus, make sure to wait for your scan to complete, before pressing another butto
#### API
The GUI uses a minimal "API" at the backend, which you can also use from other tooling (e.g., Home Assistant or a control panel near your printer).
To scan, simply call `http://<ContainerIP>:<Port>/scan.php?target=<file|email|image|OCR>`
Also check out the endpoints `list.php`, `download.php`, `active.php`.
Maybe one day an OpenAPI Spec will be included.
To scan, simply call `http://<ContainerIP>:<Port>/api/scanner/scanto/<file|email|image|OCR>`
Also check out the swagger file in the doc directory to see all available endpoints.

## Full Docker Compose Example

Expand Down
284 changes: 284 additions & 0 deletions doc/swagger.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,284 @@
openapi: 3.0.0
info:
title: BrotherScannerDocker API
description: API for managing and accessing scans and files.
version: 1.0.0
servers:
- url: http://localhost:8080/api
description: Local development server
paths:
/scanner/status:
get:
summary: Returns the current status of the scanner
responses:
'200':
description: Scanner status
content:
application/json:
schema:
type: object
properties:
scan:
type: boolean
description: Indicates if a scan is in progress
waiting:
type: boolean
description: Indicates if the scanner is waiting
ocr:
type: boolean
description: Indicates if an OCR process is running
/scanner/scanto:
post:
summary: Initiates a scan operation
requestBody:
required: true
content:
application/x-www-form-urlencoded:
schema:
type: object
properties:
target:
type: string
description: Target for the scan operation
enum:
- file
- email
- image
- ocr
responses:
'200':
description: Scan operation successfully initiate
/scanner/scanto/{parameter}:
get:
summary: Initiates a scan operation with a specified parameter
parameters:
- name: parameter
in: path
required: true
schema:
type: string
enum:
- file
- email
- image
- ocr
responses:
'200':
description: Scan operation successfully initiated, waiting for backend response
/file-list:
get:
summary: List Scanned Files
responses:
'200':
description: Returns a list of scanned files.
content:
application/json:
schema:
type: array
items:
type: object
properties:
full_path:
type: string
file:
type: string
name:
type: string
name_clean:
type: string
dir:
type: string
date_from_name:
type: string
time_from_name:
type: string
fileCreationTime:
type: integer
fileModificationTime:
type: integer
date_from_file:
type: string
time_from_file:
type: string
extension:
type: string
mimetype:
type: string
size:
type: integer
example:
- full_path: "/scans/2024-09-21 Invoice Company A.pdf"
file: "Invoice Company A.pdf"
name: "Invoice Company A"
name_clean: "Company A Invoice"
dir: "/scans"
date_from_name: "2024-09-21"
time_from_name: ""
fileCreationTime: 1726902248
fileModificationTime: 1726902199
date_from_file: "2024-09-21"
time_from_file: "09-03-19"
extension: "pdf"
mimetype: "application/pdf"
size: 2970761
- full_path: "/scans/2024-09-22 Insurance Policy Document.pdf"
file: "Insurance Policy Document.pdf"
name: "Insurance Policy Document"
name_clean: "Insurance Policy"
dir: "/scans"
date_from_name: "2024-09-22"
time_from_name: ""
fileCreationTime: 1727016766
fileModificationTime: 1726582762
date_from_file: "2024-09-17"
time_from_file: "16-19-22"
extension: "pdf"
mimetype: "application/pdf"
size: 2947326
/file/{file}/info:
get:
summary: Provides extended information about a file
parameters:
- name: file
in: path
required: true
schema:
type: string
responses:
'200':
description: Extended file information
content:
application/json:
schema:
type: object
properties:
full_path:
type: string
description: The full path to the file
file:
type: string
description: The file name
name:
type: string
description: The file name without extension
name_clean:
type: string
description: Cleaned version of the file name
dir:
type: string
description: Directory where the file is located
date_from_name:
type: string
format: date
description: Date extracted from the file name
time_from_name:
type: string
format: time
description: Time extracted from the file name
fileCreationTime:
type: integer
description: File creation time as a Unix timestamp
fileModificationTime:
type: integer
description: File modification time as a Unix timestamp
date_from_file:
type: string
format: date
description: Date extracted from the file metadata
time_from_file:
type: string
description: Time extracted from the file metadata
extension:
type: string
description: File extension
mimetype:
type: string
description: MIME type of the file
size:
type: integer
description: Size of the file in bytes
example:
full_path: "/scans/2024-09-13-13-08-46 ganz anderes.pdf"
file: "2024-09-13-13-08-46 ganz anderes.pdf"
name: "2024-09-13-13-08-46 ganz anderes"
name_clean: "ganz anderes"
dir: "/scans"
date_from_name: "2024-09-13"
time_from_name: "13:08:46"
fileCreationTime: 1727176003
fileModificationTime: 1726225726
date_from_file: "2024-09-13"
time_from_file: "13-08-46"
extension: "pdf"
mimetype: "application/pdf"
size: 1161527
/file/{file}/download:
get:
summary: Download a File
parameters:
- name: file
in: path
required: true
description: The name of the file to download.
schema:
type: string
responses:
'200':
description: The file is downloaded.
content:
application/pdf:
schema:
type: string
format: binary
/file/{file}/delete:
delete:
summary: Deletes the specified file
parameters:
- name: file
in: path
required: true
schema:
type: string
responses:
'200':
description: File successfully deleted
/file/{file}/rename:
put:
summary: Renames the specified file
parameters:
- name: file
in: path
required: true
schema:
type: string
requestBody:
required: true
content:
application/json:
schema:
type: object
properties:
new_filename:
type: string
new_filename_prefix:
type: string
enum:
- none
- date
- datetime
responses:
'200':
description: File successfully renamed
/dev/timezone:
get:
summary: Returns the current timezone
responses:
'200':
description: Current timezone
content:
application/json:
schema:
type: object
properties:
timezone:
type: string
1 change: 1 addition & 0 deletions docker-compose-example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ services:
- OCR_PATH=ocr.php
- TELEGRAM_TOKEN="" # note: keep the word bot in the string
- TELEGRAM_CHATID=127585497 # note: target chat id. can be person or group
- ALLOW_GUI_FILEOPERATIONS=true
restart: unless-stopped

# optional, for OCR
Expand Down
Loading

0 comments on commit 3d2b7c7

Please sign in to comment.