Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor frontend with routing because we need more api routes f… #32

Merged
merged 21 commits into from
Nov 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
f421230
WIP: refactor frontend with routing because we need more api routes f…
vgarcia007 Sep 17, 2024
87ba7aa
separate js and css
vgarcia007 Sep 20, 2024
75383e3
added routes
vgarcia007 Sep 20, 2024
5d633ae
common functions
vgarcia007 Sep 20, 2024
e32679c
routes for api and frontend
vgarcia007 Sep 20, 2024
4d1fcdc
A solution to keep the original date and time when renaming, without …
vgarcia007 Sep 23, 2024
4f408ca
Many adjustments to ensure that the GUI behaves correctly when deleti…
vgarcia007 Sep 23, 2024
5447cc4
trigger rename bash script
vgarcia007 Sep 23, 2024
348f08a
helper functions
vgarcia007 Sep 23, 2024
99d08f9
routs and error pages
vgarcia007 Sep 23, 2024
8c56a62
Merge pull request #2 from PhilippMundhenk/master
vgarcia007 Sep 24, 2024
953a031
Merge branch 'fileops' into master
vgarcia007 Sep 24, 2024
2f1b900
Merge pull request #3 from vgarcia007/master
vgarcia007 Sep 24, 2024
e2fd41b
rewrite to index.php
vgarcia007 Sep 24, 2024
aba698e
swagger for api endpoints
vgarcia007 Sep 24, 2024
a13aa18
mention swagger and api
vgarcia007 Sep 24, 2024
7d9a553
changed my mind about this. removed bash in do it in php
vgarcia007 Sep 24, 2024
55d37f9
temp extend sudo rights for www-data because of execution problems vi…
vgarcia007 Sep 30, 2024
ffc227d
php can log to /var/log/scanner.log now
vgarcia007 Sep 30, 2024
8b9e29c
merge conflictsMerge remote-tracking branch 'upstream/development' in…
vgarcia007 Oct 31, 2024
fdf7a2e
Updated base image to python:slim-bookworm for PHP 8.2 support.
vgarcia007 Nov 4, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading