Skip to content
Draft

Deno #27

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
42defa2
move old stuff out of the way
nleanba Sep 1, 2022
3c7dcd8
defined all routes
nleanba Oct 22, 2022
5d13636
fmt
nleanba Oct 22, 2022
315819c
added GET /version
nleanba Oct 22, 2022
b11dee5
docker framework
nleanba Oct 22, 2022
08ff7a3
setup devcontainer
nleanba Oct 22, 2022
f08e7f1
added zip restore
nleanba Oct 22, 2022
1ed70b6
added cors headers
nleanba Oct 22, 2022
d208e9e
added cors headers
nleanba Oct 22, 2022
21700f8
Merge branch 'deno' of github.com:tridoc/tridoc-backend into deno
nleanba Oct 22, 2022
ffce65f
added count
nleanba Oct 22, 2022
4c45866
added count
nleanba Oct 22, 2022
9a72686
added GET /doc/:id
nleanba Oct 22, 2022
c1c0b30
added GET /doc/:id/comment
nleanba Oct 22, 2022
1c5795c
added POST /doc
nleanba Oct 23, 2022
36ec78c
added filename to GET /doc
nleanba Oct 23, 2022
1ef5b30
added delete
nleanba Oct 23, 2022
4728531
redactored to fusekiFetch/Update instead of fetch
nleanba Oct 23, 2022
1d41598
added POST /doc/:id/comment
nleanba Oct 23, 2022
a9828f3
added GET /doc/:id/thumb
nleanba Oct 23, 2022
6b67780
added GET /doc/:id/title
nleanba Oct 23, 2022
c5576ef
added GET /doc/:id/tag, /doc/:id/meta
nleanba Oct 23, 2022
4187119
added GET /raw/rdf
nleanba Oct 23, 2022
520a4d0
added GET /raw/tgz
nleanba Oct 23, 2022
8151fe3
added GET /raw/zip
nleanba Oct 23, 2022
6050e11
rm broken
nleanba Oct 23, 2022
93bfaa6
added GET /tag/:tagLabel
nleanba Oct 23, 2022
b0384de
added POST /doc/:id/tag
nleanba Oct 23, 2022
690595b
added PUT /doc/:id/title
nleanba Oct 24, 2022
0479d8d
added POST /tag
nleanba Oct 24, 2022
876f0ae
added DELETE /tag/label and /doc/:id/tag/:label
nleanba Oct 24, 2022
aa92beb
refined HTTP response codes
nleanba Oct 24, 2022
8c4d889
implemented DELETE /doc/:id/title
nleanba Oct 24, 2022
30e234e
added message about file permissions as temp fix
nleanba Jan 13, 2023
b875206
Added correct content-type for all JSON responses
nleanba Jan 15, 2023
9d17a03
Removed deadlock
nleanba Aug 3, 2023
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
20 changes: 20 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
FROM denoland/deno:1.26.2

EXPOSE 8000

RUN mkdir -p /home/deno
RUN chown -R deno /home/deno
RUN mkdir -p /usr/src/app/src
WORKDIR /usr/src/app

RUN apt update \
&& apt -y install pdfsandwich tesseract-ocr-deu tesseract-ocr-fra curl git zip unzip
RUN rm /etc/ImageMagick-6/policy.xml

USER deno
COPY src/deps.ts src/deps.ts
RUN deno cache src/deps.ts

COPY . .

CMD [ "/bin/bash", "/usr/src/app/.devcontainer/docker-cmd.sh" ]
47 changes: 47 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at:
// https://github.com/microsoft/vscode-dev-containers/tree/v0.245.2/containers/docker-existing-docker-compose
// If you want to run as a non-root user in the container, see .devcontainer/docker-compose.yml.
{
"name": "Existing Docker Compose (Extend)",

// Update the 'dockerComposeFile' list if you have more compose files or use different names.
// The .devcontainer/docker-compose.yml file contains any overrides you need/want to make.
"dockerComposeFile": [
"../dev-docker-compose.yml",
"docker-compose.yml"
],

"containerEnv": {
"TRIDOC_PWD": "pw123",
},

// The 'service' property is the name of the service for the container that VS Code should
// use. Update this value and .devcontainer/docker-compose.yml to the real service name.
"service": "tridoc",

// The optional 'workspaceFolder' property is the path VS Code should open by default when
// connected. This is typically a file mount in .devcontainer/docker-compose.yml
"workspaceFolder": "/usr/src/app",

// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],

// Uncomment the next line if you want start specific services in your Docker Compose config.
"runServices": [ "fuseki" ],

// Uncomment the next line if you want to keep your containers running after VS Code shuts down.
// "shutdownAction": "none",

// Uncomment the next line to run commands after the container is created - for example installing curl.
// "postCreateCommand": "apt-get update && apt-get install -y curl",

// Uncomment to connect as a non-root user if you've added one. See https://aka.ms/vscode-remote/containers/non-root.
"remoteUser": "deno",
"customizations": {
"vscode": {
"extensions": [
"denoland.vscode-deno"
]
}
}
}
11 changes: 11 additions & 0 deletions .devcontainer/docker-cmd.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash
echo 'Attempting to create Dataset "3DOC"'
curl 'http://fuseki:3030/$/datasets' -H "Authorization: Basic $(echo -n admin:pw123 | base64)" \
-H 'Content-Type: application/x-www-form-urlencoded; charset=UTF-8' --data 'dbName=3DOC&dbType=tdb'
set -m
deno run --watch --allow-net --allow-read=blobs,rdf.ttl --allow-write=blobs,rdf.ttl --allow-run --allow-env=TRIDOC_PWD,OCR_LANG src/main.ts &
sleep 5
echo 'Attempting to create Dataset "3DOC"'
curl 'http://fuseki:3030/$/datasets' -H "Authorization: Basic $(echo -n admin:pw123 | base64)" \
-H 'Content-Type: application/x-www-form-urlencoded; charset=UTF-8' --data 'dbName=3DOC&dbType=tdb'
fg 1
37 changes: 37 additions & 0 deletions .devcontainer/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
version: '3'
services:
# Update this to the name of the service you want to work with in your docker-compose.yml file
tridoc:
# If you want add a non-root user to your Dockerfile, you can use the "remoteUser"
# property in devcontainer.json to cause VS Code its sub-processes (terminals, tasks,
# debugging) to execute as the user. Uncomment the next line if you want the entire
# container to run as this user instead. Note that, on Linux, you may need to
# ensure the UID and GID of the container user you create matches your local user.
# See https://aka.ms/vscode-remote/containers/non-root for details.
#
user: deno

# Uncomment if you want to override the service's Dockerfile to one in the .devcontainer
# folder. Note that the path of the Dockerfile and context is relative to the *primary*
# docker-compose.yml file (the first in the devcontainer.json "dockerComposeFile"
# array). The sample below assumes your primary file is in the root of your project.
#
build:
context: .
dockerfile: .devcontainer/Dockerfile

volumes:
# Update this to wherever you want VS Code to mount the folder of your project
- .:/usr/src/app:cached

# Uncomment the next line to use Docker from inside the container. See https://aka.ms/vscode-remote/samples/docker-from-docker-compose for details.
# - /var/run/docker.sock:/var/run/docker.sock

# Uncomment the next four lines if you will use a ptrace-based debugger like C++, Go, and Rust.
# cap_add:
# - SYS_PTRACE
# security_opt:
# - seccomp:unconfined

# Overrides default command so things don't shut down after the process ends.
# command: "/bin/bash -c \"TRIDOC_PWD=\\\"pw123\\\" deno run --allow-net --allow-read=blobs --allow-write=blobs --allow-run=convert,pdfsandwich --allow-env=TRIDOC_PWD,OCR_LANG src/main.ts &\\\n sleep 5\\\n echo 'Attempting to create Dataset \\\"3DOC\\\"'\\\n curl 'http://fuseki:3030/$/datasets' -H \\\"Authorization: Basic $(echo -n admin:pw123 | base64)\\\" -H 'Content-Type: application/x-www-form-urlencoded; charset=UTF-8' --data 'dbName=3DOC&dbType=tdb'\\\n fg 1\\\n /bin/sh -c \\\"while sleep 1000; do :; done\\\"\""
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
old
blobs
fuseki-base
node_modules
58 changes: 1 addition & 57 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,65 +1,9 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# TypeScript v1 declaration files
typings/

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env

# next.js build output
.next

node_modules
blobs

fuseki-base
15 changes: 0 additions & 15 deletions .vscode/launch.json

This file was deleted.

4 changes: 3 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{
"npm.packageManager": "yarn"
"deno.enable": true,
"deno.lint": true,
"deno.unstable": true
}
Empty file removed 3doc.config.js
Empty file.
61 changes: 8 additions & 53 deletions DEV-README.md
Original file line number Diff line number Diff line change
@@ -1,65 +1,20 @@
# tridoc

## Table Of Contents
* [Easy Setup with Docker-Compose](#easy-setup-with-docker-compose)
* [Dev Build](#dev-build)
* [Production Build](#production-build)
* [Setup with Persistent Fuseki](#setup-with-persistent-fuseki)
* [Docker](#docker)
* [Manual](#manual)
## Run "live"

## Developer Guide
Use the vscode-devcontainer: this will start tridoc and fuseki.

This assumes a Unix/Linux/wsl system with bash
It will use TRIDOC_PWD = "pw123".
Access tridoc from http://localhost:8000 and fuseki from http://localhost:8001

### Easy Setup with Docker-Compose
You might need to `chown deno:deno` blobs/ and fuseki-base (attach bash to docker as root from outside)

This will setup tridoc on port 8000 and fuseki avaliable on port 8001.
Watch the logs from outside of vscode with

Replace `YOUR PASSWORD HERE` in the first command with your choice of password.

#### Dev Build:

```
export TRIDOC_PWD="YOUR PASSWORD HERE"
docker-compose -f dev-docker-compose.yml build
docker-compose -f dev-docker-compose.yml up
```

#### Production Build:

```
export TRIDOC_PWD="YOUR PASSWORD HERE"
docker-compose build
docker-compose up
```

### Setup with Persistent Fuseki

The following method expect an instance of Fuseki running on http://fuseki:3030/ with user `admin` and password `pw123`. This fuseki instance must have lucene indexing enabled and configured as in [config-tdb.ttl](config-tdb.ttl).

#### Docker:

```
docker build -t tridoc .
docker run -p 8000:8000 -e TRIDOC_PWD="YOUR PASSWORD HERE" tridoc
```

#### Manual:

Install the following dependencies:

```
node:12.18 yarn pdfsandwich tesseract-ocr-deu tesseract-ocr-fra
```sh
docker logs -f tridoc-backend_tridoc_1
```

And run the following commands

```
rm /etc/ImageMagick-6/policy.xml
yarn install
bash docker-cmd.sh
```

## Tips & Tricks

Expand Down
23 changes: 15 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
FROM node:lts-buster
FROM denoland/deno:1.26.2

EXPOSE 8000

RUN mkdir -p /usr/src/app/src
WORKDIR /usr/src/app

RUN apt update \
&& apt -y install pdfsandwich tesseract-ocr-deu tesseract-ocr-fra
&& apt -y install pdfsandwich tesseract-ocr-deu tesseract-ocr-fra curl zip unzip
RUN rm /etc/ImageMagick-6/policy.xml
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
COPY . /usr/src/app
RUN yarn install
RUN chmod +x /usr/src/app/docker-cmd.sh
CMD [ "/usr/src/app/docker-cmd.sh" ]

USER deno
COPY src/deps.ts src/deps.ts
RUN deno cache src/deps.ts

COPY . .

CMD [ "/bin/bash", "/usr/src/app/docker-cmd.sh" ]
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2018 Reto Gmür
Copyright (c) 2022 Noam Bachmann & Reto Gmür

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ When getting a comment, a JSON array with objects of the following structure is
## API

| Address | Method | Description | Request / Payload | Response | Implemented in Version |
| - | - | - | - | - | - |
| - | - | - | - | - | - | - |
| `/count` | GET | Count (matching) documents | <sup>[1](#f1)</sup> <sup>[3](#f3)</sup> | Number | 1.1.0 |
| `/doc` | POST | Add / Store Document | PDF<sup>[5](#f5)</sup> | - | 1.1.0 |
| `/doc` | GET | Get List of all (matching) documents | <sup>[1](#f1)</sup> <sup>[2](#f2)</sup> <sup>[3](#f3)</sup> | Array of objects with document identifiers and titles (where available) | 1.1.0 |
Expand All @@ -123,6 +123,7 @@ When getting a comment, a JSON array with objects of the following structure is
| `/doc/{id}/title` | DELETE | Reset document title | - | - | 1.1.0 |
| `/doc/{id}/meta` | GET | Get various metadata | - | `{"title": "the_Title", "tags":[...], "comments": [...] ... }` | 1.1.0 \| .comments & .created in 1.2.1 |
| `/raw/rdf` | GET | Get all metadata as RDF. Useful for Backups | <sup>[4](#f4)</sup> | RDF, Content-Type defined over request Headers or ?accept. Fallback to text/turtle. | 1.1.0 |
| `/raw/rdf` | DELETE | "Cancel" failed zip upload—use only if certain it’s done & failed | | | (deno only) |
| `/raw/zip` or `/raw/tgz` | GET | Get all data. Useful for backups | - | ZIP / TGZ containing blobs/ directory with all pdfs as stored within tridoc and a rdf.ttl file with all metadata. | 1.3.0 |
| `/raw/zip` | PUT | Replace all data with backup zip | ZIP | Replaces the metadata and adds the blobs from the zip | 1.3.0 |
| `/tag` | POST | Create new tag | See above | - | 1.1.0 |
Expand Down
12 changes: 12 additions & 0 deletions deno.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"fmt": {
"files": {
"include": ["src/"]
}
},
"tasks": {
// --allow-run=convert,pdfsandwich,pdftotext,tar,zip,unzip,bash
"run": "deno run --allow-net --allow-read=blobs,rdf.ttl --allow-write=blobs,rdf.ttls --allow-run --allow-env=TRIDOC_PWD,OCR_LANG src/main.ts",
"run-watch": "deno run --watch --allow-net --allow-read=blobs,rdf.ttl --allow-write=blobs,rdf.ttl --allow-run --allow-env=TRIDOC_PWD,OCR_LANG src/main.ts"
}
}
3 changes: 1 addition & 2 deletions docker-cmd.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
#!/bin/bash
sleep 5
echo 'Attempting to create Dataset "3DOC"'
curl 'http://fuseki:3030/$/datasets' -H "Authorization: Basic $(echo -n admin:pw123 | base64)" \
-H 'Content-Type: application/x-www-form-urlencoded; charset=UTF-8' --data 'dbName=3DOC&dbType=tdb'
set -m
yarn start &
deno run --allow-net --allow-read=blobs,rdf.ttl --allow-write=blobs,rdf.ttl --allow-run --allow-env=TRIDOC_PWD,OCR_LANG src/main.ts &
sleep 5
echo 'Attempting to create Dataset "3DOC"'
curl 'http://fuseki:3030/$/datasets' -H "Authorization: Basic $(echo -n admin:pw123 | base64)" \
Expand Down
2 changes: 0 additions & 2 deletions find-draft.txt

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
22 changes: 0 additions & 22 deletions package.json

This file was deleted.

Loading